lib/measures/tbd/resources/model.rb
##
# Inserts existing model vertices that should be included in vertices
#
# @param [Array] Array of original vertices
# @return [Array] Array with inserted model vertices
Inserts existing model vertices that should be included in vertices
Inserts existing model vertices that should be included in vertices
def insert_vertices_on_edges(vertices)
      bb = BoundingBox.new
      ids = ::Set.new
      vertices.each do |vertex|
        bb.add_point(vertex.point)
        ids.add(vertex.id)
      end
      vertices_to_check = []
      @vertices.each do |vertex|
        next if ids.include?(vertex.id)
        if bb.include?(vertex.point)
          vertices_to_check << vertex
        end
      end
      vertices << vertices[0]
      new_vertices = []
      (0...vertices.size-1).each do |i|
        v_this = vertices[i]
        v_next = vertices[i+1]
        new_vertices << v_this
        vertices_to_add = []
        vertices_to_check.each do |vertex|
          new_point, length = project_point_on_edge(v_this.point, v_next.point, vertex.point)
          if new_point
            vertices_to_add << {vertex: vertex, new_point: new_point, length: length}
          end
        end
        vertices_to_add.sort! { |x, y| x[:length] <=> y[:length] }
        vertices_to_add.each { |vs| new_vertices << vs[:vertex] }
      end
      new_vertices << vertices[-1]
      vertices.pop
      new_vertices.pop
      return new_vertices
    end
def insert_vertices_on_edges ( vertices ) bb = BoundingBox . new ids = :: Set . new vertices . each do | vertex | bb . add_point ( vertex . point ) ids . add ( vertex . id ) end vertices_to_check = [ ] @vertices . each do | vertex | next if ids . include? ( vertex . id ) if bb . include? ( vertex . point ) vertices_to_check << vertex end end vertices << vertices [ 0 ] new_vertices = [ ] ( 0 ... vertices . size - 1 ) . each do | i | v_this = vertices [ i ] v_next = vertices [ i + 1 ] new_vertices << v_this vertices_to_add = [ ] vertices_to_check . each do | vertex | new_point , length = project_point_on_edge ( v_this . point , v_next . point , vertex . point ) if new_point vertices_to_add << { vertex : vertex , new_point : new_point , length : length } end end vertices_to_add . sort! { | x , y | x [ :length ] <=> y [ :length ] } vertices_to_add . each { | vs | new_vertices << vs [ :vertex ] } end new_vertices << vertices [ - 1 ] vertices . pop new_vertices . pop return new_vertices end
Inserts existing model vertices that should be included in vertices
Inserts existing model vertices that should be included in vertices
# find vertices that might be inserted # temporarily close vertices # check if any vertices need to be inserted on this edge # pop the last vertex # DLM: it's possible that inserting the vertices on the edge would make the face non-planar # but if we move the vertices that could break other surfaces #if vertices.size != new_vertices.size #  puts "old vertices" #  puts vertices.map {|v| v.point.to_s } #  puts "new vertices" #  puts new_vertices.map {|v| v.point.to_s } #end
Array with inserted model vertices
Array with inserted model vertices
Array
vertices
Array of original vertices
Array of original vertices