mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-25 09:32:37 +00:00
small fixes after d209cc9ff, added a test
This commit is contained in:
@@ -566,8 +566,8 @@ def convert(value, from_prefix, from_unit, to_prefix, to_unit):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def calculate_unit_scale(ifc_file, unit_type='LENGTHUNIT'):
|
def calculate_unit_scale(ifc_file, unit_type="LENGTHUNIT"):
|
||||||
"""Returns a unit scale factor to convert to and from IFC project length units and SI meters
|
"""Returns a unit scale factor to convert to and from IFC project units and SI units.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import pytest
|
|||||||
import test.bootstrap
|
import test.bootstrap
|
||||||
import ifcopenshell.api
|
import ifcopenshell.api
|
||||||
import ifcopenshell.util.unit as subject
|
import ifcopenshell.util.unit as subject
|
||||||
|
from math import pi
|
||||||
|
|
||||||
|
|
||||||
class TestCalculateUnitScale(test.bootstrap.IFC4):
|
class TestCalculateUnitScale(test.bootstrap.IFC4):
|
||||||
@@ -30,6 +31,11 @@ class TestCalculateUnitScale(test.bootstrap.IFC4):
|
|||||||
ifcopenshell.api.run("unit.assign_unit", self.file, units=[length])
|
ifcopenshell.api.run("unit.assign_unit", self.file, units=[length])
|
||||||
assert subject.calculate_unit_scale(self.file) == 0.3048 * 0.001
|
assert subject.calculate_unit_scale(self.file) == 0.3048 * 0.001
|
||||||
|
|
||||||
|
angle = ifcopenshell.api.run("unit.add_conversion_based_unit", self.file, name="degree")
|
||||||
|
angle.ConversionFactor.UnitComponent.Prefix = "MILLI"
|
||||||
|
ifcopenshell.api.run("unit.assign_unit", self.file, units=[angle])
|
||||||
|
assert subject.calculate_unit_scale(self.file, "PLANEANGLEUNIT") == pi / 180 * 0.001
|
||||||
|
|
||||||
|
|
||||||
class TestFormatLength(test.bootstrap.IFC4):
|
class TestFormatLength(test.bootstrap.IFC4):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user