From 936526b41b7cd6ab36384f03b81440fe46d32e23 Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Tue, 26 May 2026 16:57:49 +0200 Subject: [PATCH] Add ifcopenshell.util.unit.mm_to_m helper Centralises the millimetre-to-metre conversion shortcut that add_door_representation and add_window_representation each defined locally. Subsequent commits in this PR switch both call sites to import this from util.unit, removing the duplicate definitions. Generated with the assistance of an AI coding tool. --- src/ifcopenshell-python/ifcopenshell/util/unit.py | 5 +++++ src/ifcopenshell-python/test/util/test_unit.py | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/unit.py b/src/ifcopenshell-python/ifcopenshell/util/unit.py index 7e4686d4e4..dfadebe5f1 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/unit.py +++ b/src/ifcopenshell-python/ifcopenshell/util/unit.py @@ -644,6 +644,11 @@ def convert_unit(value: float, from_unit: ifcopenshell.entity_instance, to_unit: ) +def mm_to_m(value: float) -> float: + """Convert a millimetre value to metres.""" + return value / 1000 + + def convert(value: float, from_prefix: Optional[str], from_unit: str, to_prefix: Optional[str], to_unit: str) -> float: """Converts between length, area, and volume units diff --git a/src/ifcopenshell-python/test/util/test_unit.py b/src/ifcopenshell-python/test/util/test_unit.py index 5deef1884a..17f7fd9976 100644 --- a/src/ifcopenshell-python/test/util/test_unit.py +++ b/src/ifcopenshell-python/test/util/test_unit.py @@ -32,6 +32,17 @@ import test.bootstrap from ifcopenshell.util.shape_builder import ShapeBuilder +class TestMmToM: + def test_converts_a_positive_value(self): + assert subject.mm_to_m(150) == 0.15 + + def test_returns_zero_for_zero(self): + assert subject.mm_to_m(0) == 0.0 + + def test_passes_through_negative_values(self): + assert subject.mm_to_m(-25) == -0.025 + + class TestCacheUnits(test.bootstrap.IFC4): def test_run(self): ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")