From b77d477476684a118af141d4ec6163ab85c96d47 Mon Sep 17 00:00:00 2001 From: vocx-fc Date: Sat, 23 May 2020 01:04:17 -0500 Subject: [PATCH] Draft: move more functions to draftgeoutils.general --- src/Mod/Draft/DraftGeomUtils.py | 21 +++------------- src/Mod/Draft/draftgeoutils/general.py | 34 +++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/Mod/Draft/DraftGeomUtils.py b/src/Mod/Draft/DraftGeomUtils.py index 5d792fa7e5..3fe2577cd4 100644 --- a/src/Mod/Draft/DraftGeomUtils.py +++ b/src/Mod/Draft/DraftGeomUtils.py @@ -46,9 +46,9 @@ __title__ = "FreeCAD Draft Workbench - Geometry library" __author__ = "Yorik van Havre, Jacques-Antoine Gaudin, Ken Cline" __url__ = ["https://www.freecadweb.org"] -NORM = Vector(0, 0, 1) # provisory normal direction for all geometry ops. +from draftgeoutils.general import PARAMGRP as params -params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") +from draftgeoutils.general import NORM # Generic functions ********************************************************* @@ -134,22 +134,7 @@ from draftgeoutils.edges import isSameLine from draftgeoutils.arcs import isWideAngle -def findClosest(basepoint, pointslist): - """ - findClosest(vector,list) - in a list of 3d points, finds the closest point to the base point. - an index from the list is returned. - """ - npoint = None - if not pointslist: - return None - smallest = 1000000 - for n in range(len(pointslist)): - new = basepoint.sub(pointslist[n]).Length - if new < smallest: - smallest = new - npoint = n - return npoint +from draftgeoutils.general import findClosest from draftgeoutils.faces import concatenate diff --git a/src/Mod/Draft/draftgeoutils/general.py b/src/Mod/Draft/draftgeoutils/general.py index 1043b5f38d..3c273afa28 100644 --- a/src/Mod/Draft/draftgeoutils/general.py +++ b/src/Mod/Draft/draftgeoutils/general.py @@ -35,7 +35,10 @@ import DraftVecUtils # Delay import of module until first use because it is heavy Part = lz.LazyLoader("Part", globals(), "Part") -params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") +PARAMGRP = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft") + +# Default normal direction for all geometry operations +NORM = FreeCAD.Vector(0, 0, 1) def precision(): @@ -49,9 +52,9 @@ def precision(): # 15 that the code would never consider 2 points are coincident # as internal float is not that precise) precisionMax = 10 - precisionInt = params.GetInt("precision", 6) + precisionInt = PARAMGRP.GetInt("precision", 6) precisionInt = (precisionInt if precisionInt <= 10 else precisionMax) - return precisionInt # return params.GetInt("precision",6) + return precisionInt # return PARAMGRP.GetInt("precision", 6) def vec(edge): @@ -265,3 +268,28 @@ def isValidPath(shape): if shape.isClosed(): return False return True + + +def findClosest(base_point, point_list): + """Find closest point in a list of points to the base point. + + Returns + ------- + int + An index from the list of points is returned. + + None + If point_list is empty. + """ + npoint = None + if not point_list: + return None + + smallest = 1000000 + for n in range(len(point_list)): + new = base_point.sub(point_list[n]).Length + if new < smallest: + smallest = new + npoint = n + + return npoint