mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
997 stars 79 forks source link

Should we allow `qp.quantity_from(QuantityPoint )`? #507

Closed mpusz closed 1 week ago

mpusz commented 8 months ago

quantity_point::quantity_from(PointOrigin) was added as a type safety interface over the previous getter quantity_point::quantity_from_origin() which was deemed unsafe.

Also, we now have quantity_point::quantity_ref_from(PointOrigin) that returns the reference to the underlying storage if the provided origin is the same as the one used in the quantity_point.

The question is, should we add an overload quantity_point::quantity_from(QuantityPoint) that takes QuantityPoint as an argument? I can see some benefits from doing so. On the other hand, quantity_point::quantity_ref_from(QuantityPoint) has no sense and should not be exposed.

quantity_from just subtracts the argument from *this, so it is not something that is complicated, and the user could not easily do it just with a subtraction. It was added mostly to extend quantity_point::quantity_ref_from(QuantityPoint), which had to be there. Also, I noticed that it helps do subtraction in the correct order. I already made the mistake of accidentally exchanging the argument, and I got a negative quantity as a result when a positive one was expected.

mpusz commented 1 week ago

Done