feat: 💥 quantity_point does not provide zero() anymore

This commit is contained in:
Mateusz Pusz
2023-10-15 09:39:18 +02:00
parent fb71971ef0
commit b96be72457
3 changed files with 14 additions and 24 deletions

View File

@@ -79,19 +79,21 @@ using longitude = mp_units::quantity_point<mp_units::si::degree, prime_meridian,
template<class CharT, class Traits, typename T> template<class CharT, class Traits, typename T>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const latitude<T>& lat) std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const latitude<T>& lat)
{ {
if (is_gteq_zero(lat)) const auto& q = lat.quantity_ref_from(geographic::equator);
return os << lat.quantity_from_origin() << " N"; if (is_gteq_zero(q))
return os << q << " N";
else else
return os << -lat.quantity_from_origin() << " S"; return os << -q << " S";
} }
template<class CharT, class Traits, typename T> template<class CharT, class Traits, typename T>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const longitude<T>& lon) std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const longitude<T>& lon)
{ {
if (is_gteq_zero(lon)) const auto& q = lon.quantity_ref_from(geographic::prime_meridian);
return os << lon.quantity_from_origin() << " E"; if (is_gteq_zero(q))
return os << q << " E";
else else
return os << -lon.quantity_from_origin() << " W"; return os << -q << " W";
} }
inline namespace literals { inline namespace literals {
@@ -137,9 +139,9 @@ struct MP_UNITS_STD_FMT::formatter<geographic::latitude<T>> :
template<typename FormatContext> template<typename FormatContext>
auto format(geographic::latitude<T> lat, FormatContext& ctx) auto format(geographic::latitude<T> lat, FormatContext& ctx)
{ {
formatter<typename geographic::latitude<T>::quantity_type>::format( const auto& q = lat.quantity_ref_from(geographic::equator);
is_gteq_zero(lat) ? lat.quantity_from(geographic::equator) : -lat.quantity_from(geographic::equator), ctx); formatter<typename geographic::latitude<T>::quantity_type>::format(is_gteq_zero(q) ? q : -q, ctx);
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(lat) ? " N" : "S"); MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(q) ? " N" : "S");
return ctx.out(); return ctx.out();
} }
}; };
@@ -150,11 +152,9 @@ struct MP_UNITS_STD_FMT::formatter<geographic::longitude<T>> :
template<typename FormatContext> template<typename FormatContext>
auto format(geographic::longitude<T> lon, FormatContext& ctx) auto format(geographic::longitude<T> lon, FormatContext& ctx)
{ {
formatter<typename geographic::longitude<T>::quantity_type>::format( const auto& q = lon.quantity_ref_from(geographic::prime_meridian);
is_gteq_zero(lon) ? lon.quantity_from(geographic::prime_meridian) formatter<typename geographic::longitude<T>::quantity_type>::format(is_gteq_zero(q) ? q : -q, ctx);
: -lon.quantity_from(geographic::prime_meridian), MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(q) ? " E" : " W");
ctx);
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(lon) ? " E" : " W");
return ctx.out(); return ctx.out();
} }
}; };

View File

@@ -85,12 +85,6 @@ public:
quantity_type quantity_from_origin_; // needs to be public for a structural type quantity_type quantity_from_origin_; // needs to be public for a structural type
// static member functions // static member functions
[[nodiscard]] static constexpr quantity_point zero() noexcept
requires requires { quantity_type::zero(); }
{
return quantity_point(quantity_type::zero());
}
[[nodiscard]] static constexpr quantity_point min() noexcept [[nodiscard]] static constexpr quantity_point min() noexcept
requires requires { quantity_type::min(); } requires requires { quantity_type::min(); }
{ {

View File

@@ -240,15 +240,11 @@ static_assert(
// static member functions // static member functions
//////////////////////////// ////////////////////////////
static_assert(quantity_point<isq::height[m], mean_sea_level>::zero().quantity_from_origin_.numerical_value_ == 0);
static_assert(quantity_point<isq::height[m], mean_sea_level>::min().quantity_from_origin_.numerical_value_ == static_assert(quantity_point<isq::height[m], mean_sea_level>::min().quantity_from_origin_.numerical_value_ ==
std::numeric_limits<double>::lowest()); std::numeric_limits<double>::lowest());
static_assert(quantity_point<isq::height[m], mean_sea_level>::max().quantity_from_origin_.numerical_value_ == static_assert(quantity_point<isq::height[m], mean_sea_level>::max().quantity_from_origin_.numerical_value_ ==
std::numeric_limits<double>::max()); std::numeric_limits<double>::max());
static_assert(
quantity_point<isq::height[m], ground_level, int>::zero().quantity_from_origin_.numerical_value_ == 0);
static_assert(quantity_point<isq::height[m], ground_level, int>::min().quantity_from_origin_.numerical_value_ == static_assert(quantity_point<isq::height[m], ground_level, int>::min().quantity_from_origin_.numerical_value_ ==
std::numeric_limits<int>::lowest()); std::numeric_limits<int>::lowest());
static_assert(quantity_point<isq::height[m], ground_level, int>::max().quantity_from_origin_.numerical_value_ == static_assert(quantity_point<isq::height[m], ground_level, int>::max().quantity_from_origin_.numerical_value_ ==