More affine spaces
We have long supported The Affine Space abstraction. We have quantity and quantity_point.
Abstractions in ISQ
However, it turns out that is not the only abstraction level where we observe affine spaces. When we look closer at ISQ, we can see some examples as well.
height and altitude
- adding two
altitudesdoes not make sense, - subtracting
altitudefromheightdoes not make sense as well, - subtracting
heightfromaltitudeis analtitude, - adding
heightandaltitudeis analtitude.
Those are provided as aliased quantities in the ISQ.
displacement and position_vector
- adding two
position_vectorsdoes not make sense, - subtracting
position_vectorfromdisplacementdoes not make sense as well, - subtracting
displacementfromposition_vectoris aposition_vector, - adding
displacementandposition_vectoris aposition_vector.
Those are separate quantities in the ISQ.
duration and time
- adding two
timesdoes not make sense, - subtracting
timefromdurationdoes not make sense as well, - subtracting
durationfromtimeistime, - adding
durationandtimeistime.
time is not defined at ISQ at all (even though it is mentioned in Part 1 as a base quantity and referred to in some parts as defined in ISO 80000-3).
What to do?
Now the question is, what can/should we do with it?
- As of today, a user can add two
altitudesorposition_vectors. The same applies to one of their subtractions. Should we disallow that? - Should we provide a different type as a result of subtraction of the same types (
isq::altitude(4 * m) - isq::altitude(2 * m) -> isq::height(2 * m))? - Should the
common_typeofaltitudeandheightbealtitude? - Should we restrict
altitudeto be used only withquantity_pointandheightforquantity? This will automatically solve all the above math problems, as this has already been modeled in the library. However, we can't do arithmetic onquantity_point. If there is an operation that requires a point (e.g., usage ofposition_vectorinmoment_of_force), we would need to doqp.quantity_from_zero(). However, this should also return a quantity ofdisplacement(and notposition_vector), which will violate the requirements of the equation ofmoment_of_force.
Note 1: The above means that we need to diverge from ISQ and define altitude as a different quantity than height.
Note 2: Looking at the hierarchy tree provided in another thread https://github.com/mpusz/mp-units/issues/646#issuecomment-2488814674, we can see that it does not allow doing arithmetics on vector quantities of displacement and position_vector as those do not share a common node that would also be of a vector type. So we need to think about how to provide both:
- proper conversion rules,
- proper arithmetic.
This tree could provide a proper definition for all the quantities of kind length:
flowchart TD
length["<b>length</b><br>[m]"]
length --- width["<b>width</b> / <b>breadth</b>"]
length --- height["<b>height</b> / <b>depth</b>"]
height --- altitude["<b>altitude</b><br>{point_for<height>}"]
width --- thickness["<b>thickness</b>"]
width --- diameter["<b>diameter</b>"]
width --- radius["<b>radius</b>"]
radius --- radius_of_curvature["<b>radius_of_curvature</b>"]
length --- path_length["<b>path_length</b>"]
path_length --- distance["<b>distance</b>"]
distance --- displacement["<b>displacement</b><br>{vector}"]
distance --- radial_distance["<b>radial_distance</b>"]
radial_distance --- position_vector["<b>position_vector</b><br>{vector, point_for<displacement>}"]
length --- wavelength["<b>wavelength</b>"]
Still, we need to decide what to do with those. How can we benefit from those in the library?
And I always thought that the tree for length is one of the simplest ones we deal with... 😱