Converts between length, area, and volume units In this case, you manually specify the names and (optionally) prefixes to convert to and from. In case you want to automatically convert to units already available as IFC entities, consider using convert_unit() instead. :param value:
(value: float, from_prefix: Optional[str], from_unit: str, to_prefix: Optional[str], to_unit: str)
| 645 | |
| 646 | |
| 647 | def convert(value: float, from_prefix: Optional[str], from_unit: str, to_prefix: Optional[str], to_unit: str) -> float: |
| 648 | """Converts between length, area, and volume units |
| 649 | |
| 650 | In this case, you manually specify the names and (optionally) prefixes to |
| 651 | convert to and from. In case you want to automatically convert to units |
| 652 | already available as IFC entities, consider using convert_unit() instead. |
| 653 | |
| 654 | :param value: The numeric value you want to convert |
| 655 | :param from_prefix: A prefix from IfcSIPrefix. Can be None |
| 656 | :param from_unit: IfcSIUnitName or IfcConversionBasedUnit.Name |
| 657 | :param to_prefix: A prefix from IfcSIPrefix. Can be None |
| 658 | :param to_unit: IfcSIUnitName or IfcConversionBasedUnit.Name |
| 659 | :return: The converted value. |
| 660 | """ |
| 661 | if from_unit.lower() in si_conversions: |
| 662 | value *= si_conversions[from_unit.lower()] |
| 663 | elif from_prefix: |
| 664 | value *= get_prefix_multiplier(from_prefix) |
| 665 | if "SQUARE" in from_unit: |
| 666 | value *= get_prefix_multiplier(from_prefix) |
| 667 | elif "CUBIC" in from_unit: |
| 668 | value *= get_prefix_multiplier(from_prefix) |
| 669 | value *= get_prefix_multiplier(from_prefix) |
| 670 | if to_unit.lower() in si_conversions: |
| 671 | return value * (1 / si_conversions[to_unit.lower()]) |
| 672 | elif to_prefix: |
| 673 | value *= 1 / get_prefix_multiplier(to_prefix) |
| 674 | if "SQUARE" in from_unit: |
| 675 | value *= 1 / get_prefix_multiplier(to_prefix) |
| 676 | elif "CUBIC" in from_unit: |
| 677 | value *= 1 / get_prefix_multiplier(to_prefix) |
| 678 | value *= 1 / get_prefix_multiplier(to_prefix) |
| 679 | return value |
| 680 | |
| 681 | |
| 682 | def calculate_unit_scale(ifc_file: ifcopenshell.file, unit_type: str = "LENGTHUNIT") -> float: |
no test coverage detected