mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 12:54:25 +02:00
refactor: conversion from quantity
to quantity_point
is now explicit
This commit is contained in:
@@ -78,7 +78,7 @@ quantity<To, Rep> exchange_to(quantity<From, Rep> q)
|
|||||||
template<ReferenceOf<currency> auto To, ReferenceOf<currency> auto From, auto PO, typename Rep>
|
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)
|
quantity_point<To, PO, Rep> exchange_to(quantity_point<From, PO, Rep> q)
|
||||||
{
|
{
|
||||||
return static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.absolute().number()) * To;
|
return quantity_point{static_cast<Rep>(exchange_rate<q.unit, get_unit(To)>() * q.absolute().number()) * To};
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@@ -97,7 +97,7 @@ hae_altitude<M> to_hae(msl_altitude msl, position<long double> pos)
|
|||||||
{
|
{
|
||||||
const auto geoid_undulation =
|
const auto geoid_undulation =
|
||||||
isq::height(GeographicLibWhatsMyOffset(pos.lat.number_in(si::degree), pos.lon.number_in(si::degree)) * si::metre);
|
isq::height(GeographicLibWhatsMyOffset(pos.lat.number_in(si::degree), pos.lon.number_in(si::degree)) * si::metre);
|
||||||
return msl.absolute() - geoid_undulation;
|
return hae_altitude<M>{msl.absolute() - geoid_undulation};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ struct STD_FMT::formatter<hal_altitude> : formatter<hal_altitude::quantity_type>
|
|||||||
// **** UAV ****
|
// **** UAV ****
|
||||||
|
|
||||||
class unmanned_aerial_vehicle {
|
class unmanned_aerial_vehicle {
|
||||||
msl_altitude current_ = 0 * si::metre;
|
msl_altitude current_{0 * si::metre};
|
||||||
msl_altitude launch_ = current_;
|
msl_altitude launch_ = current_;
|
||||||
public:
|
public:
|
||||||
void take_off(msl_altitude alt) { launch_ = alt; }
|
void take_off(msl_altitude alt) { launch_ = alt; }
|
||||||
@@ -138,7 +138,7 @@ public:
|
|||||||
void current(msl_altitude alt) { current_ = alt; }
|
void current(msl_altitude alt) { current_ = alt; }
|
||||||
msl_altitude current() const { return current_; }
|
msl_altitude current() const { return current_; }
|
||||||
|
|
||||||
hal_altitude hal() const { return current_ - launch_; }
|
hal_altitude hal() const { return hal_altitude{current_ - launch_}; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -148,11 +148,11 @@ int main()
|
|||||||
using namespace mp_units::international::unit_symbols;
|
using namespace mp_units::international::unit_symbols;
|
||||||
|
|
||||||
unmanned_aerial_vehicle uav;
|
unmanned_aerial_vehicle uav;
|
||||||
uav.take_off(6'000 * ft);
|
uav.take_off(msl_altitude{6'000 * ft});
|
||||||
uav.current(10'000 * ft);
|
uav.current(msl_altitude{10'000 * ft});
|
||||||
std::cout << STD_FMT::format("hal = {}\n", uav.hal());
|
std::cout << STD_FMT::format("hal = {}\n", uav.hal());
|
||||||
|
|
||||||
msl_altitude ground_level = 123 * m;
|
msl_altitude ground_level{123 * m};
|
||||||
std::cout << STD_FMT::format("agl = {}\n", uav.current() - ground_level);
|
std::cout << STD_FMT::format("agl = {}\n", uav.current() - ground_level);
|
||||||
|
|
||||||
struct waypoint {
|
struct waypoint {
|
||||||
|
@@ -102,7 +102,7 @@ public:
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
requires std::constructible_from<quantity_type, T>
|
requires std::constructible_from<quantity_type, T>
|
||||||
constexpr explicit(!std::convertible_to<T, quantity_type>) quantity_point(T&& v) : q_(std::forward<T>(v))
|
constexpr explicit quantity_point(T&& v) : q_(std::forward<T>(v))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user