forked from mpusz/mp-units
fix: add quantity_point::origin, like std::chrono::time_point::clock
This commit is contained in:
committed by
Mateusz Pusz
parent
7ed29807a6
commit
80eefec97c
@@ -23,7 +23,7 @@ The most important concepts in the library are `Unit`, `Dimension`,
|
||||
]
|
||||
|
||||
[<abstract>QuantityPoint|
|
||||
[quantity_point<Dimension, Unit, Rep>]
|
||||
[quantity_point<PointOrigin, Unit, Rep>]
|
||||
]
|
||||
|
||||
[<abstract>QuantityKind|
|
||||
@@ -39,6 +39,10 @@ The most important concepts in the library are `Unit`, `Dimension`,
|
||||
[Unit]<-[Quantity]
|
||||
[Quantity]<-[QuantityPoint]
|
||||
|
||||
[<abstract>PointOrigin]<-[QuantityPoint]
|
||||
[Dimension]<-[PointOrigin]
|
||||
[PointOrigin]<-[PointKind]
|
||||
|
||||
[<abstract>Kind]<-[QuantityKind]
|
||||
[Dimension]<-[Kind]
|
||||
[Quantity]<-[QuantityKind]
|
||||
@@ -60,7 +64,7 @@ derived dimensions. Examples: ``si::dim_time``, ``si::dim_length``, ``si::dim_sp
|
||||
specific representation. Examples: ``quantity<si::dim_time, si::second, int>``,
|
||||
``si::length<si::metre, int>``, ``si::speed<si::kilometre_per_hour>``.
|
||||
|
||||
`QuantityPoint` is an absolute `Quantity` with respect to some origin.
|
||||
`QuantityPoint` is an absolute `Quantity` with respect to an origin.
|
||||
Examples: timestamp (as opposed to duration), absolute temperature
|
||||
(as opposed to temperature difference).
|
||||
|
||||
@@ -68,6 +72,6 @@ Examples: timestamp (as opposed to duration), absolute temperature
|
||||
distance (``horizonal_kind``) and height (``vertical_kind``) are different kinds
|
||||
of a length quantity.
|
||||
|
||||
`QuantityPointKind` is an absolute `QuantityKind` with respect to some origin.
|
||||
`QuantityPointKind` is an absolute `QuantityKind` with respect to an origin.
|
||||
Examples: altitude is a quantity point of ``vertical_kind`` (as opposed to
|
||||
height).
|
||||
|
||||
@@ -106,8 +106,9 @@ Quantity Points
|
||||
+++++++++++++++
|
||||
|
||||
Quantity points have a more restricted set of operations.
|
||||
Quantity can be added to or subtracted from a quantity point.
|
||||
The result will always be a quantity point of the same dimension:
|
||||
Quantity can be added to or subtracted
|
||||
from a quantity point of the same origin.
|
||||
The result will always be a quantity point of the same origin:
|
||||
|
||||
.. code-block::
|
||||
:emphasize-lines: 3-5
|
||||
@@ -132,9 +133,10 @@ The result is a relative quantity of the same dimension:
|
||||
|
||||
It is not allowed to:
|
||||
|
||||
- add quantity points
|
||||
- subtract a quantity point from a quantity:
|
||||
- multiply nor divide quantity points with anything else.
|
||||
- add quantity points,
|
||||
- subtract a quantity point from a quantity,
|
||||
- multiply nor divide quantity points with anything else, and
|
||||
- mix quantity points with different origins:
|
||||
|
||||
.. code-block::
|
||||
:emphasize-lines: 3-5
|
||||
@@ -144,6 +146,8 @@ The result is a relative quantity of the same dimension:
|
||||
auto res1 = quantity_point{dist1} + quantity_point{dist2}; // ERROR
|
||||
auto res2 = dist1 - quantity_point{dist2}; // ERROR
|
||||
auto res3 = quantity_point{dist1} / (2 * s); // ERROR
|
||||
auto res4 = quantity_point{std::chrono::utc_second{1s}} +
|
||||
quantity_point{std::chrono::sys_second{1s}}; // ERROR
|
||||
|
||||
Quantity Point Kinds
|
||||
++++++++++++++++++++
|
||||
|
||||
@@ -3,9 +3,20 @@
|
||||
Quantity Points
|
||||
===============
|
||||
|
||||
A quantity point is an absolute quantity with respect to zero
|
||||
(which represents some origin) and is represented in the library with a
|
||||
`quantity_point` class template.
|
||||
A quantity point is an absolute quantity with respect to an origin
|
||||
and is represented in the library with a `quantity_point` class template.
|
||||
|
||||
Point Origins
|
||||
-------------
|
||||
|
||||
We need a `point_origin` to represent the origin of a quantity point::
|
||||
|
||||
struct mean_sea_level : point_origin<si::dim_length> {};
|
||||
|
||||
Quantities points with this origin represent a point from the mean sea level.
|
||||
|
||||
The library offers a `dynamic_origin<Dimension>`
|
||||
for quantity points whose origin is not specified in the type system.
|
||||
|
||||
|
||||
Construction
|
||||
@@ -14,7 +25,7 @@ Construction
|
||||
To create the quantity point object from a `quantity` we just have to pass
|
||||
the value to the `quantity_point` class template explicit constructor::
|
||||
|
||||
quantity_point<si::dim_length, si::kilometre, double> d(123 * km);
|
||||
quantity_point<dynamic_origin<si::dim_length>, si::kilometre, double> d(123 * km);
|
||||
|
||||
.. note::
|
||||
|
||||
@@ -25,7 +36,7 @@ the value to the `quantity_point` class template explicit constructor::
|
||||
`copy initialization <https://en.cppreference.com/w/cpp/language/copy_initialization>`_
|
||||
**does not compile**::
|
||||
|
||||
quantity_point<si::dim_length, si::kilometre, double> d = 123 * km; // ERROR
|
||||
quantity_point<dynamic_origin<si::dim_length>, si::kilometre, double> d = 123 * km; // ERROR
|
||||
|
||||
|
||||
Differences To Quantity
|
||||
|
||||
Reference in New Issue
Block a user