From ccdf5d319a001245672042c0f32dd2b0073f91b6 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 2 Aug 2023 11:20:32 +0200 Subject: [PATCH] feat: `point_from` extended with the case of the same origin --- src/core/include/mp-units/quantity_point.h | 4 +++- test/unit_test/static/quantity_point_test.cpp | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/include/mp-units/quantity_point.h b/src/core/include/mp-units/quantity_point.h index ced82c60..535a16e0 100644 --- a/src/core/include/mp-units/quantity_point.h +++ b/src/core/include/mp-units/quantity_point.h @@ -142,7 +142,9 @@ public: template NewPO> [[nodiscard]] constexpr QuantityPointOf auto point_from(NewPO origin) const { - if constexpr (detail::is_derived_from_specialization_of_relative_point_origin) { + if constexpr (std::is_same_v>) { + return *this; + } else if constexpr (detail::is_derived_from_specialization_of_relative_point_origin) { auto q = absolute() - origin.quantity_point.absolute(); return quantity_point(std::move(q)); } else { diff --git a/test/unit_test/static/quantity_point_test.cpp b/test/unit_test/static/quantity_point_test.cpp index c6a0d35a..becf1062 100644 --- a/test/unit_test/static/quantity_point_test.cpp +++ b/test/unit_test/static/quantity_point_test.cpp @@ -410,12 +410,15 @@ static_assert(quantity_point(quantity_point(quantity_point(84 * m)) .relative() == 42 * m); +static_assert(quantity_point(42 * m).point_from(mean_sea_level).relative() == 42 * m); static_assert(quantity_point(42 * m).point_from(mean_sea_level).relative() == 84 * m); static_assert(quantity_point(42 * m).point_from(mean_sea_level).relative() == 126 * m); +static_assert(quantity_point(84 * m).point_from(ground_level).relative() == 84 * m); static_assert(quantity_point(84 * m).point_from(ground_level).relative() == 42 * m); static_assert(quantity_point(42 * m).point_from(ground_level).relative() == 84 * m); +static_assert(quantity_point(42 * m).point_from(tower_peak).relative() == 42 * m); static_assert(quantity_point(42 * m).point_from(tower_peak).relative() == -42 * m); static_assert(quantity_point(84 * m).point_from(tower_peak).relative() == 42 * m); @@ -448,12 +451,15 @@ static_assert(quantity_point(quantity_point(quantity_point(84 * m)) .absolute() == 126 * m); +static_assert(quantity_point(42 * m).point_from(mean_sea_level).absolute() == 42 * m); static_assert(quantity_point(42 * m).point_from(mean_sea_level).absolute() == 84 * m); static_assert(quantity_point(42 * m).point_from(mean_sea_level).absolute() == 126 * m); +static_assert(quantity_point(42 * m).point_from(ground_level).absolute() == 84 * m); static_assert(quantity_point(84 * m).point_from(ground_level).absolute() == 84 * m); static_assert(quantity_point(42 * m).point_from(ground_level).absolute() == 126 * m); +static_assert(quantity_point(42 * m).point_from(tower_peak).absolute() == 126 * m); static_assert(quantity_point(42 * m).point_from(tower_peak).absolute() == 42 * m); static_assert(quantity_point(84 * m).point_from(tower_peak).absolute() == 126 * m);