From b77aa52355715d292a0fc15e3b3084281f01f844 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 24 Nov 2024 14:19:16 +0100 Subject: [PATCH] refactor: `absolute` renamed to `point` Resolves #645 --- docs/getting_started/quick_start.md | 4 ++-- .../framework_basics/the_affine_space.md | 24 +++++++++---------- example/hw_voltage.cpp | 4 ++-- .../mp-units/framework/construction_helpers.h | 7 ++++-- .../include/mp-units/framework/reference.h | 4 ++-- .../include/mp-units/systems/si/units.h | 2 +- src/systems/include/mp-units/systems/usc.h | 2 +- test/static/quantity_point_test.cpp | 4 ++-- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/docs/getting_started/quick_start.md b/docs/getting_started/quick_start.md index c0a5368ed..71ea1bf97 100644 --- a/docs/getting_started/quick_start.md +++ b/docs/getting_started/quick_start.md @@ -261,7 +261,7 @@ This introduces an additional type-safety. using namespace mp_units::si::unit_symbols; using namespace mp_units::usc::unit_symbols; - quantity_point temp = absolute(20.); + quantity_point temp = point(20.); std::println("Temperature: {} ({})", temp.quantity_from_zero(), temp.in(deg_F).quantity_from_zero()); @@ -282,7 +282,7 @@ This introduces an additional type-safety. using namespace mp_units::si::unit_symbols; using namespace mp_units::usc::unit_symbols; - quantity_point temp = absolute(20.); + quantity_point temp = point(20.); std::println("Temperature: {} ({})", temp.quantity_from_zero(), temp.in(deg_F).quantity_from_zero()); diff --git a/docs/users_guide/framework_basics/the_affine_space.md b/docs/users_guide/framework_basics/the_affine_space.md index 50a297722..2d661cfd0 100644 --- a/docs/users_guide/framework_basics/the_affine_space.md +++ b/docs/users_guide/framework_basics/the_affine_space.md @@ -118,7 +118,7 @@ scale zeroth point using the following rules: - otherwise, an instantiation of `zeroth_point_origin` is being used which provides a well-established zeroth point for a specific quantity type. -Quantity points with default point origins may be constructed with the `absolute` construction +Quantity points with default point origins may be constructed with the `point` construction helper or forcing an explicit conversion from the `quantity`: ```cpp @@ -128,9 +128,9 @@ helper or forcing an explicit conversion from the `quantity`: quantity_point qp4(42 * m); quantity_point qp5(42 * K); quantity_point qp6(delta(42)); -quantity_point qp7 = absolute(42); -quantity_point qp8 = absolute(42); -quantity_point qp9 = absolute(42); +quantity_point qp7 = point(42); +quantity_point qp8 = point(42); +quantity_point qp9 = point(42); ``` !!! tip @@ -149,7 +149,7 @@ for this domain. ```cpp quantity_point qp1(100 * m); -quantity_point qp2 = absolute(120); +quantity_point qp2 = point(120); assert(qp1.quantity_from_zero() == 100 * m); assert(qp2.quantity_from_zero() == 120 * m); @@ -178,7 +178,7 @@ compatible: ```cpp quantity_point qp1{isq::distance(100 * m)}; -quantity_point qp2 = absolute(120); +quantity_point qp2 = point(120); assert(qp2.quantity_from(qp1) == 20 * m); assert(qp1.quantity_from(qp2) == -20 * m); @@ -411,7 +411,7 @@ namespace si { inline constexpr struct absolute_zero final : absolute_point_origin {} absolute_zero; inline constexpr auto zeroth_kelvin = absolute_zero; -inline constexpr struct ice_point final : relative_point_origin>(273'150)}> {} ice_point; +inline constexpr struct ice_point final : relative_point_origin>(273'150)}> {} ice_point; inline constexpr auto zeroth_degree_Celsius = ice_point; } @@ -419,7 +419,7 @@ inline constexpr auto zeroth_degree_Celsius = ice_point; namespace usc { inline constexpr struct zeroth_degree_Fahrenheit final : - relative_point_origin * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit; + relative_point_origin * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit; } ``` @@ -471,7 +471,7 @@ choose from here. Depending on our needs or tastes, we can: quantity_point q1 = si::zeroth_degree_Celsius + delta(20.5); quantity_point q2{delta(20.5), si::zeroth_degree_Celsius}; quantity_point q3{delta(20.5)}; - quantity_point q4 = absolute(20.5); + quantity_point q4 = point(20.5); ``` - specify a unit and use its zeroth point origin implicitly: @@ -480,7 +480,7 @@ choose from here. Depending on our needs or tastes, we can: quantity_point q5 = si::zeroth_degree_Celsius + delta(20.5); quantity_point q6{delta(20.5), si::zeroth_degree_Celsius}; quantity_point q7{delta(20.5)}; - quantity_point q8 = absolute(20.5); + quantity_point q8 = point(20.5); ``` - benefit from CTAD: @@ -489,7 +489,7 @@ choose from here. Depending on our needs or tastes, we can: quantity_point q9 = si::zeroth_degree_Celsius + delta(20.5); quantity_point q10{delta(20.5), si::zeroth_degree_Celsius}; quantity_point q11{delta(20.5)}; - quantity_point q12 = absolute(20.5); + quantity_point q12 = point(20.5); ``` In all of the above cases, we end up with the `quantity_point` of the same type and value. @@ -500,7 +500,7 @@ the following way: ![affine_space_6](affine_space_6.svg){style="width:80%;display: block;margin: 0 auto;"} ```cpp -constexpr struct room_reference_temp final : relative_point_origin(21)> {} room_reference_temp; +constexpr struct room_reference_temp final : relative_point_origin(21)> {} room_reference_temp; using room_temp = quantity_point; constexpr auto step_delta = delta>(0.5); diff --git a/example/hw_voltage.cpp b/example/hw_voltage.cpp index f04c6489f..2d57c72ae 100644 --- a/example/hw_voltage.cpp +++ b/example/hw_voltage.cpp @@ -59,7 +59,7 @@ inline constexpr voltage_hw_t voltage_hw_zero = voltage_hw_range / 2; // clang-format off inline constexpr struct hw_voltage_origin final : - relative_point_origin(min_voltage)> {} hw_voltage_origin; + relative_point_origin(min_voltage)> {} hw_voltage_origin; inline constexpr struct hw_voltage_unit final : named_unit<"hwV", mag_ratio * si::volt, hw_voltage_origin> {} hw_voltage_unit; @@ -74,7 +74,7 @@ std::optional read_hw_voltage() { voltage_hw_t local_copy = hw_voltage_value; if (local_copy == voltage_hw_error) return std::nullopt; - return absolute(local_copy); + return point(local_copy); } void print(QuantityPoint auto qp) diff --git a/src/core/include/mp-units/framework/construction_helpers.h b/src/core/include/mp-units/framework/construction_helpers.h index 36ffac6eb..fd9620865 100644 --- a/src/core/include/mp-units/framework/construction_helpers.h +++ b/src/core/include/mp-units/framework/construction_helpers.h @@ -47,7 +47,7 @@ struct delta_ { }; template -struct absolute_ { +struct point_ { template Rep = std::remove_cvref_t> [[nodiscard]] constexpr quantity_point operator()(FwdRep&& lhs) const @@ -62,7 +62,10 @@ template constexpr delta_ delta{}; template -constexpr absolute_ absolute{}; +constexpr point_ point{}; + +template +[[deprecated("Use `point` instead")]] constexpr point_ absolute{}; MP_UNITS_EXPORT_END diff --git a/src/core/include/mp-units/framework/reference.h b/src/core/include/mp-units/framework/reference.h index 102b09a9c..823434825 100644 --- a/src/core/include/mp-units/framework/reference.h +++ b/src/core/include/mp-units/framework/reference.h @@ -207,7 +207,7 @@ template template Rep = std::remove_cvref_t> requires detail::OffsetUnit [[deprecated( - "References using offset units (e.g., temperatures) should be constructed with the `delta` or `absolute` " + "References using offset units (e.g., temperatures) should be constructed with the `delta` or `point` " "helpers")]] constexpr auto operator*(FwdRep&& lhs, R r) { @@ -217,7 +217,7 @@ operator*(FwdRep&& lhs, R r) template Rep = std::remove_cvref_t> requires detail::OffsetUnit [[deprecated( - "References using offset units (e.g., temperatures) should be constructed with the `delta` or `absolute` " + "References using offset units (e.g., temperatures) should be constructed with the `delta` or `point` " "helpers")]] constexpr auto operator/(FwdRep&& lhs, R) { diff --git a/src/systems/include/mp-units/systems/si/units.h b/src/systems/include/mp-units/systems/si/units.h index b4828bebb..7c36f015a 100644 --- a/src/systems/include/mp-units/systems/si/units.h +++ b/src/systems/include/mp-units/systems/si/units.h @@ -78,7 +78,7 @@ inline constexpr struct weber final : named_unit<"Wb", volt * second> {} weber; inline constexpr struct tesla final : named_unit<"T", weber / square(metre)> {} tesla; inline constexpr struct henry final : named_unit<"H", weber / ampere> {} henry; -inline constexpr struct ice_point final : relative_point_origin>(273'150)> {} ice_point; +inline constexpr struct ice_point final : relative_point_origin<::mp_units::point>(273'150)> {} ice_point; inline constexpr auto zeroth_degree_Celsius = ice_point; inline constexpr struct degree_Celsius final : named_unit {} degree_Celsius; diff --git a/src/systems/include/mp-units/systems/usc.h b/src/systems/include/mp-units/systems/usc.h index cca91973d..87961da5c 100644 --- a/src/systems/include/mp-units/systems/usc.h +++ b/src/systems/include/mp-units/systems/usc.h @@ -127,7 +127,7 @@ inline constexpr struct inch_of_mercury final : named_unit<"inHg", mag_ratio<3'3 #endif // https://en.wikipedia.org/wiki/United_States_customary_units#Temperature -inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit; +inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<::mp_units::point * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit; inline constexpr struct degree_Fahrenheit final : named_unit * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit; // clang-format on diff --git a/test/static/quantity_point_test.cpp b/test/static/quantity_point_test.cpp index 6b3fe0812..975b2d6b9 100644 --- a/test/static/quantity_point_test.cpp +++ b/test/static/quantity_point_test.cpp @@ -808,8 +808,8 @@ static_assert(quantity_point{42 * m}.quantity_from_zero() == 42 * m); static_assert(quantity_point{isq::height(42 * m)}.quantity_from_zero() == 42 * m); static_assert(quantity_point{delta(20)}.quantity_from_zero() == delta(20)); static_assert(quantity_point{delta(20.)}.in(deg_F).quantity_from_zero() == delta(68)); -static_assert(absolute(20).quantity_from_zero() == delta(20)); -static_assert(absolute(20.).in(deg_F).quantity_from_zero() == delta(68)); +static_assert(point(20).quantity_from_zero() == delta(20)); +static_assert(point(20.).in(deg_F).quantity_from_zero() == delta(68)); static_assert((mean_sea_level + 42 * m).quantity_from_zero() == 42 * m); static_assert((ground_level + 42 * m).quantity_from_zero() == 84 * m);