o-murphy / py-ballisticcalc

LGPL library for small arms ballistic calculations based on point-mass (3 DoF) plus spin drift.
https://pypi.org/project/py-ballisticcalc
GNU Lesser General Public License v3.0
20 stars 8 forks source link

Units features #47

Closed dbookstaber closed 6 months ago

dbookstaber commented 7 months ago

We have to be able to do arithmetic on Units. For example, suppose we have a some_distance instance of Distance, and we want to double it.

Here is one kludge: Distance(2*some_distance.raw_value, Distance.Inch) << some_distance.unit

Problem: We have to read through the Distance class to see that its raw_value is in units of Distance.Inch.

Solution: Give all AbstractUnits child classes a raw_units property (can be static) that returns the raw units for the subclass. For example, Distance.raw_units would return Distance.Inch. Then we could instead do: Distance(2*some_distance.raw_value, some_distance.raw_units) << some_distance.unit

dbookstaber commented 6 months ago

Moves this to comment in #35