Skip to content

Commit

Permalink
xo-unit: + missing doc .rst files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rconybea committed May 19, 2024
1 parent 454b146 commit 8c09ee4
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
40 changes: 40 additions & 0 deletions docs/natural-unit-class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
.. _natural-unit-class:

Natural Unit
============

.. ditaa::

+----------------+----------------+
| quantity | xquantity |
+----------------+----------------+
| scaled_unit |
+---------------------------------+
|cYEL natural_unit |
+---------------------------------+
| bpu |
+----------------+ |
| bu_store | |
+----------------+----------------+
| basis_unit |
+---------------------------------+
| dimension |
+---------------------------------+

.. code-block:: cpp
#include <xo/unit/natural_unit.hpp>
Representation for the unit associated with a @ref quantity or xquantity.

- represents a cartesian product of basis units.
- constexpr implementation
- limited support for fractional dimensions such as time^-1/2

.. doxygenclass:: xo::qty::natural_unit

.. doxygengroup:: natural-unit-instance-vars
.. doxygengroup:: natural-unit-ctors
.. doxygengroup:: natural-unit-access-methods
.. doxygengroup:: natural-unit-methods
.. doxygengroup:: natural-unit-conversion-methods
59 changes: 59 additions & 0 deletions docs/scaled-unit-class.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.. _scaled-unit-class:

Scaled Unit
===========

.. ditaa::

+----------------+----------------+
| quantity | xquantity |
+----------------+----------------+
|cYEL scaled_unit |
+---------------------------------+
| natural_unit |
+---------------------------------+
| bpu |
+----------------+ |
| bu_store | |
+----------------+----------------+
| basis_unit |
+---------------------------------+
| dimension |
+---------------------------------+


.. code-block::cpp
#include <xo/unit/scaled_unit.hpp>
Result of mutliplication or division of natural units (:doc:`natural-unit-class`).

Motivation
----------

Consider multiplying two units:

.. code-block:: cpp
using namespace xo::qty;
constexpr auto u_prod = u::meter * u::kilometer;
How should we represent the product?

We don't want to mix units. Instead we consolidate on a common unit;
to do this we accumulate a product of conversion factors from such consolidation.

For example:

.. code-block:: cpp
static_assert(u_prod.natural_unit[0].bu() == detail::bu::meter);
static_assert(u_prod.natural_unit[0].power() == power_ratio_type(2));
static_assert(u_prod.outer_scale_factor_ == xo::ratio::ratio<int64_t>(1000));
static_assert(u_prod.outer_scale_sq_ == 1.0); // used if fractional dimension
Class
-----

.. doxygenclass:: xo::qty::scaled_unit

0 comments on commit 8c09ee4

Please sign in to comment.