Draft: move more functions to draftgeoutils.edges

This commit is contained in:
vocx-fc
2020-05-23 01:09:08 -05:00
committed by Yorik van Havre
parent 538327995d
commit 910ce96aed
2 changed files with 28 additions and 21 deletions

View File

@@ -244,26 +244,7 @@ from draftgeoutils.geometry import isPlanar
from draftgeoutils.wires import findWiresOld from draftgeoutils.wires import findWiresOld
def getTangent(edge, frompoint=None): from draftgeoutils.edges import getTangent
"""
returns the tangent to an edge. If from point is given, it is used to
calculate the tangent (only useful for an arc of course).
"""
if geomType(edge) == "Line":
return vec(edge)
elif geomType(edge) == "BSplineCurve" or \
geomType(edge) == "BezierCurve":
if not frompoint:
return None
cp = edge.Curve.parameter(frompoint)
return edge.Curve.tangent(cp)[0]
elif geomType(edge) == "Circle":
if not frompoint:
v1 = edge.Vertexes[0].Point.sub(edge.Curve.Center)
else:
v1 = frompoint.sub(edge.Curve.Center)
return v1.cross(edge.Curve.Axis)
return None
from draftgeoutils.faces import bind from draftgeoutils.faces import bind

View File

@@ -31,7 +31,7 @@ import lazy_loader.lazy_loader as lz
import FreeCAD import FreeCAD
import DraftVecUtils import DraftVecUtils
from draftgeoutils.general import geomType from draftgeoutils.general import geomType, vec
# Delay import of module until first use because it is heavy # Delay import of module until first use because it is heavy
Part = lz.LazyLoader("Part", globals(), "Part") Part = lz.LazyLoader("Part", globals(), "Part")
@@ -179,3 +179,29 @@ def findMidpoint(edge):
else: else:
return None return None
def getTangent(edge, from_point=None):
"""Return the tangent to an edge, including BSpline and circular arcs.
If from_point is given, it is used to calculate the tangent,
only useful for a circular arc.
"""
if geomType(edge) == "Line":
return vec(edge)
elif (geomType(edge) == "BSplineCurve"
or geomType(edge) == "BezierCurve"):
if not from_point:
return None
cp = edge.Curve.parameter(from_point)
return edge.Curve.tangent(cp)[0]
elif geomType(edge) == "Circle":
if not from_point:
v1 = edge.Vertexes[0].Point.sub(edge.Curve.Center)
else:
v1 = from_point.sub(edge.Curve.Center)
return v1.cross(edge.Curve.Axis)
return None