Skip to content

Commit

Permalink
refactor: absolute renamed to point
Browse files Browse the repository at this point in the history
Resolves #645
  • Loading branch information
mpusz committed Nov 24, 2024
1 parent 36b1707 commit b77aa52
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/getting_started/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<deg_C>(20.);
quantity_point temp = point<deg_C>(20.);
std::println("Temperature: {} ({})",
temp.quantity_from_zero(),
temp.in(deg_F).quantity_from_zero());
Expand All @@ -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<deg_C>(20.);
quantity_point temp = point<deg_C>(20.);
std::println("Temperature: {} ({})",
temp.quantity_from_zero(),
temp.in(deg_F).quantity_from_zero());
Expand Down
24 changes: 12 additions & 12 deletions docs/users_guide/framework_basics/the_affine_space.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ scale zeroth point using the following rules:
- otherwise, an instantiation of `zeroth_point_origin<QuantitySpec>` 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
Expand All @@ -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<deg_C>(42));
quantity_point qp7 = absolute<m>(42);
quantity_point qp8 = absolute<K>(42);
quantity_point qp9 = absolute<deg_C>(42);
quantity_point qp7 = point<m>(42);
quantity_point qp8 = point<K>(42);
quantity_point qp9 = point<deg_C>(42);
```
!!! tip
Expand All @@ -149,7 +149,7 @@ for this domain.
```cpp
quantity_point<isq::distance[si::metre]> qp1(100 * m);
quantity_point<isq::distance[si::metre]> qp2 = absolute<m>(120);
quantity_point<isq::distance[si::metre]> qp2 = point<m>(120);
assert(qp1.quantity_from_zero() == 100 * m);
assert(qp2.quantity_from_zero() == 120 * m);
Expand Down Expand Up @@ -178,7 +178,7 @@ compatible:

```cpp
quantity_point<si::metre> qp1{isq::distance(100 * m)};
quantity_point<si::metre> qp2 = absolute<isq::height[m]>(120);
quantity_point<si::metre> qp2 = point<isq::height[m]>(120);

assert(qp2.quantity_from(qp1) == 20 * m);
assert(qp1.quantity_from(qp2) == -20 * m);
Expand Down Expand Up @@ -411,15 +411,15 @@ namespace si {
inline constexpr struct absolute_zero final : absolute_point_origin<isq::thermodynamic_temperature> {} absolute_zero;
inline constexpr auto zeroth_kelvin = absolute_zero;

inline constexpr struct ice_point final : relative_point_origin<absolute<milli<kelvin>>(273'150)}> {} ice_point;
inline constexpr struct ice_point final : relative_point_origin<point<milli<kelvin>>(273'150)}> {} ice_point;
inline constexpr auto zeroth_degree_Celsius = ice_point;

}

namespace usc {

inline constexpr struct zeroth_degree_Fahrenheit final :
relative_point_origin<absolute<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
relative_point_origin<point<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;

}
```
Expand Down Expand Up @@ -471,7 +471,7 @@ choose from here. Depending on our needs or tastes, we can:
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q1 = si::zeroth_degree_Celsius + delta<deg_C>(20.5);
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q2{delta<deg_C>(20.5), si::zeroth_degree_Celsius};
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q3{delta<deg_C>(20.5)};
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q4 = absolute<deg_C>(20.5);
quantity_point<si::degree_Celsius, si::zeroth_degree_Celsius> q4 = point<deg_C>(20.5);
```

- specify a unit and use its zeroth point origin implicitly:
Expand All @@ -480,7 +480,7 @@ choose from here. Depending on our needs or tastes, we can:
quantity_point<si::degree_Celsius> q5 = si::zeroth_degree_Celsius + delta<deg_C>(20.5);
quantity_point<si::degree_Celsius> q6{delta<deg_C>(20.5), si::zeroth_degree_Celsius};
quantity_point<si::degree_Celsius> q7{delta<deg_C>(20.5)};
quantity_point<si::degree_Celsius> q8 = absolute<deg_C>(20.5);
quantity_point<si::degree_Celsius> q8 = point<deg_C>(20.5);
```

- benefit from CTAD:
Expand All @@ -489,7 +489,7 @@ choose from here. Depending on our needs or tastes, we can:
quantity_point q9 = si::zeroth_degree_Celsius + delta<deg_C>(20.5);
quantity_point q10{delta<deg_C>(20.5), si::zeroth_degree_Celsius};
quantity_point q11{delta<deg_C>(20.5)};
quantity_point q12 = absolute<deg_C>(20.5);
quantity_point q12 = point<deg_C>(20.5);
```

In all of the above cases, we end up with the `quantity_point` of the same type and value.
Expand All @@ -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<absolute<deg_C>(21)> {} room_reference_temp;
constexpr struct room_reference_temp final : relative_point_origin<point<deg_C>(21)> {} room_reference_temp;
using room_temp = quantity_point<isq::Celsius_temperature[deg_C], room_reference_temp>;

constexpr auto step_delta = delta<isq::Celsius_temperature<deg_C>>(0.5);
Expand Down
4 changes: 2 additions & 2 deletions example/hw_voltage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<absolute<si::volt>(min_voltage)> {} hw_voltage_origin;
relative_point_origin<point<si::volt>(min_voltage)> {} hw_voltage_origin;

inline constexpr struct hw_voltage_unit final :
named_unit<"hwV", mag_ratio<voltage_range, voltage_hw_range> * si::volt, hw_voltage_origin> {} hw_voltage_unit;
Expand All @@ -74,7 +74,7 @@ std::optional<hw_voltage_quantity_point> read_hw_voltage()
{
voltage_hw_t local_copy = hw_voltage_value;
if (local_copy == voltage_hw_error) return std::nullopt;
return absolute<hw_voltage_unit>(local_copy);
return point<hw_voltage_unit>(local_copy);
}

void print(QuantityPoint auto qp)
Expand Down
7 changes: 5 additions & 2 deletions src/core/include/mp-units/framework/construction_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ struct delta_ {
};

template<Reference R>
struct absolute_ {
struct point_ {
template<typename FwdRep, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>>
[[nodiscard]] constexpr quantity_point<MP_UNITS_EXPRESSION_WORKAROUND(R{}), default_point_origin(R{}), Rep>
operator()(FwdRep&& lhs) const
Expand All @@ -62,7 +62,10 @@ template<Reference auto R>
constexpr delta_<MP_UNITS_REMOVE_CONST(decltype(R))> delta{};

template<Reference auto R>
constexpr absolute_<MP_UNITS_REMOVE_CONST(decltype(R))> absolute{};
constexpr point_<MP_UNITS_REMOVE_CONST(decltype(R))> point{};

template<Reference auto R>
[[deprecated("Use `point` instead")]] constexpr point_<MP_UNITS_REMOVE_CONST(decltype(R))> absolute{};

MP_UNITS_EXPORT_END

Expand Down
4 changes: 2 additions & 2 deletions src/core/include/mp-units/framework/reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})>
template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>>
requires detail::OffsetUnit<decltype(get_unit(R{}))>
[[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)
{
Expand All @@ -217,7 +217,7 @@ operator*(FwdRep&& lhs, R r)
template<typename FwdRep, Reference R, RepresentationOf<get_quantity_spec(R{})> Rep = std::remove_cvref_t<FwdRep>>
requires detail::OffsetUnit<decltype(get_unit(R{}))>
[[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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/systems/include/mp-units/systems/si/units.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<absolute<milli<kelvin>>(273'150)> {} ice_point;
inline constexpr struct ice_point final : relative_point_origin<::mp_units::point<milli<kelvin>>(273'150)> {} ice_point;
inline constexpr auto zeroth_degree_Celsius = ice_point;
inline constexpr struct degree_Celsius final : named_unit<symbol_text{u8"", "`C"}, kelvin, zeroth_degree_Celsius> {} degree_Celsius;

Expand Down
2 changes: 1 addition & 1 deletion src/systems/include/mp-units/systems/usc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<absolute<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
inline constexpr struct zeroth_degree_Fahrenheit final : relative_point_origin<::mp_units::point<mag_ratio<5, 9> * si::degree_Celsius>(-32)> {} zeroth_degree_Fahrenheit;
inline constexpr struct degree_Fahrenheit final : named_unit<symbol_text{u8"", "`F"}, mag_ratio<5, 9> * si::degree_Celsius, zeroth_degree_Fahrenheit> {} degree_Fahrenheit;

// clang-format on
Expand Down
4 changes: 2 additions & 2 deletions test/static/quantity_point_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<deg_C>(20)}.quantity_from_zero() == delta<deg_C>(20));
static_assert(quantity_point{delta<deg_C>(20.)}.in(deg_F).quantity_from_zero() == delta<deg_F>(68));
static_assert(absolute<deg_C>(20).quantity_from_zero() == delta<deg_C>(20));
static_assert(absolute<deg_C>(20.).in(deg_F).quantity_from_zero() == delta<deg_F>(68));
static_assert(point<deg_C>(20).quantity_from_zero() == delta<deg_C>(20));
static_assert(point<deg_C>(20.).in(deg_F).quantity_from_zero() == delta<deg_F>(68));

static_assert((mean_sea_level + 42 * m).quantity_from_zero() == 42 * m);
static_assert((ground_level + 42 * m).quantity_from_zero() == 84 * m);
Expand Down

0 comments on commit b77aa52

Please sign in to comment.