mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-06 07:51:47 +00:00
Move _is_multiple_of_pi to tool.Cad
Pure-math parallelism check (value ≡ 0 mod π within VTX_PRECISION) that lived as a module-private helper in mep.py belongs next to tool.Cad.is_x — same comparator family, no MEP-specific knowledge. Other features with rotation-difference checks (wall fillet, roof slope, railing terminus) now have a sanctioned spelling. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -49,11 +49,6 @@ from bonsai.tool.cad import VTX_PRECISION
|
||||
V = lambda *x: Vector([float(i) for i in x])
|
||||
|
||||
|
||||
def _is_multiple_of_pi(value: float) -> bool:
|
||||
n = round(value / pi)
|
||||
return tool.Cad.is_x(abs(value - n * pi), 0)
|
||||
|
||||
|
||||
def _segment_port(segment, at_segment_start: bool):
|
||||
port_key = "start_port" if at_segment_start else "end_port"
|
||||
return MEPGenerator.get_segment_data(segment).get(port_key)
|
||||
@@ -1072,7 +1067,7 @@ class MEPAddTransition(bpy.types.Operator, tool.Ifc.Operator):
|
||||
start_object.matrix_world.to_quaternion().rotation_difference(end_object_rotation).to_euler().z
|
||||
)
|
||||
|
||||
if not _is_multiple_of_pi(rotation_difference_z):
|
||||
if not tool.Cad.is_multiple_of_pi(rotation_difference_z):
|
||||
self.report(
|
||||
{"ERROR"},
|
||||
"There is some rotation difference between profiles by local Z axis: "
|
||||
@@ -1313,7 +1308,7 @@ class MEPAddBend(bpy.types.Operator, tool.Ifc.Operator):
|
||||
start_object.matrix_world.to_quaternion().rotation_difference(end_object_rotation).to_euler()
|
||||
)
|
||||
|
||||
if not _is_multiple_of_pi(rotation_difference.z):
|
||||
if not tool.Cad.is_multiple_of_pi(rotation_difference.z):
|
||||
error_msg = (
|
||||
"There is some rotation difference between profiles by local Z axis: "
|
||||
f"{round(degrees(rotation_difference.z))} deg, adding a bend is not possible."
|
||||
|
||||
@@ -177,6 +177,14 @@ class Cad:
|
||||
return False
|
||||
return (x + tolerance) > value > (x - tolerance)
|
||||
|
||||
@classmethod
|
||||
def is_multiple_of_pi(cls, value: float) -> bool:
|
||||
"""True when ``value`` is an integer multiple of π within tolerance —
|
||||
the parallelism / anti-parallelism check rotation-difference logic
|
||||
reaches for (segments aligned modulo a 180° flip)."""
|
||||
n = round(value / math.pi)
|
||||
return cls.is_x(abs(value - n * math.pi), 0)
|
||||
|
||||
@classmethod
|
||||
def normalise_angle(cls, angle: float) -> float:
|
||||
"""Normalise an angle between -179 and 180"""
|
||||
|
||||
Reference in New Issue
Block a user