From ea16bb939450415797052e5b19fac68376a50345 Mon Sep 17 00:00:00 2001 From: paul lee Date: Wed, 5 Aug 2020 02:14:37 +0800 Subject: [PATCH] [ DraftVecUtils.closet ] Could return the distance (no unit) of the tested point from the found closest point. --- src/Mod/Draft/DraftVecUtils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Mod/Draft/DraftVecUtils.py b/src/Mod/Draft/DraftVecUtils.py index 9467b8c364..44b62b4ad8 100644 --- a/src/Mod/Draft/DraftVecUtils.py +++ b/src/Mod/Draft/DraftVecUtils.py @@ -602,7 +602,8 @@ def find(vector, vlist): return None -def closest(vector, vlist): +def closest(vector, vlist, returnLength=False): + """Find the closest point to one point in a list of points (vectors). The scalar distance between the original point and one point in the list @@ -615,11 +616,14 @@ def closest(vector, vlist): The tested point (or vector). vlist : list A list of points (or vectors). + returnLength : True / False Returns ------- int The index of the list where the closest point is found. + dist + The distance (no unit) of the tested point from the found closest point. """ typecheck([(vector, Vector), (vlist, list)], "closest") @@ -632,7 +636,11 @@ def closest(vector, vlist): if d < dist: dist = d index = i - return index + + if returnLength: + return (index, dist) + else: + return index def isColinear(vlist):