From 10f8254cc8f72a9e240dd628cdb77ad75b068155 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 13 May 2022 09:56:58 +0200 Subject: [PATCH 01/18] style: `si.h` includes order fixed --- src/systems/si/include/units/isq/si/si.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/systems/si/include/units/isq/si/si.h b/src/systems/si/include/units/isq/si/si.h index 6a0d03c9..d7095a6e 100644 --- a/src/systems/si/include/units/isq/si/si.h +++ b/src/systems/si/include/units/isq/si/si.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -40,35 +41,36 @@ #include #include #include -#include -#include -#include -#include -#include -// TODO Add when downcasting issue is solved (collides with pressure) -// #include #include #include #include #include +#include #include +#include #include #include +#include #include #include #include #include #include -#include -// TODO Add when downcasting issue is solved (collides with frequency) -// #include -#include #include +#include #include #include #include #include +#include +#include #include #include #include // IWYU pragma: end_exports + +// TODO Add when downcasting issue is solved (collides with pressure) +// #include + +// TODO Add when downcasting issue is solved (collides with frequency) +// #include From 13f03bfe704083fb1e397f515fba08fd730823be Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 13 May 2022 14:31:13 +0200 Subject: [PATCH 02/18] feat: `luminous_flux` support added --- src/systems/isq/CMakeLists.txt | 1 + .../isq/include/units/isq/dimensions.h | 1 + .../units/isq/dimensions/luminous_flux.h | 36 ++++++++ src/systems/si/CMakeLists.txt | 1 + .../si/include/units/isq/si/luminous_flux.h | 89 +++++++++++++++++++ src/systems/si/include/units/isq/si/si.h | 1 + test/unit_test/static/si_test.cpp | 6 ++ 7 files changed, 135 insertions(+) create mode 100644 src/systems/isq/include/units/isq/dimensions/luminous_flux.h create mode 100644 src/systems/si/include/units/isq/si/luminous_flux.h diff --git a/src/systems/isq/CMakeLists.txt b/src/systems/isq/CMakeLists.txt index c7dffcfc..bb575c65 100644 --- a/src/systems/isq/CMakeLists.txt +++ b/src/systems/isq/CMakeLists.txt @@ -49,6 +49,7 @@ add_units_module( include/units/isq/dimensions/inductance.h include/units/isq/dimensions/length.h include/units/isq/dimensions/luminance.h + include/units/isq/dimensions/luminous_flux.h include/units/isq/dimensions/luminous_intensity.h include/units/isq/dimensions/magnetic_flux.h include/units/isq/dimensions/magnetic_induction.h diff --git a/src/systems/isq/include/units/isq/dimensions.h b/src/systems/isq/include/units/isq/dimensions.h index a4e8dd1d..4983390c 100644 --- a/src/systems/isq/include/units/isq/dimensions.h +++ b/src/systems/isq/include/units/isq/dimensions.h @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include diff --git a/src/systems/isq/include/units/isq/dimensions/luminous_flux.h b/src/systems/isq/include/units/isq/dimensions/luminous_flux.h new file mode 100644 index 00000000..a86a6285 --- /dev/null +++ b/src/systems/isq/include/units/isq/dimensions/luminous_flux.h @@ -0,0 +1,36 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include + +namespace units::isq { + +template +using dim_luminous_flux = dim_power; + +template +concept LuminousFlux = QuantityOfT; + +} // namespace units::isq diff --git a/src/systems/si/CMakeLists.txt b/src/systems/si/CMakeLists.txt index f591c780..052d6d3c 100644 --- a/src/systems/si/CMakeLists.txt +++ b/src/systems/si/CMakeLists.txt @@ -50,6 +50,7 @@ add_units_module( include/units/isq/si/inductance.h include/units/isq/si/length.h include/units/isq/si/luminance.h + include/units/isq/si/luminous_flux.h include/units/isq/si/luminous_intensity.h include/units/isq/si/magnetic_flux.h include/units/isq/si/magnetic_induction.h diff --git a/src/systems/si/include/units/isq/si/luminous_flux.h b/src/systems/si/include/units/isq/si/luminous_flux.h new file mode 100644 index 00000000..7d9592e3 --- /dev/null +++ b/src/systems/si/include/units/isq/si/luminous_flux.h @@ -0,0 +1,89 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +// IWYU pragma: begin_exports +#include +#include +#include +#include +// IWYU pragma: end_exports + +#include +#include + +namespace units::isq::si { + +// TODO Is this correct? Should we account for steradian here? How? + +struct lumen : named_scaled_unit {}; + +using dim_luminous_flux = dim_power; + +template U, Representation Rep = double> +using luminous_flux = power; + +#ifndef UNITS_NO_LITERALS + +inline namespace literals { + +// lm +constexpr auto operator"" _q_lm(unsigned long long l) +{ + gsl_ExpectsAudit(std::in_range(l)); + return luminous_flux(static_cast(l)); +} +constexpr auto operator"" _q_lm(long double l) { return luminous_flux(l); } + +} // namespace literals + +#endif // UNITS_NO_LITERALS + +#ifndef UNITS_NO_REFERENCES + +namespace luminous_flux_references { + +inline constexpr auto lm = reference{}; + +} // namespace luminous_flux_references + +namespace references { + +using namespace luminous_flux_references; + +} // namespace references + +#endif // UNITS_NO_REFERENCES + +} // namespace units::isq::si + +#ifndef UNITS_NO_ALIASES + +namespace units::aliases::isq::si::inline luminous_flux { + +template +using lm = units::isq::si::luminous_flux; + +} // namespace units::aliases::isq::si::inline luminous_flux + +#endif // UNITS_NO_ALIASES diff --git a/src/systems/si/include/units/isq/si/si.h b/src/systems/si/include/units/isq/si/si.h index d7095a6e..369d6f3d 100644 --- a/src/systems/si/include/units/isq/si/si.h +++ b/src/systems/si/include/units/isq/si/si.h @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 5155f916..ff32ecc7 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -239,6 +239,12 @@ static_assert(gray::symbol == "Gy"); static_assert(milligray::symbol == "mGy"); static_assert(kilogray::symbol == "kGy"); +// luminous flux + +static_assert(683_q_lm == 1_q_W); + +static_assert(lumen::symbol == "lm"); + /* ************** DERIVED DIMENSIONS IN TERMS OF BASE UNITS **************** */ // speed From 4a09edfcbff36dca639f77084175033a3c581043 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 13 May 2022 14:32:57 +0200 Subject: [PATCH 03/18] feat: `luminous_efficacy` SI defining constant support added --- src/systems/si/include/units/isq/si/constants.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/systems/si/include/units/isq/si/constants.h b/src/systems/si/include/units/isq/si/constants.h index a0097532..4b3928d0 100644 --- a/src/systems/si/include/units/isq/si/constants.h +++ b/src/systems/si/include/units/isq/si/constants.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -53,8 +54,8 @@ inline constexpr auto speed_of_light = speed(299'792'458) template inline constexpr auto hyperfine_structure_transition_frequency = frequency(9'192'631'770); -// template -// inline constexpr auto luminous_efficacy = 683_q_lm / 1_q_W; +template +inline constexpr auto luminous_efficacy = luminous_flux(683) / power(1); template inline constexpr auto standard_gravity = acceleration(9.80665); From a2a50622a4204e662ef0f88dc92fe10bfac3fe15 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Fri, 13 May 2022 18:35:25 +0200 Subject: [PATCH 04/18] style: `test_package/conanfile.py` reformatted to make pre-commit happy --- test_package/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 1afb178a..4f4506f5 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -21,8 +21,8 @@ # SOFTWARE. from conan import ConanFile -from conan.tools.cmake import CMake from conan.tools.build import cross_building +from conan.tools.cmake import CMake class TestPackageConan(ConanFile): From e5565c7d047ec69f486a44ddf89e2defc0783288 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 14 May 2022 11:29:23 +0200 Subject: [PATCH 05/18] docs: typo in the `CHANGELOG` fixed --- docs/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fc803b52..4e1072d2 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,7 +9,7 @@ - (!) refactor: `PrefixFamily` support removed - (!) refactor: `mi(naut)` renamed to `nmi` - (!) refactor: `knot` unit helper renamed to `kn` in FPS - - (!) refactor: `knot` text symbol changed from `"knot"` to `"kn`" + - (!) refactor: `knot` text symbol changed from `"knot"` to `"kn"` - refactor: `quantity` `op+()` and `op-()` reimplemented in terms of `reference` rather then `quantity` types - refactor(example): `glide_computer` now use dimensionless quantities with `ranged_representation` as `rep` - feat: HEP system support added (thanks [@RalphSteinhagen](https://github.com/RalphSteinhagen)) From 09a0c35cf3fbadb2acb6c9860a11967528952834 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Wed, 18 May 2022 15:56:58 +0200 Subject: [PATCH 06/18] docs: `src/include` directory does not exist anymore Resolves #363 --- docs/usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index bde4ea77..9e1ebe10 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -212,8 +212,8 @@ only a few of many options possible. Copy ^^^^ -As **mp-units** is a C++ header-only library you can simply copy *src/include* directory to -your source tree and use it as regular header files. +As **mp-units** is a C++ header-only library you can simply copy all needed ``src/*/include`` subdirectories +to your source tree. .. important:: From 49eb4523cd144a647c9f4adc0ec3d355db78f907 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sat, 21 May 2022 18:56:47 +0200 Subject: [PATCH 07/18] refactor: `units::` namespace prefix is no longer needed before `prefix` --- docs/framework/units.rst | 52 +++++++++---------- .../units/isq/iec80000/binary_prefixes.h | 12 ++--- .../si/include/units/isq/si/prefixes.h | 40 +++++++------- 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/docs/framework/units.rst b/docs/framework/units.rst index 8e37e3e2..ef619c8e 100644 --- a/docs/framework/units.rst +++ b/docs/framework/units.rst @@ -208,26 +208,26 @@ complete list of all the :term:`SI` prefixes supported by the library:: namespace si { - struct yocto : units::prefix {}; - struct zepto : units::prefix {}; - struct atto : units::prefix {}; - struct femto : units::prefix {}; - struct pico : units::prefix {}; - struct nano : units::prefix {}; - struct micro : units::prefix {}; - struct milli : units::prefix {}; - struct centi : units::prefix {}; - struct deci : units::prefix {}; - struct deca : units::prefix {}; - struct hecto : units::prefix {}; - struct kilo : units::prefix {}; - struct mega : units::prefix {}; - struct giga : units::prefix {}; - struct tera : units::prefix {}; - struct peta : units::prefix {}; - struct exa : units::prefix {}; - struct zetta : units::prefix {}; - struct yotta : units::prefix {}; + struct yocto : prefix {}; + struct zepto : prefix {}; + struct atto : prefix {}; + struct femto : prefix {}; + struct pico : prefix {}; + struct nano : prefix {}; + struct micro : prefix {}; + struct milli : prefix {}; + struct centi : prefix {}; + struct deci : prefix {}; + struct deca : prefix {}; + struct hecto : prefix {}; + struct kilo : prefix {}; + struct mega : prefix {}; + struct giga : prefix {}; + struct tera : prefix {}; + struct peta : prefix {}; + struct exa : prefix {}; + struct zetta : prefix {}; + struct yotta : prefix {}; } @@ -236,12 +236,12 @@ domain:: namespace iec80000 { - struct kibi : units::prefix {}; - struct mebi : units::prefix {}; - struct gibi : units::prefix {}; - struct tebi : units::prefix {}; - struct pebi : units::prefix {}; - struct exbi : units::prefix {}; + struct kibi : prefix {}; + struct mebi : prefix {}; + struct gibi : prefix {}; + struct tebi : prefix {}; + struct pebi : prefix {}; + struct exbi : prefix {}; } diff --git a/src/systems/isq-iec80000/include/units/isq/iec80000/binary_prefixes.h b/src/systems/isq-iec80000/include/units/isq/iec80000/binary_prefixes.h index 1ff0679e..f5e472ef 100644 --- a/src/systems/isq-iec80000/include/units/isq/iec80000/binary_prefixes.h +++ b/src/systems/isq-iec80000/include/units/isq/iec80000/binary_prefixes.h @@ -26,11 +26,11 @@ namespace units::isq::iec80000 { -struct kibi : units::prefix {}; -struct mebi : units::prefix {}; -struct gibi : units::prefix {}; -struct tebi : units::prefix {}; -struct pebi : units::prefix {}; -struct exbi : units::prefix {}; +struct kibi : prefix {}; +struct mebi : prefix {}; +struct gibi : prefix {}; +struct tebi : prefix {}; +struct pebi : prefix {}; +struct exbi : prefix {}; } // namespace units::isq::iec80000 diff --git a/src/systems/si/include/units/isq/si/prefixes.h b/src/systems/si/include/units/isq/si/prefixes.h index 0efabcf3..81f7c553 100644 --- a/src/systems/si/include/units/isq/si/prefixes.h +++ b/src/systems/si/include/units/isq/si/prefixes.h @@ -27,26 +27,26 @@ namespace units::isq::si { // clang-format off -struct yocto : units::prefix {}; -struct zepto : units::prefix {}; -struct atto : units::prefix {}; -struct femto : units::prefix {}; -struct pico : units::prefix {}; -struct nano : units::prefix {}; -struct micro : units::prefix {}; -struct milli : units::prefix {}; -struct centi : units::prefix {}; -struct deci : units::prefix {}; -struct deca : units::prefix {}; -struct hecto : units::prefix {}; -struct kilo : units::prefix {}; -struct mega : units::prefix {}; -struct giga : units::prefix {}; -struct tera : units::prefix {}; -struct peta : units::prefix {}; -struct exa : units::prefix {}; -struct zetta : units::prefix {}; -struct yotta : units::prefix {}; +struct yocto : prefix {}; +struct zepto : prefix {}; +struct atto : prefix {}; +struct femto : prefix {}; +struct pico : prefix {}; +struct nano : prefix {}; +struct micro : prefix {}; +struct milli : prefix {}; +struct centi : prefix {}; +struct deci : prefix {}; +struct deca : prefix {}; +struct hecto : prefix {}; +struct kilo : prefix {}; +struct mega : prefix {}; +struct giga : prefix {}; +struct tera : prefix {}; +struct peta : prefix {}; +struct exa : prefix {}; +struct zetta : prefix {}; +struct yotta : prefix {}; // clang-format on } // namespace units::isq::si From 842f2eaf2739c550dfb76121fa05fbc2fc6b285b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 22 May 2022 19:47:11 +0200 Subject: [PATCH 08/18] feat: `quantity` CTAD guide added --- src/core/include/units/quantity.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/include/units/quantity.h b/src/core/include/units/quantity.h index 39c3c805..d2a40fa2 100644 --- a/src/core/include/units/quantity.h +++ b/src/core/include/units/quantity.h @@ -449,6 +449,9 @@ template explicit(false) quantity(Rep&&)->quantity; #endif +template +explicit(false) quantity(quantity)->quantity; + template explicit(false) quantity(Rep)->quantity; From 4498adce7ca2db1b841e3e3c23f8e2d9fb59f110 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 22 May 2022 19:49:10 +0200 Subject: [PATCH 09/18] test: test for new `quantity` CTAD guide added --- test/unit_test/static/quantity_test.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index 29258656..7e4821a3 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -288,10 +288,13 @@ static_assert(get_length_derived_quantity() == 1_q_m); ///////// #if UNITS_COMP_GCC >= 11 || UNITS_COMP_CLANG > 15 -static_assert(std::is_same_v); -static_assert(std::is_same_v); +static_assert(std::is_same_v); +static_assert(std::is_same_v); #endif +static_assert( + std::is_same_v); + static_assert(is_same_v(123)}), length>); static_assert(is_same_v(123)}), speed>); // static_assert(is_same_v(123)}), length>); // TODO gcc ICE @@ -513,7 +516,9 @@ static_assert( is_same_v>); // TODO should we address fundamental types implicit // truncating conversions with concepts? static_assert(is_same_v>); -static_assert(compare>); // TODO should we address fundamental types implicit truncating conversions with concepts? +static_assert(compare>); // TODO should we address fundamental types implicit truncating + // conversions with concepts? static_assert(compare>); static_assert(is_same_v>); static_assert(compare>); From 0acfc8aa8681ced1cdc147ab8bd0e3704df38049 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 22 May 2022 19:49:55 +0200 Subject: [PATCH 10/18] refactor(example): `are_derivatives` renamed to `are_time_derivatives` in kalman examples --- example/kalman_filter/kalman.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/example/kalman_filter/kalman.h b/example/kalman_filter/kalman.h index a034d2db..f878335b 100644 --- a/example/kalman_filter/kalman.h +++ b/example/kalman_filter/kalman.h @@ -38,20 +38,20 @@ concept QuantityOrQuantityPoint = units::Quantity || units::QuantityPoint; // TODO Should it also account for `kinds`? template -inline constexpr bool are_derivatives = false; +inline constexpr bool are_time_derivatives = false; template -inline constexpr bool are_derivatives = true; +inline constexpr bool are_time_derivatives = true; template -inline constexpr bool are_derivatives = +inline constexpr bool are_time_derivatives = units::DimensionOfT && // TODO Think on how to simplify this - are_derivatives; + are_time_derivatives; // state template - requires(sizeof...(QQPs) > 0) && (sizeof...(QQPs) <= 3) && are_derivatives + requires(sizeof...(QQPs) > 0) && (sizeof...(QQPs) <= 3) && are_time_derivatives struct state { std::tuple variables_; constexpr state(QQPs... qqps) : variables_(std::move(qqps)...) {} From 7a368ab3e44c6351415ee720f7c9c808a3449489 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 22 May 2022 19:50:36 +0200 Subject: [PATCH 11/18] fix: `hyperfine_structure_transition_frequency` fixed to properly initialize `Rep` type --- src/systems/si/include/units/isq/si/constants.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/systems/si/include/units/isq/si/constants.h b/src/systems/si/include/units/isq/si/constants.h index 4b3928d0..79884577 100644 --- a/src/systems/si/include/units/isq/si/constants.h +++ b/src/systems/si/include/units/isq/si/constants.h @@ -52,7 +52,7 @@ template inline constexpr auto speed_of_light = speed(299'792'458); template -inline constexpr auto hyperfine_structure_transition_frequency = frequency(9'192'631'770); +inline constexpr auto hyperfine_structure_transition_frequency = frequency(Rep{9'192'631'770}); template inline constexpr auto luminous_efficacy = luminous_flux(683) / power(1); From a1637ebac6f9ac7d8b84c177eedd9f223a6fd6ae Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 22 May 2022 19:51:35 +0200 Subject: [PATCH 12/18] feat(example): `si_constants` example added --- example/CMakeLists.txt | 1 + example/si_constants.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 example/si_constants.cpp diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 76117aa4..6733348b 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -37,6 +37,7 @@ add_example(conversion_factor mp-units::core-fmt mp-units::core-io mp-units::si) add_example(custom_systems mp-units::core-io mp-units::si) add_example(hello_units mp-units::core-fmt mp-units::core-io mp-units::si mp-units::si-international) add_example(measurement mp-units::core-io mp-units::si) +add_example(si_constants mp-units::core-fmt mp-units::si) if(NOT ${projectPrefix}LIBCXX) add_subdirectory(glide_computer) diff --git a/example/si_constants.cpp b/example/si_constants.cpp new file mode 100644 index 00000000..c3c9ccf2 --- /dev/null +++ b/example/si_constants.cpp @@ -0,0 +1,40 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#include +#include +#include + +int main() +{ + using namespace units::isq::si::si2019; + + std::cout << "The seven defining constants of the SI and the seven corresponding units they define:\n"; + std::cout << STD_FMT::format("- hyperfine transition frequency of Cs: {:%.0Q %q}\n", + hyperfine_structure_transition_frequency<>); + std::cout << STD_FMT::format("- speed of light in vacuum: {:%.0Q %q}\n", speed_of_light<>); + std::cout << STD_FMT::format("- Planck constant: {}\n", planck_constant<>); + std::cout << STD_FMT::format("- elementary charge: {}\n", elementary_charge<>); + std::cout << STD_FMT::format("- Boltzmann constant: {}\n", boltzmann_constant<>); + std::cout << STD_FMT::format("- Avogadro constant: {}\n", avogadro_constant<>); + std::cout << STD_FMT::format("- luminous efficacy: {}\n", luminous_efficacy<>); +} From 768f400cc3b18e47f991d39b1f893cfbc945ddce Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 23 May 2022 09:56:45 +0200 Subject: [PATCH 13/18] test: quantity CTAD tests enabled only for the newest compilers --- test/unit_test/static/quantity_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index 7e4821a3..82bf34d0 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -290,10 +290,9 @@ static_assert(get_length_derived_quantity() == 1_q_m); #if UNITS_COMP_GCC >= 11 || UNITS_COMP_CLANG > 15 static_assert(std::is_same_v); static_assert(std::is_same_v); -#endif - static_assert( std::is_same_v); +#endif static_assert(is_same_v(123)}), length>); static_assert(is_same_v(123)}), speed>); From ef7e7c4cfcf2617982193d126a6d4300dbc7b999 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 23 May 2022 20:47:29 +0200 Subject: [PATCH 14/18] refactor: `detail::same_scaled_units` renamed to `detail::compatible_units` --- src/core/include/units/bits/derived_scaled_unit.h | 6 +++--- src/core/include/units/unit.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/include/units/bits/derived_scaled_unit.h b/src/core/include/units/bits/derived_scaled_unit.h index e94c7636..5844100e 100644 --- a/src/core/include/units/bits/derived_scaled_unit.h +++ b/src/core/include/units/bits/derived_scaled_unit.h @@ -26,12 +26,12 @@ namespace units::detail { -// same_scaled_units +// compatible_units template -inline constexpr bool same_scaled_units = false; +inline constexpr bool compatible_units = false; template -inline constexpr bool same_scaled_units, Us...> = (UnitOf && ...); +inline constexpr bool compatible_units, Us...> = (UnitOf && ...); // derived_scaled_unit diff --git a/src/core/include/units/unit.h b/src/core/include/units/unit.h index eddb7ea2..ad79bae3 100644 --- a/src/core/include/units/unit.h +++ b/src/core/include/units/unit.h @@ -145,7 +145,7 @@ struct derived_unit : downcast_dispatch> {}; * @tparam URest the units for the rest of dimensions from the recipe */ template - requires detail::same_scaled_units + requires detail::compatible_units struct derived_scaled_unit : downcast_dispatch> { static constexpr auto symbol = detail::derived_symbol_text(); }; From 38fb9911a9714fbdf6dd963e6ed287c5720d6086 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 24 May 2022 12:48:07 +0200 Subject: [PATCH 15/18] =?UTF-8?q?refactor:=20:boom:=20!=20"=20=E2=8B=85=20?= =?UTF-8?q?"=20replaced=20with=20"=E2=8B=85"=20in=20derived=20unit=20symbo?= =?UTF-8?q?ls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/framework/units.rst | 8 ++++---- .../include/units/bits/derived_symbol_text.h | 2 +- test/unit_test/runtime/fmt_test.cpp | 16 ++++++++-------- test/unit_test/runtime/fmt_units_test.cpp | 12 ++++++------ test/unit_test/static/fps_test.cpp | 8 ++++---- test/unit_test/static/si_test.cpp | 6 +++--- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/docs/framework/units.rst b/docs/framework/units.rst index ef619c8e..571be15f 100644 --- a/docs/framework/units.rst +++ b/docs/framework/units.rst @@ -303,15 +303,15 @@ will result in a different unnamed unit symbol: struct dim_momentum : derived_dimension, exponent, - exponent> {}; // kg ⋅ m/s + exponent> {}; // kg⋅m/s struct dim_momentum : derived_dimension, exponent, - exponent> {}; // m ⋅ kg/s + exponent> {}; // m⋅kg/s struct dim_momentum : derived_dimension, exponent, - exponent> {}; // 1/s ⋅ m ⋅ kg + exponent> {}; // 1/s⋅m⋅kg where ``kilogram_metre_per_second`` is defined as:: @@ -325,7 +325,7 @@ However, the easiest way to define momentum is just to use the struct dim_momentum : derived_dimension, - exponent> {}; // kg ⋅ m/s + exponent> {}; // kg⋅m/s In such a case the library will do its magic and will automatically unpack a provided derived dimension to its base dimensions in order to diff --git a/src/core/include/units/bits/derived_symbol_text.h b/src/core/include/units/bits/derived_symbol_text.h index 10a08de3..2d358725 100644 --- a/src/core/include/units/bits/derived_symbol_text.h +++ b/src/core/include/units/bits/derived_symbol_text.h @@ -42,7 +42,7 @@ constexpr auto operator_text() if constexpr (Divide && NegativeExpCount == 1) { return basic_fixed_string("/"); } else { - return basic_symbol_text(" ⋅ ", " "); + return basic_symbol_text("⋅", " "); } } } diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index 4e24c5cd..70c8c73f 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -317,7 +317,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 2_q_s * 2_q_m * 2_q_kg; os << q; - SECTION("iostream") { CHECK(os.str() == "8 m ⋅ kg ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "8 m⋅kg⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -329,7 +329,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 2._q_s * si::cgs::length(2) * si::cgs::mass(2); os << q; - SECTION("iostream") { CHECK(os.str() == "8 cm ⋅ g ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "8 cm⋅g⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -342,7 +342,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 4_q_km * 2_q_s; os << q; - SECTION("iostream") { CHECK(os.str() == "8 × 10³ m ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "8 × 10³ m⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -378,7 +378,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 2._q_s * si::cgs::length(2) * si::cgs::mass(2); os << q; - SECTION("iostream") { CHECK(os.str() == "8 × 10⁵ cm ⋅ g ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "8 × 10⁵ cm⋅g⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -390,7 +390,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 60_q_min / 2_q_km; os << q; - SECTION("iostream") { CHECK(os.str() == "30 [6 × 10⁻²] 1/m ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "30 [6 × 10⁻²] 1/m⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -402,7 +402,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 4_q_m * 2_q_s; os << q; - SECTION("iostream") { CHECK(os.str() == "8 m ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "8 m⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -414,7 +414,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 4_q_m * 2_q_s * 2_q_s; os << q; - SECTION("iostream") { CHECK(os.str() == "16 m ⋅ s²"); } + SECTION("iostream") { CHECK(os.str() == "16 m⋅s²"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } @@ -426,7 +426,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") const auto q = 8_q_s / 2_q_m / 2_q_m; os << q; - SECTION("iostream") { CHECK(os.str() == "2 1/m² ⋅ s"); } + SECTION("iostream") { CHECK(os.str() == "2 1/m²⋅s"); } SECTION("fmt with default format {} on a quantity") { CHECK(STD_FMT::format("{}", q) == os.str()); } diff --git a/test/unit_test/runtime/fmt_units_test.cpp b/test/unit_test/runtime/fmt_units_test.cpp index 8414e5a0..f862bffd 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -166,7 +166,7 @@ TEST_CASE("std::format on synthesized unit symbols", "[text][fmt]") SECTION("momentum") { - CHECK(STD_FMT::format("{}", 1_q_kg_m_per_s) == "1 kg ⋅ m/s"); + CHECK(STD_FMT::format("{}", 1_q_kg_m_per_s) == "1 kg⋅m/s"); CHECK(STD_FMT::format("{:%Q %Aq}", 1_q_kg_m_per_s) == "1 kg m/s"); } @@ -243,7 +243,7 @@ TEST_CASE("std::format on synthesized unit symbols", "[text][fmt]") SECTION("dynamic viscosity") { - CHECK(STD_FMT::format("{}", 1_q_Pa_s) == "1 Pa ⋅ s"); + CHECK(STD_FMT::format("{}", 1_q_Pa_s) == "1 Pa⋅s"); CHECK(STD_FMT::format("{:%Q %Aq}", 1_q_Pa_s) == "1 Pa s"); } @@ -251,19 +251,19 @@ TEST_CASE("std::format on synthesized unit symbols", "[text][fmt]") SECTION("specific heat capacity") { - CHECK(STD_FMT::format("{}", 1_q_J_per_kg_K) == "1 J ⋅ K⁻¹ ⋅ kg⁻¹"); + CHECK(STD_FMT::format("{}", 1_q_J_per_kg_K) == "1 J⋅K⁻¹⋅kg⁻¹"); CHECK(STD_FMT::format("{:%Q %Aq}", 1_q_J_per_kg_K) == "1 J K^-1 kg^-1"); } SECTION("molar heath capacity") { - CHECK(STD_FMT::format("{}", 1_q_J_per_mol_K) == "1 J ⋅ K⁻¹ ⋅ mol⁻¹"); + CHECK(STD_FMT::format("{}", 1_q_J_per_mol_K) == "1 J⋅K⁻¹⋅mol⁻¹"); CHECK(STD_FMT::format("{:%Q %Aq}", 1_q_J_per_mol_K) == "1 J K^-1 mol^-1"); } SECTION("thermal conductivity") { - CHECK(STD_FMT::format("{}", 1_q_W_per_m_K) == "1 W ⋅ m⁻¹ ⋅ K⁻¹"); + CHECK(STD_FMT::format("{}", 1_q_W_per_m_K) == "1 W⋅m⁻¹⋅K⁻¹"); CHECK(STD_FMT::format("{:%Q %Aq}", 1_q_W_per_m_K) == "1 W m^-1 K^-1"); } @@ -283,7 +283,7 @@ TEST_CASE("std::format on synthesized unit symbols", "[text][fmt]") SECTION("molar energy") { CHECK(STD_FMT::format("{}", 1_q_J_per_mol) == "1 J/mol"); } - SECTION("torque") { CHECK(STD_FMT::format("{}", 1_q_N_m_per_rad) == "1 N ⋅ m/rad"); } + SECTION("torque") { CHECK(STD_FMT::format("{}", 1_q_N_m_per_rad) == "1 N⋅m/rad"); } SECTION("storage_capacity") { diff --git a/test/unit_test/static/fps_test.cpp b/test/unit_test/static/fps_test.cpp index 8f241525..c86961c6 100644 --- a/test/unit_test/static/fps_test.cpp +++ b/test/unit_test/static/fps_test.cpp @@ -88,8 +88,8 @@ static_assert(10_q_pdl * 10_q_ft == 100_q_ft_pdl); static_assert(100_q_ft_pdl / 10_q_ft == 10_q_pdl); static_assert(100_q_ft_pdl / 10_q_pdl == 10_q_ft); -static_assert(detail::unit_text() == basic_symbol_text("ft ⋅ pdl", "ft pdl")); -static_assert(detail::unit_text() == basic_symbol_text("ft ⋅ lbf", "ft lbf")); +static_assert(detail::unit_text() == basic_symbol_text("ft⋅pdl", "ft pdl")); +static_assert(detail::unit_text() == basic_symbol_text("ft⋅lbf", "ft lbf")); /* ************** DERIVED DIMENSIONS IN TERMS OF OTHER UNITS **************** */ @@ -99,8 +99,8 @@ static_assert(10_q_ft_pdl / 10_q_s == 1_q_ft_pdl_per_s); static_assert(1_q_ft_pdl_per_s * 10_q_s == 10_q_ft_pdl); static_assert(10_q_ft_pdl / 1_q_ft_pdl_per_s == 10_q_s); -static_assert(detail::unit_text() == basic_symbol_text("ft ⋅ pdl/s", "ft pdl/s")); +static_assert(detail::unit_text() == basic_symbol_text("ft⋅pdl/s", "ft pdl/s")); static_assert(detail::unit_text() == - basic_symbol_text("ft ⋅ lbf/s", "ft lbf/s")); + basic_symbol_text("ft⋅lbf/s", "ft lbf/s")); } // namespace diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index ff32ecc7..48a7d24e 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -340,7 +340,7 @@ static_assert(detail::unit_text() == basic_ // dynamic viscosity static_assert(1_q_Pa_s == 1_q_N * 1_q_s / 1_q_m2); -static_assert(detail::unit_text() == basic_symbol_text("Pa ⋅ s", "Pa s")); +static_assert(detail::unit_text() == basic_symbol_text("Pa⋅s", "Pa s")); // [specific|molar] heath capacity @@ -350,13 +350,13 @@ static_assert(1_q_J_per_mol_K == 1_q_J_per_K / 1_q_mol); static_assert(detail::unit_text() == "J/K"); static_assert(detail::unit_text() == - basic_symbol_text("J ⋅ K⁻¹ ⋅ kg⁻¹", "J K^-1 kg^-1")); + basic_symbol_text("J⋅K⁻¹⋅kg⁻¹", "J K^-1 kg^-1")); // thermal conductivity static_assert(20_q_W_per_m_K * 10_q_m * 300_q_K == 60'000_q_W); static_assert(detail::unit_text() == - basic_symbol_text("W ⋅ m⁻¹ ⋅ K⁻¹", "W m^-1 K^-1")); + basic_symbol_text("W⋅m⁻¹⋅K⁻¹", "W m^-1 K^-1")); // electric field strength From c713ae7a43a33740a12e5899f385baf112add404 Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 6 Jun 2022 19:05:57 +0200 Subject: [PATCH 16/18] docs: P0847 reference removed Resolves #364 --- docs/framework/dimensions.rst | 2 -- docs/framework/units.rst | 2 -- docs/references.rst | 2 -- 3 files changed, 6 deletions(-) diff --git a/docs/framework/dimensions.rst b/docs/framework/dimensions.rst index 534db6b2..524d1b8b 100644 --- a/docs/framework/dimensions.rst +++ b/docs/framework/dimensions.rst @@ -115,8 +115,6 @@ analysis in the library to work as expected. :abbr:`CRTP (Curiously Recurring Template Parameter)` Idiom and is used in many places in this library to provide :ref:`design/downcasting:The Downcasting Facility`. - Hopefully if [P0847]_ will land in C++23 the additional CRTP-related - template parameter will be removed from this definition. Obtaining a Unit of the Dimension diff --git a/docs/framework/units.rst b/docs/framework/units.rst index 571be15f..f9981ba5 100644 --- a/docs/framework/units.rst +++ b/docs/framework/units.rst @@ -122,8 +122,6 @@ definitions of prefixed units using ``si::metre`` as a reference (i.e. :abbr:`CRTP (Curiously Recurring Template Parameter)` Idiom and is used in many places in this library to provide :ref:`design/downcasting:The Downcasting Facility`. - Hopefully if [P0847]_ will land in C++23 the additional CRTP-related - template parameter will be removed from this definition. It is important to notice here that :term:`SI` is not the only system used diff --git a/docs/references.rst b/docs/references.rst index 5e7c5842..35181006 100644 --- a/docs/references.rst +++ b/docs/references.rst @@ -2,5 +2,3 @@ References ========== .. [ISO80000] `ISO 80000-1:2009(E) "Quantities and units — Part 1: General" `_, International Organization for Standardization. - -.. [P0847] `"Deducing this" `_, Programming Language C++ proposal. From 955b6a7332d709c5823e94d58caf2d95faae9e0b Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Mon, 6 Jun 2022 19:57:17 +0200 Subject: [PATCH 17/18] ci: documentation generation fixed after latest Conan breaking changes --- .github/workflows/documentation.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index df86be5f..9ab7c1ed 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -25,16 +25,16 @@ name: Documentation on: push: paths: - - '.github/workflows/documentation.yml' - - 'docs/**' - - 'src/**' - - 'example/**' + - ".github/workflows/documentation.yml" + - "docs/**" + - "src/**" + - "example/**" pull_request: paths: - - '.github/workflows/documentation.yml' - - 'docs/**' - - 'src/**' - - 'example/**' + - ".github/workflows/documentation.yml" + - "docs/**" + - "src/**" + - "example/**" env: CC: gcc-10 @@ -65,7 +65,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v2 with: - python-version: '3.8' + python-version: "3.8" - name: Install Python dependencies run: | pip install -Ur docs/requirements.txt @@ -83,7 +83,7 @@ jobs: - name: Configure CMake working-directory: build run: | - cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake + cmake .. -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release - name: Generate documentation working-directory: build run: | From bd641228808588d5488c501c402817ac06c729ff Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Tue, 14 Jun 2022 11:18:29 +0200 Subject: [PATCH 18/18] docs: "Quantity-like Types" chapter added Refers to #365 --- docs/CMakeLists.txt | 2 ++ docs/_static/img/quantity_like.svg | 37 ++++++++++++++++++++++ docs/framework.rst | 1 + docs/framework/quantity_like.rst | 51 ++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 docs/_static/img/quantity_like.svg create mode 100644 docs/framework/quantity_like.rst diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 657bbdd5..04c7fc08 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -44,6 +44,7 @@ set(unitsSphinxDocs "${CMAKE_CURRENT_SOURCE_DIR}/_static/img/downcast_1.png" "${CMAKE_CURRENT_SOURCE_DIR}/_static/img/downcast_2.png" "${CMAKE_CURRENT_SOURCE_DIR}/_static/img/units.svg" + "${CMAKE_CURRENT_SOURCE_DIR}/_static/img/quantity_like.svg" "${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md" "${CMAKE_CURRENT_SOURCE_DIR}/design.rst" "${CMAKE_CURRENT_SOURCE_DIR}/design/directories.rst" @@ -88,6 +89,7 @@ set(unitsSphinxDocs "${CMAKE_CURRENT_SOURCE_DIR}/framework/dimensions.rst" "${CMAKE_CURRENT_SOURCE_DIR}/framework/quantities.rst" "${CMAKE_CURRENT_SOURCE_DIR}/framework/quantity_kinds.rst" + "${CMAKE_CURRENT_SOURCE_DIR}/framework/quantity_like.rst" "${CMAKE_CURRENT_SOURCE_DIR}/framework/quantity_points.rst" "${CMAKE_CURRENT_SOURCE_DIR}/framework/text_output.rst" "${CMAKE_CURRENT_SOURCE_DIR}/framework/units.rst" diff --git a/docs/_static/img/quantity_like.svg b/docs/_static/img/quantity_like.svg new file mode 100644 index 00000000..bcc1c0ff --- /dev/null +++ b/docs/_static/img/quantity_like.svg @@ -0,0 +1,37 @@ +quantityquantity_pointquantity_kindquantity_point_kindRepnumber()relative()common()relative() diff --git a/docs/framework.rst b/docs/framework.rst index ba17d2e2..cacfa71b 100644 --- a/docs/framework.rst +++ b/docs/framework.rst @@ -12,6 +12,7 @@ Framework Basics :maxdepth: 2 framework/basic_concepts + framework/quantity_like framework/quantities framework/quantity_points framework/quantity_kinds diff --git a/docs/framework/quantity_like.rst b/docs/framework/quantity_like.rst new file mode 100644 index 00000000..f963fdc7 --- /dev/null +++ b/docs/framework/quantity_like.rst @@ -0,0 +1,51 @@ +.. namespace:: units + +Quantity-like Types +=================== + +.. raw:: html + + + +.. + https://www.planttext.com + + @startuml + + skinparam monochrome true + skinparam shadowing false + skinparam backgroundColor #fcfcfc + + hide members + hide circle + + class quantity [[../framework/quantities.html]] + class quantity_point [[../framework/quantity_points.html]] + class quantity_kind [[../framework/quantity_kinds.html]] + class quantity_point_kind [[../framework/quantity_kinds.html#quantity-point-kinds]] + + Rep <-- quantity : number() + quantity <-- quantity_point : relative() + quantity <-- quantity_kind : common() + quantity_kind <-- quantity_point_kind : relative() + + @enduml + + +[ISO80000]_ defines a :term:`quantity` as a: + + Property of a phenomenon, body, or substance, where the property has a magnitude that can be expressed by + means of a number and a reference. + +You can use `quantity::number()` member function to get a concrete amount of a unit expressed with a specific +representation type ``Rep``. + +:term:`Kind of quantity ` is defined as: + + Aspect common to mutually comparable quantities. + +We can obtain a `quantity` with a `quantity_kind::common()` member function. + +`quantity_point` and `quantity_point_kind` are absolute quantities and quantity kinds relative to some +specific origin. `quantity` and `quantity_point` types can be obtained from them using a ``relative()`` member +function (`quantity_point::relative()`, `quantity_point_kind::relative()`).