From 6c9cfccc436a1c47087edffb54b68a3cd44fee52 Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Wed, 10 Jun 2026 12:35:21 +0200 Subject: [PATCH] Move _is_multiple_of_pi to tool.Cad MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/bonsai/bonsai/bim/module/model/mep.py | 9 ++------- src/bonsai/bonsai/tool/cad.py | 8 ++++++++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/model/mep.py b/src/bonsai/bonsai/bim/module/model/mep.py index eff6146e76..39f5699be7 100644 --- a/src/bonsai/bonsai/bim/module/model/mep.py +++ b/src/bonsai/bonsai/bim/module/model/mep.py @@ -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." diff --git a/src/bonsai/bonsai/tool/cad.py b/src/bonsai/bonsai/tool/cad.py index 4c61bf1b15..957c8339fb 100644 --- a/src/bonsai/bonsai/tool/cad.py +++ b/src/bonsai/bonsai/tool/cad.py @@ -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"""