feat: absolute() member function removed from quantity_point

This commit is contained in:
Mateusz Pusz
2023-08-23 14:52:09 +02:00
parent fb9f288c56
commit e49e6c40ae
5 changed files with 38 additions and 46 deletions
+4 -3
View File
@@ -81,7 +81,8 @@ quantity<To, Rep> exchange_to(quantity<From, Rep> q)
template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, auto PO, typename Rep>
quantity_point<To, PO, Rep> exchange_to(quantity_point<From, PO, Rep> q)
{
return quantity_point{zero + static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.absolute().number()) * To};
return quantity_point{
zero + static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * (q - q.absolute_point_origin).number()) * To};
}
int main()
@@ -89,6 +90,6 @@ int main()
quantity_point price_usd = zero + 100 * us_dollar;
quantity_point price_euro = exchange_to<euro>(price_usd);
std::cout << price_usd.absolute() << " -> " << price_euro.absolute() << "\n";
// std::cout << price_usd.absolute() + price_euro.absolute() << "\n"; // does not compile
std::cout << price_usd.quantity_from_origin() << " -> " << price_euro.quantity_from_origin() << "\n";
// std::cout << price_usd.quantity_from_origin() + price_euro.quantity_from_origin() << "\n"; // does not compile
}
+2 -2
View File
@@ -46,7 +46,7 @@ using msl_altitude = mp_units::quantity_point<mp_units::isq::altitude[mp_units::
template<class CharT, class Traits>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const msl_altitude& a)
{
return os << a.absolute() << " AMSL";
return os << a - mean_sea_level << " AMSL";
}
} // namespace geographic
@@ -56,7 +56,7 @@ struct MP_UNITS_STD_FMT::formatter<geographic::msl_altitude> : formatter<geograp
template<typename FormatContext>
auto format(const geographic::msl_altitude& a, FormatContext& ctx)
{
formatter<geographic::msl_altitude::quantity_type>::format(a.absolute(), ctx);
formatter<geographic::msl_altitude::quantity_type>::format(a - geographic::mean_sea_level, ctx);
return MP_UNITS_STD_FMT::format_to(ctx.out(), " AMSL");
}
};
+5 -5
View File
@@ -71,7 +71,7 @@ template<class CharT, class Traits, QuantityPoint QP>
requires(is_hae(QP::absolute_point_origin))
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const QP& a)
{
return os << a.absolute() << " HAE(" << to_text(a.absolute_point_origin.egm) << ")";
return os << a - a.absolute_point_origin << " HAE(" << to_text(a.absolute_point_origin.egm) << ")";
}
template<QuantityPoint QP>
@@ -80,7 +80,7 @@ struct MP_UNITS_STD_FMT::formatter<QP> : formatter<typename QP::quantity_type> {
template<typename FormatContext>
auto format(const QP& a, FormatContext& ctx)
{
formatter<typename QP::quantity_type>::format(a.absolute(), ctx);
formatter<typename QP::quantity_type>::format(a - a.absolute_point_origin, ctx);
return MP_UNITS_STD_FMT::format_to(ctx.out(), " HAE({})", to_text(QP::absolute_point_origin.egm));
}
};
@@ -98,7 +98,7 @@ hae_altitude<M> to_hae(msl_altitude msl, position<long double> pos)
{
const auto geoid_undulation =
isq::height(GeographicLibWhatsMyOffset(pos.lat.number_in(si::degree), pos.lon.number_in(si::degree)) * si::metre);
return height_above_ellipsoid<M> + (msl.absolute() - geoid_undulation);
return height_above_ellipsoid<M> + (msl - mean_sea_level - geoid_undulation);
}
@@ -113,7 +113,7 @@ using hal_altitude = quantity_point<isq::altitude[si::metre], height_above_launc
template<class CharT, class Traits>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, const hal_altitude& a)
{
return os << a.absolute() << " HAL";
return os << a.quantity_from_origin() << " HAL";
}
template<>
@@ -121,7 +121,7 @@ struct MP_UNITS_STD_FMT::formatter<hal_altitude> : formatter<hal_altitude::quant
template<typename FormatContext>
auto format(const hal_altitude& a, FormatContext& ctx)
{
formatter<hal_altitude::quantity_type>::format(a.absolute(), ctx);
formatter<hal_altitude::quantity_type>::format(a.quantity_from_origin(), ctx);
return MP_UNITS_STD_FMT::format_to(ctx.out(), " HAL");
}
};