DraftVecUtils.equals relies on the Draft precision. So it may be better to switch to the isEqual method of the Vector class here. In the suggested code the tolerance is hard-coded. I do not know if that is OK.
Suggested code (see # Modified)
Code: Select all
if not firstDir:
# need to test against Part.Circle, not Part.ArcOfCircle
if isinstance(e.Curve, (Part.Circle,Part.Ellipse)):
v0 = e.tangentAt(e.FirstParameter).cross(norm)
else:
v0 = vec(e).cross(norm)
# check against dvec provided for the offset direction
# would not know if dvec is vector of width (Left/Right Align)
# or width/2 (Center Align)
v0.normalize() # Modified
v1 = App.Vector(dvec).normalize() # Modified
if v0.isEqual(v1, 0.0001): # Modified
# "Left Offset" (Left Align or 'left offset' in Centre Align)
firstDir = 1
firstAlign = 'Left'
alignListC.append('Left')
elif v0.isEqual(v1.negative(), 0.0001): # Modified
# "Right Offset" (Right Align or 'right offset' in Centre Align)
firstDir = -1
firstAlign = 'Right'
alignListC.append('Right')
else:
print(" something wrong with firstDir ")
firstAlign = 'Left'
alignListC.append('Left')
Code: Select all
if not firstDir:
# need to test against Part.Circle, not Part.ArcOfCircle
if isinstance(e.Curve, (Part.Circle,Part.Ellipse)):
v0 = e.tangentAt(e.FirstParameter).cross(norm)
else:
v0 = vec(e).cross(norm)
# check against dvec provided for the offset direction
# would not know if dvec is vector of width (Left/Right Align)
# or width/2 (Center Align)
dvec0 = DraftVecUtils.scaleTo(v0, dvec.Length)
if DraftVecUtils.equals(dvec0, dvec):
# "Left Offset" (Left Align or 'left offset' in Centre Align)
firstDir = 1
firstAlign = 'Left'
alignListC.append('Left')
elif DraftVecUtils.equals(dvec0, dvec.negative()):
# "Right Offset" (Right Align or 'right offset' in Centre Align)
firstDir = -1
firstAlign = 'Right'
alignListC.append('Right')
else:
print(" something wrong with firstDir ")
firstAlign = 'Left'
alignListC.append('Left')
Code: Select all
OS: Windows 8.1 Version 6.3 (Build 9600)
Word size of FreeCAD: 64-bit
Version: 0.20.24893 (Git)
Build type: Release
Branch: master
Hash: 03855f793feaceeb4385c02f6520f3e1b6429c93
Python version: 3.8.6+
Qt version: 5.15.2
Coin version: 4.0.1
OCC version: 7.5.0
Locale: Dutch/Netherlands (nl_NL)