mirror of
https://github.com/mpusz/mp-units.git
synced 2025-07-30 18:37:15 +02:00
feat: quantity_from_zero()
enabled for absolute point origins
This commit is contained in:
@ -178,10 +178,10 @@ distance spherical_distance(position<T> from, position<T> to)
|
||||
|
||||
using isq::sin, isq::cos, isq::asin, isq::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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -266,13 +266,11 @@ public:
|
||||
const auto q = quantity_from(unit.point_origin);
|
||||
if constexpr (requires { q.in(unit); })
|
||||
// restore the unit if possible (non-truncating)
|
||||
// original quantity point unit can be lost in the below operation
|
||||
const auto q = quantity_from(zeroth_point_origin(R));
|
||||
if constexpr (requires { q.in(unit); })
|
||||
// restore it if possible (non-truncating)
|
||||
return q.in(unit);
|
||||
else
|
||||
return q;
|
||||
} else
|
||||
return quantity_from(absolute_point_origin);
|
||||
}
|
||||
|
||||
// unit conversions
|
||||
|
@ -798,6 +798,10 @@ static_assert(quantity_point{isq::height(42 * m)}.quantity_from_zero() == 42 * m
|
||||
static_assert(quantity_point{20 * deg_C}.quantity_from_zero() == 20 * deg_C);
|
||||
static_assert(quantity_point{20. * deg_C}.in(deg_F).quantity_from_zero() == 68 * deg_F);
|
||||
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from_zero() == 42 * m);
|
||||
static_assert((ground_level + 42 * m).quantity_from_zero() == 84 * m);
|
||||
static_assert((tower_peak + 42 * m).quantity_from_zero() == 126 * m);
|
||||
|
||||
static_assert((mean_sea_level + 42 * m).quantity_from(mean_sea_level) == 42 * m);
|
||||
static_assert((mean_sea_level + isq::height(42 * m)).quantity_from(mean_sea_level) == 42 * m);
|
||||
|
||||
@ -979,14 +983,14 @@ static_assert([](auto v) {
|
||||
////////////////////////
|
||||
|
||||
// same type
|
||||
static_assert((mean_sea_level + 1 * m += 1 * m).quantity_from(mean_sea_level).numerical_value_in(m) == 2);
|
||||
static_assert((mean_sea_level + 2 * m -= 1 * m).quantity_from(mean_sea_level).numerical_value_in(m) == 1);
|
||||
static_assert((mean_sea_level + 1 * m += 1 * m).quantity_from_zero().numerical_value_in(m) == 2);
|
||||
static_assert((mean_sea_level + 2 * m -= 1 * m).quantity_from_zero().numerical_value_in(m) == 1);
|
||||
|
||||
// different types
|
||||
static_assert((mean_sea_level + 2.5 * m += 3 * m).quantity_from(mean_sea_level).numerical_value_in(m) == 5.5);
|
||||
static_assert((mean_sea_level + 123 * m += 1 * km).quantity_from(mean_sea_level).numerical_value_in(m) == 1123);
|
||||
static_assert((mean_sea_level + 5.5 * m -= 3 * m).quantity_from(mean_sea_level).numerical_value_in(m) == 2.5);
|
||||
static_assert((mean_sea_level + 1123 * m -= 1 * km).quantity_from(mean_sea_level).numerical_value_in(m) == 123);
|
||||
static_assert((mean_sea_level + 2.5 * m += 3 * m).quantity_from_zero().numerical_value_in(m) == 5.5);
|
||||
static_assert((mean_sea_level + 123 * m += 1 * km).quantity_from_zero().numerical_value_in(m) == 1123);
|
||||
static_assert((mean_sea_level + 5.5 * m -= 3 * m).quantity_from_zero().numerical_value_in(m) == 2.5);
|
||||
static_assert((mean_sea_level + 1123 * m -= 1 * km).quantity_from_zero().numerical_value_in(m) == 123);
|
||||
|
||||
|
||||
template<template<auto, auto, typename> typename QP>
|
||||
|
Reference in New Issue
Block a user