From 1fca69f0b36db0e30c97985dc60d44d9f466c322 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Sun, 12 Jun 2022 19:03:14 +0200 Subject: [PATCH] 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. --- libs/shape.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/shape.py b/libs/shape.py index 55866c5b..65b5bac1 100644 --- a/libs/shape.py +++ b/libs/shape.py @@ -153,10 +153,13 @@ class Shape(object): assert False, "unsupported vertex shape" def nearest_vertex(self, point, epsilon): + index = None for i, p in enumerate(self.points): - if distance(p - point) <= epsilon: - return i - return None + dist = distance(p - point) + if dist <= epsilon: + index = i + epsilon = dist + return index def contains_point(self, point): return self.make_path().contains(point)