From 0a9cac21d2ba3b0d9f3a29c7aac5fe1223e86adc Mon Sep 17 00:00:00 2001 From: James Crake-Merani Date: Thu, 12 Sep 2024 11:16:42 +0100 Subject: [PATCH] Multiply dimensions function. --- sasdata/quantities/unit_parser.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sasdata/quantities/unit_parser.py b/sasdata/quantities/unit_parser.py index 7dba3dd..b4801fc 100644 --- a/sasdata/quantities/unit_parser.py +++ b/sasdata/quantities/unit_parser.py @@ -1,6 +1,19 @@ from sasdata.quantities.units import Dimensions, NamedUnit, Unit, symbol_lookup from re import findall +# TODO: This should probably be part of the Dimensions class but I don't want to change Lucas's code without asking him +# when he gets back. +def multiply_dimensions(dimensions_1: Dimensions, dimensions_2: Dimensions) -> Dimensions: + return Dimensions( + length=dimensions_1.length * dimensions_2.length, + time=dimensions_1.time * dimensions_2.time, + mass=dimensions_1.mass * dimensions_2.mass, + current=dimensions_1.current * dimensions_2.current, + temperature=dimensions_1.temperature * dimensions_2.temperature, + moles_hint=dimensions_1.moles_hint * dimensions_2.moles_hint, + angle_hint=dimensions_1.angle_hint * dimensions_2.angle_hint + ) + def split_unit_str(unit_str: str) -> list[str]: return findall(r'[A-Za-z]+|[-\d]+', unit_str)