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")