Skip to content

Commit

Permalink
fix: point origins comparison fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Dec 2, 2023
1 parent b7045e7 commit 8dab59a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
20 changes: 9 additions & 11 deletions src/core/include/mp-units/bits/quantity_point_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,16 @@ template<typename T>
inline constexpr bool is_quantity_point<T> = true;

template<PointOrigin PO1, PointOrigin PO2>
[[nodiscard]] consteval bool same_absolute_point_origins(PO1, PO2)
[[nodiscard]] consteval bool same_absolute_point_origins(PO1 po1, PO2 po2)
{
if constexpr (is_same_v<PO1, PO2>)
return true;
else if constexpr (is_derived_from_specialization_of_relative_point_origin<PO1> &&
is_derived_from_specialization_of_relative_point_origin<PO2>)
return is_same_v<std::remove_const_t<decltype(PO1::absolute_point_origin)>,
std::remove_const_t<decltype(PO2::absolute_point_origin)>>;
else if constexpr (is_derived_from_specialization_of_relative_point_origin<PO1>)
return is_same_v<std::remove_const_t<decltype(PO1::absolute_point_origin)>, PO2>;
else if constexpr (is_derived_from_specialization_of_relative_point_origin<PO2>)
return is_same_v<PO1, std::remove_const_t<decltype(PO2::absolute_point_origin)>>;
if constexpr (AbsolutePointOrigin<PO1> && AbsolutePointOrigin<PO2>)
return po1 == po2;
else if constexpr (RelativePointOrigin<PO1> && RelativePointOrigin<PO2>)
return po1.absolute_point_origin == po2.absolute_point_origin;
else if constexpr (RelativePointOrigin<PO1>)
return po1.absolute_point_origin == po2;
else if constexpr (RelativePointOrigin<PO2>)
return po1 == po2.absolute_point_origin;
else
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ template<PointOrigin PO1, PointOrigin PO2>
else if constexpr (detail::RelativePointOrigin<PO1> && detail::RelativePointOrigin<PO2>)
return PO1::quantity_point == PO2::quantity_point;
else if constexpr (detail::RelativePointOrigin<PO1>)
return same_absolute_point_origins(po1, po2) &&
return detail::same_absolute_point_origins(po1, po2) &&
detail::is_eq_zero(PO1::quantity_point.quantity_from(PO1::quantity_point.absolute_point_origin));
else if constexpr (detail::RelativePointOrigin<PO2>)
return same_absolute_point_origins(po1, po2) &&
return detail::same_absolute_point_origins(po1, po2) &&
detail::is_eq_zero(PO2::quantity_point.quantity_from(PO2::quantity_point.absolute_point_origin));
}

Expand Down
16 changes: 16 additions & 0 deletions test/unit_test/static/quantity_point_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ inline constexpr struct mean_sea_level : absolute_point_origin<mean_sea_level, i
inline constexpr struct my_mean_sea_level : decltype(mean_sea_level) {
} my_mean_sea_level;

inline constexpr struct same_mean_sea_level : relative_point_origin<mean_sea_level + 0 * isq::height[m]> {
} same_mean_sea_level;

inline constexpr struct ground_level : relative_point_origin<mean_sea_level + 42 * isq::height[m]> {
} ground_level;

Expand Down Expand Up @@ -75,6 +78,19 @@ QUANTITY_SPEC(special_height, isq::height);

static_assert(si::absolute_zero == si::zeroth_kelvin);
static_assert(si::ice_point == si::zeroth_degree_Celsius);
static_assert(si::absolute_zero != si::ice_point);
static_assert(si::zeroth_kelvin != si::zeroth_degree_Celsius);

static_assert(my_mean_sea_level == mean_sea_level);
static_assert(my_mean_sea_level == same_mean_sea_level);

static_assert(my_ground_level == ground_level);
static_assert(same_ground_level1 == ground_level);
static_assert(same_ground_level2 == my_ground_level);

static_assert(mean_sea_level != other_absolute_level);
static_assert(my_mean_sea_level != other_absolute_level);
static_assert(ground_level != other_ground_level);

template<auto QS>
struct absolute_po_ : absolute_point_origin<absolute_po_<QS>, QS> {};
Expand Down

0 comments on commit 8dab59a

Please sign in to comment.