Draft: move more functions to draftgeoutils.general

This commit is contained in:
vocx-fc
2020-05-23 01:04:17 -05:00
committed by Yorik van Havre
parent 0a445d9e5b
commit b77d477476
2 changed files with 34 additions and 21 deletions

View File

@@ -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

View File

@@ -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