Replies: 4 comments 11 replies
-
Explicit origin provided via quantity::relative_to()Right now, we have the following helpers in quantity point: qp.quantity_from_zero() -> quantity
qp.quantity_from(Origin) -> quantity
qp.point_for(Origin) -> quantity_point with the above changes, those probably should be renamed to: q.delta_from_zero() -> quantity<delta...>
q.delta_from(Origin) -> quantity<delta...>
q.point_for(Origin) -> quantity<point...> We could consider adding a symmetric interface to obtain a point from the quantity. For example: quantity qp1 = (40 * m).relative_to(mean_sea_level);
quantity qp2 = (40 * delta<m>).relative_to(mean_sea_level);
quantity qp3 = delta<m>(40).relative_to(mean_sea_level);
quantity qp4 = (40 * isq::height[m]).relative_to(mean_sea_level);
quantity qp5 = (40 * delta<isq::height[m]>).relative_to(mean_sea_level);
quantity qp6 = isq::height(40 * m).relative_to(mean_sea_level);
quantity qp7 = delta<isq::height>(40 * m).relative_to(mean_sea_level);
quantity qp8 = delta<isq::height[m]>(40).relative_to(mean_sea_level); I have also considered the following names: q.point_from(Origin)
q.point_for(Origin) I really do not know which one is better. Let's try to use actual variable names: height.relative_to(mean_sea_level)
height.point_relative_to(mean_sea_level)
height.point_from(mean_sea_level)
height.point_for(mean_sea_level) Do you think we should add such a function? If so, how to name it? |
Beta Was this translation helpful? Give feedback.
-
Offset unitsFor offset units, we decided to be specific and prevent any ambiguity. This is why the below commented-out lines should not compile: // delta
// quantity t1 = 40 * deg_C;
quantity t2 = 40 * delta<deg_C>;
quantity t3 = delta<deg_C>(40);
// quantity t4 = 40 * isq::Celsius_temperature[deg_C];
quantity t5 = 40 * delta<isq::Celsius_temperature[deg_C]>;
quantity t6 = 40 * delta<isq::Celsius_temperature>[deg_C];
// quantity t7 = isq::Celsius_temperature(40 * deg_C);
quantity t8 = delta<isq::Celsius_temperature>(40 * deg_C);
quantity t9 = delta<isq::Celsius_temperature[deg_C]>(40);
quantity t10 = delta<isq::Celsius_temperature>[deg_C](40);
// implicit origin
quantity tp1 = 40 * point<deg_C>;
quantity tp2 = point<deg_C>(40);
quantity tp3 = 40 * point<isq::Celsius_temperature[deg_C]>;
quantity tp4 = 40 * point<isq::Celsius_temperature>[deg_C];
quantity tp5 = point<isq::Celsius_temperature>(40 * deg_C);
quantity tp6 = point<isq::Celsius_temperature[deg_C]>(40);
quantity tp7 = point<isq::Celsius_temperature>[deg_C](40);
// explicit origin provided via addition
// quantity c1 = ice_point + 40 * deg_C;
quantity c2 = ice_point + 40 * delta<deg_C>;
quantity c3 = ice_point + delta<deg_C>(40);
// quantity c4 = ice_point + 40 * isq::Celsius_temperature[deg_C];
quantity c5 = ice_point + 40 * delta<isq::Celsius_temperature[deg_C]>;
// quantity c6 = ice_point + isq::Celsius_temperature(40 * deg_C);
quantity c7 = ice_point + delta<isq::Celsius_temperature>(40 * deg_C);
quantity c8 = ice_point + delta<isq::Celsius_temperature[deg_C]>(40);
// explicit origin provided via quantity::relative_to()
// quantity qp1 = (40 * deg_C).relative_to(ice_point);
quantity qp2 = (40 * delta<deg_C>).relative_to(ice_point);
quantity qp3 = delta<deg_C>(40).relative_to(ice_point);
// quantity qp4 = (40 * isq::Celsius_temperature[deg_C]).relative_to(ice_point);
quantity qp5 = (40 * delta<isq::Celsius_temperature[deg_C]>).relative_to(ice_point);
// quantity qp6 = isq::Celsius_temperature(40 * deg_C).relative_to(ice_point);
quantity qp7 = delta<isq::Celsius_temperature>(40 * deg_C).relative_to(ice_point);
quantity qp8 = delta<isq::Celsius_temperature[deg_C]>(40).relative_to(ice_point);
// explicit origin provided via point<>
quantity qp1 = 40 * point<deg_C, ice_point>;
quantity qp2 = point<deg_C, ice_point>(40);
quantity qp3 = 40 * point<isq::Celsius_temperature[deg_C], ice_point>;
quantity qp4 = 40 * point<isq::Celsius_temperature, ice_point>[deg_C];
quantity qp5 = point<isq::Celsius_temperature, ice_point>(40 * deg_C);
quantity qp6 = point<isq::Celsius_temperature[deg_C], ice_point>(40); |
Beta Was this translation helpful? Give feedback.
-
In the first post, I suggested removing additional
|
Beta Was this translation helpful? Give feedback.
-
Moving the origin to the reference would be a huge improvement for my application because we use explicit representation types in most quantities which forces us to provide an origin (due to the template parameter order) - even though it is almost always default/zero. This makes the type definitions prohibitively complicated to the point that we almost always use normal quantities, which is a real shame (QP + QP protection is very desirable).
Agreed. You can have a "point of 40 metres" but not vice-versa, and this is consistent with the idea that you cant multiply a point by a scalar. Not necessarily related to this proposal, but: The other issue I find with QPs is the restrictive nature of absolute point origins. In our application we have a GNSS library and a CANBUS library that both independently define latitudes/longitudes, without any knowledge of each other. I would like to do the correct thing and have: inline constexpr struct equator final : mp_units::absolute_point_origin<mp_units::isq::angular_measure> {} equator;
inline constexpr struct prime_meridian final : mp_units::absolute_point_origin<mp_units::isq::angular_measure> {} prime_meridian;
using latitude = mp_units::quantity_point<mp_units::si::degree, equator, double>;
using longitude = mp_units::quantity_point<mp_units::si::degree, prime_meridian, double>; But now it becomes a lot more difficult to share these quantities. Converting between a
If there was a way to define e.g. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As stated in my last blog post, we are considering changing the way how do we spell points in mp-units.
Let's discuss various options for new syntax here.
I thought about it for a while, and this is what I ended up with
How the user's code converts to generated types
I propose that we can put a reference in
delta<>
andpoint<>
as well:From the beginning of mp-units 2.0 we had the
QuantitySpec[Unit] -> Reference
rule.The below follows the above proposal of putting a reference in
delta<>
andpoint<>
Here are two examples of how a
quantity
will look with the above. Note how currentquantity<reference<QS, U>, Rep>
is replaced withquantity<delta<QS, U>, Rep>
:Delta quantities
We've always had the rule that
Number * Reference -> Quantity
. So everything that satisfiesReference
above and represents adelta
can be put to the right ofop*
.We also always had explicit conversions with
QuantitySpec(Quantity)
.Finally, to solve the "temperature problem", we have added
point
anddelta
helpers. Now, they might not be needed but still might be useful for points with an explicit origin. Please let me know if you feel that we should remove the below syntax.Point quantities
Previously, we were not allowed to use
op*
to create points. Now we can have such support if we decide that is a good idea. For sure, this simplifies the design and follows theNumber * Reference -> Quantity
rule (and nowpoint
is a `quantity). However it just looks wrong. What does it mean to have 40 points of metre?Implicit origins
Explicit origin provided via addition
Explicit origin provided via point<>
Beta Was this translation helpful? Give feedback.
All reactions