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:
+6
-3
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user