Skip to content

Commit

Permalink
Merge pull request #439 from alexneufeld/isnormalfix
Browse files Browse the repository at this point in the history
polyfill isNormal, eliminate typing.self
  • Loading branch information
shaise authored Jan 13, 2025
2 parents 27c151c + a837ce4 commit 5aded0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 6 additions & 7 deletions SheetMetalNewUnfolder.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from math import degrees, log10, pi, radians, sin, tan
from operator import mul as multiply_operator
from statistics import StatisticsError, mode
from typing import Self

import FreeCAD
import Part
Expand Down Expand Up @@ -152,7 +151,7 @@ def compare_plane_cylinder(p: Part.Plane, c: Part.Cylinder) -> bool:
# returns True if the cylinder is tangent to the plane
# (there is 'line contact' between the surfaces)
return (
p.Axis.isNormal(c.Axis, eps_angular)
SheetMetalTools.smIsNormal(p.Axis, c.Axis)
and abs(abs(c.Center.distanceToPlane(p.Position, p.Axis)) - c.Radius) < eps
)

Expand Down Expand Up @@ -192,7 +191,7 @@ def compare_cylinder_torus(c: Part.Cylinder, t: Part.Toroid) -> bool:
or abs(c.Radius - abs(t.MajorRadius + t.MinorRadius)) < eps
)
) or (
c.Axis.isNormal(t.Axis, eps_angular)
SheetMetalTools.smIsNormal(c.Axis, t.Axis)
and abs(abs(t.Center.distanceToLine(c.Center, c.Axis)) - t.MajorRadius)
< eps
and abs(c.Radius - t.MinorRadius) < eps
Expand Down Expand Up @@ -223,7 +222,7 @@ def compare_torus_sphere(t: Part.Toroid, s: Part.Sphere) -> bool:
)
) or (
abs(s.Radius - t.MinorRadius) < eps
and t.Axis.isNormal(s.Center - t.Center, eps_angular)
and SheetMetalTools.smIsNormal(t.Axis, s.Center - t.Center)
and abs(t.Center.distanceToPoint(s.Center) - t.MajorRadius) < eps
)

Expand Down Expand Up @@ -424,7 +423,7 @@ class BendDirection(Enum):
DOWN = auto()

@staticmethod
def from_face(bent_face: Part.Face) -> Self:
def from_face(bent_face: Part.Face):
"""Cylindrical faces may be convex or concave, and the boundary
representation can be forward or reversed. the bend direction may be
determined according to these values."""
Expand Down Expand Up @@ -570,7 +569,7 @@ def __init__(self) -> None:
self.k_factor_values = None

@classmethod
def from_single_value(cls, k_factor: float) -> Self:
def from_single_value(cls, k_factor: float):
"""one k-factor for all radius:thickness ratios"""
instance = cls()
instance.k_factor_standard = cls.KFactorStandard.ANSI
Expand Down Expand Up @@ -624,7 +623,7 @@ class KFactorStandard(Enum):
DIN = auto()

@classmethod
def from_spreadsheet(cls, sheet: FreeCAD.DocumentObject) -> Self:
def from_spreadsheet(cls, sheet: FreeCAD.DocumentObject):
instance = cls()
r_t_header = sheet.getContents("A1")
r_t_header = "".join(c for c in r_t_header if c not in "' ").lower()
Expand Down
3 changes: 2 additions & 1 deletion SheetMetalTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
language_path = os.path.join(mod_path, "translations")
params = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/SheetMetal")
smEpsilon = FreeCAD.Base.Precision.approximation()
print("======> Epsilon:", + smEpsilon)
smForceRecompute = False
smObjectsToRecompute = set()

Expand Down Expand Up @@ -598,6 +597,8 @@ def getElementFromTNP(tnpName):
def smIsParallel(v1, v2):
return abs(abs(v1.normalize().dot(v2.normalize())) - 1.0) < smEpsilon

def smIsNormal(v1, v2):
return abs(v1.dot(v2)) < smEpsilon

def smAddProperty(obj, proptype, name, proptip, defval=None, paramgroup="Parameters",
replacedname = None, readOnly = False, isHiddden = False, attribs = 0):
Expand Down

0 comments on commit 5aded0b

Please sign in to comment.