5 Quantities and units library [quantities]

5.7 Quantity point [qty.pt]

5.7.2 Point origin [qty.pt.orig]

5.7.2.1 General [qty.pt.orig.general]

This subclause specifies the components for defining the origin of an affine space.
An origin is a point from which measurements (IEC 60050, 112-04-01) take place.

5.7.2.2 Concepts [qty.pt.orig.concepts]

template<typename T> concept PointOrigin = SymbolicConstant<T> && std::derived_from<T, point-origin-interface>; template<typename T, auto QS> concept PointOriginFor = PointOrigin<T> && QuantitySpecOf<decltype(QS), T::quantity-spec>; template<typename T, auto V> concept SameAbsolutePointOriginAs = // exposition only PointOrigin<T> && PointOrigin<decltype(V)> && same-absolute-point-origins(T{}, V);

5.7.2.3 Types [qty.pt.orig.types]

5.7.2.3.1 Absolute [qty.abs.pt.orig]

namespace mp_units { template<QuantitySpec auto QS> struct absolute_point_origin : point-origin-interface { static constexpr QuantitySpec auto quantity-spec = QS; // exposition only }; }
An absolute origin is an origin chosen by convention and not defined in terms of another origin.
A specialization of absolute_point_origin is used as a base type when defining an absolute origin.
QS is the quantity the origin represents.

5.7.2.3.2 Relative [qty.rel.pt.orig]

namespace mp_units { template<QuantityPoint auto QP> struct relative_point_origin : point-origin-interface { static constexpr QuantityPoint auto quantity-point = QP; // exposition only static constexpr QuantitySpec auto quantity-spec = see below; // exposition only static constexpr PointOrigin auto absolute-point-origin = // exposition only QP.absolute_point_origin; }; }
A relative origin is an origin of a subspace (IEC 60050, 102-03-03).
A specialization of relative_point_origin is used as a base type when defining a relative origin O.
O is offset from QP.absolute_point_origin by QP.quantity_from_zero().
The member quantity-spec is equal to QP.point_origin.quantity-spec if QuantityKindSpec<decltype(auto(QP.quantity-spec))> is satisfied, and to QP.quantity-spec otherwise.

5.7.2.3.3 Zeroth [qty.zeroth.pt.orig]

namespace mp_units { template<QuantitySpec auto QS> struct zeroth_point_origin_ final : absolute_point_origin<QS> {}; }
zeroth_point_origin_<QS> represents an origin chosen by convention as the value 0 of the quantity QS.

5.7.2.4 Operations [qty.pt.orig.ops]

namespace mp_units { struct point-origin-interface { template<PointOrigin PO, typename FwdQ, QuantityOf<PO::quantity-spec> Q = std::remove_cvref_t<FwdQ>> friend constexpr quantity_point<Q::reference, PO{}, typename Q::rep> operator+(PO, FwdQ&& q); template<Quantity FwdQ, PointOrigin PO, QuantityOf<PO::quantity-spec> Q = std::remove_cvref_t<FwdQ>> friend constexpr quantity_point<Q::reference, PO{}, typename Q::rep> operator+(FwdQ&& q, PO); template<PointOrigin PO, Quantity Q> requires ReferenceOf<decltype(auto(Q::reference)), PO::quantity-spec> friend constexpr QuantityPoint auto operator-(PO po, const Q& q) requires requires { -q; }; template<PointOrigin PO1, SameAbsolutePointOriginAs<PO1{}> PO2> requires see below friend constexpr Quantity auto operator-(PO1 po1, PO2 po2); template<PointOrigin PO1, PointOrigin PO2> friend consteval bool operator==(PO1 po1, PO2 po2); }; }
template<PointOrigin PO, typename FwdQ, QuantityOf<PO::quantity-spec> Q = std::remove_cvref_t<FwdQ>> friend constexpr quantity_point<Q::reference, PO{}, typename Q::rep> operator+(PO, FwdQ&& q); template<Quantity FwdQ, PointOrigin PO, QuantityOf<PO::quantity-spec> Q = std::remove_cvref_t<FwdQ>> friend constexpr quantity_point<Q::reference, PO{}, typename Q::rep> operator+(FwdQ&& q, PO);
Effects: Equivalent to: return quantity_point{std​::​forward<FwdQ>(q), PO{}};
template<PointOrigin PO, Quantity Q> requires ReferenceOf<decltype(auto(Q::reference)), PO::quantity-spec> friend constexpr QuantityPoint auto operator-(PO po, const Q& q) requires requires { -q; };
Effects: Equivalent to: return po + -q;
template<PointOrigin PO1, SameAbsolutePointOriginAs<PO1{}> PO2> requires see below friend constexpr Quantity auto operator-(PO1 po1, PO2 po2);
Effects: Equivalent to: if constexpr (is-derived-from-specialization-of<PO1, absolute_point_origin>()) { return po1 - po2.quantity-point; } else if constexpr (is-derived-from-specialization-of<PO2, absolute_point_origin>()) { return po1.quantity-point - po2; } else { return po1.quantity-point - po2.quantity-point; }
Remarks: The expression in the requires-clause is equivalent to: QuantitySpecOf<decltype(auto(PO1::quantity-spec)), PO2::quantity-spec> && (is-derived-from-specialization-of<PO1, relative_point_origin>() || is-derived-from-specialization-of<PO2, relative_point_origin>())
template<PointOrigin PO1, PointOrigin PO2> friend consteval bool operator==(PO1 po1, PO2 po2);
Effects: Equivalent to: if constexpr (is-derived-from-specialization-of<PO1, absolute_point_origin>() && is-derived-from-specialization-of<PO2, absolute_point_origin>()) return std::is_same_v<PO1, PO2> || (is-specialization-of<PO1, zeroth_point_origin>() && is-specialization-of<PO2, zeroth_point_origin>() && interconvertible(po1.quantity-spec, po2.quantity-spec)); else if constexpr (is-derived-from-specialization-of<PO1, relative_point_origin>() && is-derived-from-specialization-of<PO2, relative_point_origin>()) return PO1::quantity-point == PO2::quantity-point; else if constexpr (is-derived-from-specialization-of<PO1, relative_point_origin>()) return same-absolute-point-origins(po1, po2) && is_eq_zero(PO1::quantity-point.quantity_from_zero()); else if constexpr (is-derived-from-specialization-of<PO2, relative_point_origin>()) return same-absolute-point-origins(po1, po2) && is_eq_zero(PO2::quantity-point.quantity_from_zero());

5.7.2.5 Utilities [qty.pt.orig.utils]

5.7.2.5.1 Same absolute [qty.same.abs.pt.origs]

template<PointOrigin PO1, PointOrigin PO2> consteval bool same-absolute-point-origins(PO1 po1, PO2 po2); // exposition only
Effects: Equivalent to: if constexpr (is-derived-from-specialization-of<PO1, absolute_point_origin>() && is-derived-from-specialization-of<PO2, absolute_point_origin>()) return po1 == po2; else if constexpr (is-derived-from-specialization-of<PO1, relative_point_origin>() && is-derived-from-specialization-of<PO2, relative_point_origin>()) return po1.absolute-point-origin == po2.absolute-point-origin; else if constexpr (is-derived-from-specialization-of<PO1, relative_point_origin>()) return po1.absolute-point-origin == po2; else if constexpr (is-derived-from-specialization-of<PO2, relative_point_origin>()) return po1 == po2.absolute-point-origin; else return false;

5.7.2.5.2 Default [qty.def.pt.orig]

template<Reference R> consteval PointOriginFor<get_quantity_spec(R{})> auto default_point_origin(R);
Effects: Equivalent to: if constexpr (requires { get_unit(R{}).point-origin; }) return get_unit(R{}).point-origin; else return zeroth_point_origin<get_quantity_spec(R{})>;