actually find nearest point of shape (#889)

For any shape with a dimension smaller than 2*epsilon, there can be
multiple potential points to select from. In practice this resulted
in e.g. the top right corner being highlighted when the cursor was
placed below the bottom right corner.
This commit is contained in:
Stefan Breunig
2022-06-12 19:03:14 +02:00
committed by GitHub
parent e2d758f540
commit 1fca69f0b3
+6 -3
View File
@@ -153,10 +153,13 @@ class Shape(object):
assert False, "unsupported vertex shape" assert False, "unsupported vertex shape"
def nearest_vertex(self, point, epsilon): def nearest_vertex(self, point, epsilon):
index = None
for i, p in enumerate(self.points): for i, p in enumerate(self.points):
if distance(p - point) <= epsilon: dist = distance(p - point)
return i if dist <= epsilon:
return None index = i
epsilon = dist
return index
def contains_point(self, point): def contains_point(self, point):
return self.make_path().contains(point) return self.make_path().contains(point)