Merge pull request #522 from mpusz/implicit_point_origin

feat: implementation of implicit point origins
This commit is contained in:
Mateusz Pusz authored and GitHub committed 2023-12-26 11:09:43 +01:00
commit 6324f6dc2a
21 files changed
+903 -251

No files matched your search

+6 -8
View File
@@ -33,8 +33,6 @@ inline constexpr struct dim_currency : base_dimension<"$"> {} dim_currency;
QUANTITY_SPEC(currency, dim_currency);
constexpr struct zero : absolute_point_origin<zero, currency> {} zero;
inline constexpr struct euro : named_unit<"EUR", kind_of<currency>> {} euro;
inline constexpr struct us_dollar : named_unit<"USD", kind_of<currency>> {} us_dollar;
inline constexpr struct great_british_pound : named_unit<"GBP", kind_of<currency>> {} great_british_pound;
@@ -90,18 +88,18 @@ 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 - q.absolute_point_origin).numerical_value_in(q.unit)) *
To};
return quantity_point{
static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.quantity_from_zero().numerical_value_in(q.unit)) * To};
}
int main()
{
using namespace unit_symbols;
quantity_point price_usd = zero + 100 * USD;
quantity_point price_usd{100 * USD};
quantity_point price_euro = exchange_to<euro>(price_usd);
std::cout << price_usd.quantity_from(zero) << " -> " << price_euro.quantity_from(zero) << "\n";
// std::cout << price_usd.quantity_from(zero) + price_euro.quantity_from(zero) << "\n"; // does not compile
std::cout << price_usd.quantity_from_zero() << " -> " << price_euro.quantity_from_zero() << "\n";
// std::cout << price_usd.quantity_from_zero() + price_euro.quantity_from_zero() << "\n"; // does
// not compile
}
+4 -4
View File
@@ -178,10 +178,10 @@ distance spherical_distance(position<T> from, position<T> to)
using si::sin, si::cos, si::asin, si::acos;
const quantity from_lat = from.lat.quantity_from(equator);
const quantity from_lon = from.lon.quantity_from(prime_meridian);
const quantity to_lat = to.lat.quantity_from(equator);
const quantity to_lon = to.lon.quantity_from(prime_meridian);
const quantity from_lat = from.lat.quantity_from_zero();
const quantity from_lon = from.lon.quantity_from_zero();
const quantity to_lat = to.lat.quantity_from_zero();
const quantity to_lon = to.lon.quantity_from_zero();
// https://en.wikipedia.org/wiki/Great-circle_distance#Formulae
if constexpr (sizeof(T) >= 8) {
+2 -2
View File
@@ -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(equator).numerical_value_in(si::degree),
pos.lon.quantity_from(prime_meridian).numerical_value_in(si::degree)) *
isq::height(GeographicLibWhatsMyOffset(pos.lat.quantity_from_zero().numerical_value_in(si::degree),
pos.lon.quantity_from_zero().numerical_value_in(si::degree)) *
si::metre);
return height_above_ellipsoid<M> + (msl - mean_sea_level - geoid_undulation);
}