mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
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.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user