Bounding boxes are now drawn using Vertex arrays

This commit is contained in:
2018-07-30 12:52:35 -05:00
parent ded012a9e0
commit 67b06b0001
7 changed files with 195 additions and 78 deletions

View File

@@ -22,15 +22,15 @@ class IMICFPS
p model.faces.first
end
def height_at(vertex)
if vert = find_nearest_vertex(vertex)
def height_at(vertex, max_distance = Float::INFINITY)
if vert = find_nearest_vertex(vertex, max_distance)
return vert.y
else
-1
end
end
def find_nearest_vertex(vertex)
def find_nearest_vertex(vertex, max_distance)
nearest = nil
smaller_list = []
smaller_list << @nearest_vertex_lookup.dig(vertex.x.round-1, vertex.y.round-1)
@@ -41,12 +41,12 @@ class IMICFPS
smaller_list.each do |vert|
next if vert.nil?
if nearest
if distance(vert, vertex) < distance(vert, nearest)
if distance(vert, vertex) < distance(vert, nearest) && distance(vert, vertex) <= max_distance
nearest = vert
end
end
nearest = vert unless nearest
nearest = vert unless nearest && distance(vert, vertex) > max_distance
end
return nearest