mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 18:37:15 +02:00
feat: qp1.quantity_from(qp2)
added
This commit is contained in:
@ -149,7 +149,7 @@ public:
|
||||
void current(msl_altitude alt) { current_ = alt; }
|
||||
[[nodiscard]] msl_altitude current() const { return current_; }
|
||||
|
||||
[[nodiscard]] hal_altitude hal() const { return height_above_launch + (current_ - launch_); }
|
||||
[[nodiscard]] hal_altitude hal() const { return height_above_launch + current_.quantity_from(launch_); }
|
||||
};
|
||||
|
||||
|
||||
@ -164,7 +164,7 @@ int main()
|
||||
std::cout << MP_UNITS_STD_FMT::format("hal = {::N[.2f]}\n", uav.hal());
|
||||
|
||||
const msl_altitude ground_level = mean_sea_level + 123 * m;
|
||||
std::cout << MP_UNITS_STD_FMT::format("agl = {::N[.2f]}\n", uav.current() - ground_level);
|
||||
std::cout << MP_UNITS_STD_FMT::format("agl = {::N[.2f]}\n", uav.current().quantity_from(ground_level));
|
||||
|
||||
struct waypoint {
|
||||
std::string name;
|
||||
|
@ -256,6 +256,12 @@ public:
|
||||
return *this - PO2{};
|
||||
}
|
||||
|
||||
template<QuantityPointOf<absolute_point_origin> QP>
|
||||
[[nodiscard]] constexpr Quantity auto quantity_from(const QP& qp) const
|
||||
{
|
||||
return *this - qp;
|
||||
}
|
||||
|
||||
[[nodiscard]] constexpr Quantity auto quantity_from_zero() const
|
||||
{
|
||||
if constexpr (requires { unit.point_origin; }) {
|
||||
|
@ -1439,6 +1439,17 @@ static_assert((ground_level + 42 * m) - (other_ground_level + 42 * m) == -81 * m
|
||||
static_assert((other_ground_level + 42 * m) - (tower_peak + 42 * m) == 39 * m);
|
||||
static_assert((tower_peak + 42 * m) - (other_ground_level + 42 * m) == -39 * m);
|
||||
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from(ground_level + 42 * m) == -42 * m);
|
||||
static_assert((ground_level + 42 * m).quantity_from(mean_sea_level + 42 * m) == 42 * m);
|
||||
static_assert((tower_peak + 42 * m).quantity_from(ground_level + 42 * m) == 42 * m);
|
||||
static_assert((ground_level + 42 * m).quantity_from(tower_peak + 42 * m) == -42 * m);
|
||||
static_assert((tower_peak + 42 * m).quantity_from(mean_sea_level + 42 * m) == 84 * m);
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from(tower_peak + 42 * m) == -84 * m);
|
||||
static_assert((other_ground_level + 42 * m).quantity_from(ground_level + 42 * m) == 81 * m);
|
||||
static_assert((ground_level + 42 * m).quantity_from(other_ground_level + 42 * m) == -81 * m);
|
||||
static_assert((other_ground_level + 42 * m).quantity_from(tower_peak + 42 * m) == 39 * m);
|
||||
static_assert((tower_peak + 42 * m).quantity_from(other_ground_level + 42 * m) == -39 * m);
|
||||
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from(mean_sea_level) == 42 * m);
|
||||
static_assert((42 * m + mean_sea_level).quantity_from(mean_sea_level) == 42 * m);
|
||||
static_assert((mean_sea_level - 42 * m).quantity_from(mean_sea_level) == -42 * m);
|
||||
|
Reference in New Issue
Block a user