forked from mpusz/mp-units
refactor: quantity_point::quantity_from_origin() refactored to quantity_point::quantity_ref_from(PO)
Resolves #479 and relates to #477
This commit is contained in:
@@ -93,6 +93,6 @@ int main()
|
||||
quantity_point price_usd = zero + 100 * us_dollar;
|
||||
quantity_point price_euro = exchange_to<euro>(price_usd);
|
||||
|
||||
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
|
||||
std::cout << price_usd.quantity_ref_from(zero) << " -> " << price_euro.quantity_ref_from(zero) << "\n";
|
||||
// std::cout << price_usd.quantity_ref_from(zero) + price_euro.quantity_ref_from(zero) << "\n"; // does not compile
|
||||
}
|
||||
|
||||
@@ -138,7 +138,7 @@ struct MP_UNITS_STD_FMT::formatter<geographic::latitude<T>> :
|
||||
auto format(geographic::latitude<T> lat, FormatContext& ctx)
|
||||
{
|
||||
formatter<typename geographic::latitude<T>::quantity_type>::format(
|
||||
is_gt_zero(lat) ? lat.quantity_from_origin() : -lat.quantity_from_origin(), ctx);
|
||||
is_gt_zero(lat) ? lat.quantity_ref_from(geographic::equator) : -lat.quantity_ref_from(geographic::equator), ctx);
|
||||
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gt_zero(lat) ? " N" : "S");
|
||||
return ctx.out();
|
||||
}
|
||||
@@ -151,7 +151,9 @@ struct MP_UNITS_STD_FMT::formatter<geographic::longitude<T>> :
|
||||
auto format(geographic::longitude<T> lon, FormatContext& ctx)
|
||||
{
|
||||
formatter<typename geographic::longitude<T>::quantity_type>::format(
|
||||
is_gt_zero(lon) ? lon.quantity_from_origin() : -lon.quantity_from_origin(), ctx);
|
||||
is_gt_zero(lon) ? lon.quantity_ref_from(geographic::prime_meridian)
|
||||
: -lon.quantity_ref_from(geographic::prime_meridian),
|
||||
ctx);
|
||||
MP_UNITS_STD_FMT::format_to(ctx.out(), "{}", is_gt_zero(lon) ? " E" : " W");
|
||||
return ctx.out();
|
||||
}
|
||||
@@ -175,10 +177,10 @@ distance spherical_distance(position<T> from, position<T> to)
|
||||
|
||||
using isq::sin, isq::cos, isq::asin, isq::acos;
|
||||
|
||||
const auto& from_lat = from.lat.quantity_from_origin();
|
||||
const auto& from_lon = from.lon.quantity_from_origin();
|
||||
const auto& to_lat = to.lat.quantity_from_origin();
|
||||
const auto& to_lon = to.lon.quantity_from_origin();
|
||||
const auto& from_lat = from.lat.quantity_ref_from(equator);
|
||||
const auto& from_lon = from.lon.quantity_ref_from(prime_meridian);
|
||||
const auto& to_lat = to.lat.quantity_ref_from(equator);
|
||||
const auto& to_lon = to.lon.quantity_ref_from(prime_meridian);
|
||||
|
||||
// https://en.wikipedia.org/wiki/Great-circle_distance#Formulae
|
||||
if constexpr (sizeof(T) >= 8) {
|
||||
|
||||
@@ -212,7 +212,7 @@ struct MP_UNITS_STD_FMT::formatter<kalman::estimation<Q>> {
|
||||
if constexpr (mp_units::Quantity<Q>)
|
||||
return t;
|
||||
else
|
||||
return t.quantity_from_origin();
|
||||
return t.quantity_ref_from(t.point_origin);
|
||||
}(kalman::get<0>(e.state));
|
||||
|
||||
std::string value_buffer;
|
||||
|
||||
@@ -45,7 +45,7 @@ template<QuantityPoint QP, QuantityOf<dimensionless> K>
|
||||
void print(auto iteration, K gain, QP measured, kalman::estimation<QP> current, kalman::estimation<QP> next)
|
||||
{
|
||||
std::cout << MP_UNITS_STD_FMT::format("{:2} | {:7%.4Q} | {:10%.3Q %q} | {:>18.3} | {:>18.3}\n", iteration, gain,
|
||||
measured.quantity_from_origin(), current, next);
|
||||
measured.quantity_ref_from(QP::point_origin), current, next);
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -45,7 +45,7 @@ template<QuantityPoint QP, QuantityOf<dimensionless> K>
|
||||
void print(auto iteration, K gain, QP measured, kalman::estimation<QP> current, kalman::estimation<QP> next)
|
||||
{
|
||||
std::cout << MP_UNITS_STD_FMT::format("{:2} | {:7%.4Q} | {:10%.3Q %q} | {:>18.3} | {:>18.3}\n", iteration, gain,
|
||||
measured.quantity_from_origin(), current, next);
|
||||
measured.quantity_ref_from(QP::point_origin), current, next);
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -45,7 +45,7 @@ template<QuantityPoint QP, QuantityOf<dimensionless> K>
|
||||
void print(auto iteration, K gain, QP measured, kalman::estimation<QP> current, kalman::estimation<QP> next)
|
||||
{
|
||||
std::cout << MP_UNITS_STD_FMT::format("{:2} | {:7%.3Q} | {:10%.3Q %q} | {:>16.2} | {:>16.2}\n", iteration, gain,
|
||||
measured.quantity_from_origin(), current, next);
|
||||
measured.quantity_ref_from(QP::point_origin), current, next);
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
@@ -97,8 +97,8 @@ template<earth_gravity_model M>
|
||||
hae_altitude<M> to_hae(msl_altitude msl, position<long double> pos)
|
||||
{
|
||||
const auto geoid_undulation =
|
||||
isq::height(GeographicLibWhatsMyOffset(pos.lat.quantity_from_origin().numerical_value_in(si::degree),
|
||||
pos.lon.quantity_from_origin().numerical_value_in(si::degree)) *
|
||||
isq::height(GeographicLibWhatsMyOffset(pos.lat.quantity_ref_from(equator).numerical_value_in(si::degree),
|
||||
pos.lon.quantity_ref_from(prime_meridian).numerical_value_in(si::degree)) *
|
||||
si::metre);
|
||||
return height_above_ellipsoid<M> + (msl - mean_sea_level - geoid_undulation);
|
||||
}
|
||||
@@ -115,7 +115,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.quantity_from_origin() << " HAL";
|
||||
return os << a.quantity_ref_from(height_above_launch) << " HAL";
|
||||
}
|
||||
|
||||
template<>
|
||||
@@ -123,7 +123,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.quantity_from_origin(), ctx);
|
||||
formatter<hal_altitude::quantity_type>::format(a.quantity_ref_from(height_above_launch), ctx);
|
||||
return MP_UNITS_STD_FMT::format_to(ctx.out(), " HAL");
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user