-
-
Notifications
You must be signed in to change notification settings - Fork 119
Description
I am in the process of improving the support for vector quantities. We have had many simplifications and errors in this subject so far, and we should try to improve here. The question here is how strict we should be.
Let's see the following example.
We were defining speed and velocity as
inline constexpr speed final : quantity_spec<length / time> {} speed;
inline constexpr velocity final : quantity_spec<speed, position_vector / duration> {} velocity;which was a simplification, wrong, and inconsistent with ISQ definitions. ISQ defines them in the following way:
inline constexpr velocity final : quantity_spec<displacement / duration> {} velocity;
inline constexpr speed final : quantity_spec<norm(velocity)> speed {};Well, velocity is actually defined in terms of delta position_vector, but that is a displacement and should be fixed in our definitions.
Note that speed and velocity are not in the same tree, and the real definition order (dependency) is reversed to what we had before.
Moreover, our flagship example for many years looked like this:
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<isq::length> auto d,
QuantityOf<isq::time> auto t)
{
return d / t;
}
quantity height = isq::height(20 * m);
quantity time = 5 * s;
quantity speed = avg_speed(height, time);This is a simplification as length does not necessarily have to describe a displacement. What kind of speed will I get by dividing the height of the building by time? The building does not move or change its height. But this is how we are used to do it in the engineering.
Of course, if I drop a rock from the top of the roof and observe it falling down, I may use the height of this building to measure the displacement of the rock on its way down.
Also, a displacement is a vector quantity and should be described by the vector representation type. However, when we want to get speed and not velocity, we should not care.
To summarize, a proper function template should look like:
constexpr QuantityOf<isq::speed> auto avg_speed(QuantityOf<norm(isq::displacement)> auto d,
QuantityOf<isq::duration> auto t)
{
return d / t;
}and we should call it with:
quantity speed = avg_speed(quantity_cast<norm(isq::displacement)>(height), time);The question is, is that not too much? Does requiring a quantity_cast to a norm(displacement) not sacrifice usability for physical safety/correctness too much? What can we do to improve that?