Skip to content

Commit

Permalink
feat: 💥 quantity_point does not provide zero() anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
mpusz committed Oct 15, 2023
1 parent fb71971 commit b96be72
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
28 changes: 14 additions & 14 deletions example/include/geographic.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ using longitude = mp_units::quantity_point<mp_units::si::degree, prime_meridian,
template<class CharT, class Traits, typename T>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const latitude<T>& lat)
{
if (is_gteq_zero(lat))
return os << lat.quantity_from_origin() << " N";
const auto& q = lat.quantity_ref_from(geographic::equator);
if (is_gteq_zero(q))
return os << q << " N";
else
return os << -lat.quantity_from_origin() << " S";
return os << -q << " S";
}

template<class CharT, class Traits, typename T>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const longitude<T>& lon)
{
if (is_gteq_zero(lon))
return os << lon.quantity_from_origin() << " E";
const auto& q = lon.quantity_ref_from(geographic::prime_meridian);
if (is_gteq_zero(q))
return os << q << " E";
else
return os << -lon.quantity_from_origin() << " W";
return os << -q << " W";
}

inline namespace literals {
Expand Down Expand Up @@ -137,9 +139,9 @@ struct MP_UNITS_STD_FMT::formatter<geographic::latitude<T>> :
template<typename FormatContext>
auto format(geographic::latitude<T> lat, FormatContext& ctx)
{
formatter<typename geographic::latitude<T>::quantity_type>::format(
is_gteq_zero(lat) ? lat.quantity_from(geographic::equator) : -lat.quantity_from(geographic::equator), ctx);
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(lat) ? " N" : "S");
const auto& q = lat.quantity_ref_from(geographic::equator);
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(q) ? " N" : "S");
return ctx.out();
}
};
Expand All @@ -150,11 +152,9 @@ struct MP_UNITS_STD_FMT::formatter<geographic::longitude<T>> :
template<typename FormatContext>
auto format(geographic::longitude<T> lon, FormatContext& ctx)
{
formatter<typename geographic::longitude<T>::quantity_type>::format(
is_gteq_zero(lon) ? lon.quantity_from(geographic::prime_meridian)
: -lon.quantity_from(geographic::prime_meridian),
ctx);
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(lon) ? " E" : " W");
const auto& q = lon.quantity_ref_from(geographic::prime_meridian);
formatter<typename geographic::longitude<T>::quantity_type>::format(is_gteq_zero(q) ? q : -q, ctx);
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gteq_zero(q) ? " E" : " W");
return ctx.out();
}
};
Expand Down
6 changes: 0 additions & 6 deletions src/core/include/mp-units/quantity_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@ class quantity_point {
quantity_type quantity_from_origin_; // needs to be public for a structural type

// 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
requires requires { quantity_type::min(); }
{
Expand Down
4 changes: 0 additions & 4 deletions test/unit_test/static/quantity_point_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,11 @@ static_assert(
// 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_ ==
std::numeric_limits<double>::lowest());
static_assert(quantity_point<isq::height[m], mean_sea_level>::max().quantity_from_origin_.numerical_value_ ==
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_ ==
std::numeric_limits<int>::lowest());
static_assert(quantity_point<isq::height[m], ground_level, int>::max().quantity_from_origin_.numerical_value_ ==
Expand Down

0 comments on commit b96be72

Please sign in to comment.