From 1cec3d48671484702e24c2cc327e2a705d831d0a Mon Sep 17 00:00:00 2001 From: Mateusz Pusz Date: Sun, 25 Dec 2022 17:20:44 +0100 Subject: [PATCH] refactor: _chrono.h_, _math.h_, and _random.h_ move to `utlitity` CMake module --- example/glide_computer/CMakeLists.txt | 2 +- example/kalman_filter/CMakeLists.txt | 16 +++--- src/CMakeLists.txt | 5 +- src/core/CMakeLists.txt | 8 +-- src/utility/CMakeLists.txt | 27 +++++++++ src/{core => utility}/include/units/chrono.h | 0 src/{core => utility}/include/units/math.h | 59 ++++++++++++++++++++ src/{core => utility}/include/units/random.h | 0 8 files changed, 100 insertions(+), 17 deletions(-) create mode 100644 src/utility/CMakeLists.txt rename src/{core => utility}/include/units/chrono.h (100%) rename src/{core => utility}/include/units/math.h (86%) rename src/{core => utility}/include/units/random.h (100%) diff --git a/example/glide_computer/CMakeLists.txt b/example/glide_computer/CMakeLists.txt index 7c19f4db..01e64578 100644 --- a/example/glide_computer/CMakeLists.txt +++ b/example/glide_computer/CMakeLists.txt @@ -23,5 +23,5 @@ cmake_minimum_required(VERSION 3.2) add_library(glide_computer STATIC include/geographic.h glide_computer.cpp include/glide_computer.h) -target_link_libraries(glide_computer PRIVATE mp-units::core-fmt PUBLIC mp-units::si example_utils) +target_link_libraries(glide_computer PRIVATE mp-units::core-fmt PUBLIC mp-units::si mp-units::utility example_utils) target_include_directories(glide_computer PUBLIC include) diff --git a/example/kalman_filter/CMakeLists.txt b/example/kalman_filter/CMakeLists.txt index 79bd7cfc..f1370018 100644 --- a/example/kalman_filter/CMakeLists.txt +++ b/example/kalman_filter/CMakeLists.txt @@ -30,11 +30,11 @@ function(add_example target) target_link_libraries(${target} PRIVATE ${ARGN}) endfunction() -add_example(kalman_filter-example_1 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_2 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_3 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_4 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_5 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_6 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_7 mp-units::core-fmt mp-units::si) -add_example(kalman_filter-example_8 mp-units::core-fmt mp-units::si) +add_example(kalman_filter-example_1 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_2 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_3 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_4 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_5 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_6 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_7 mp-units::core-fmt mp-units::si mp-units::utility) +add_example(kalman_filter-example_8 mp-units::core-fmt mp-units::si mp-units::utility) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 32a5e555..3de4c96e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,10 +41,13 @@ add_subdirectory(core) add_subdirectory(core-fmt) add_subdirectory(core-io) add_subdirectory(systems) +add_subdirectory(utility) # project-wide wrapper add_library(mp-units INTERFACE) -target_link_libraries(mp-units INTERFACE mp-units::core mp-units::core-io mp-units::core-fmt mp-units::systems) +target_link_libraries( + mp-units INTERFACE mp-units::core mp-units::core-io mp-units::core-fmt mp-units::systems mp-units::utility +) add_library(mp-units::mp-units ALIAS mp-units) install(TARGETS mp-units EXPORT mp-unitsTargets) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 04df1b6f..cc5187bd 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -37,17 +37,11 @@ check_libcxx_in_use(${projectPrefix}LIBCXX) add_library( mp-units-core INTERFACE - # include/units/chrono.h include/units/customization_points.h include/units/dimension.h - # include/units/generic/angle.h - include/units/generic/dimensionless.h - # include/units/generic/solid_angle.h - include/units/math.h include/units/quantity.h - # include/units/quantity_point.h + include/units/quantity_point.h include/units/quantity_spec.h - include/units/random.h include/units/reference.h include/units/system_reference.h include/units/unit.h diff --git a/src/utility/CMakeLists.txt b/src/utility/CMakeLists.txt new file mode 100644 index 00000000..3fadb69f --- /dev/null +++ b/src/utility/CMakeLists.txt @@ -0,0 +1,27 @@ +# 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. + +cmake_minimum_required(VERSION 3.19) + +add_units_module(utility DEPENDENCIES mp-units::core mp-units::isq mp-units::si mp-units::angular HEADERS include/units/chrono.h + include/units/math.h + include/units/random.h) diff --git a/src/core/include/units/chrono.h b/src/utility/include/units/chrono.h similarity index 100% rename from src/core/include/units/chrono.h rename to src/utility/include/units/chrono.h diff --git a/src/core/include/units/math.h b/src/utility/include/units/math.h similarity index 86% rename from src/core/include/units/math.h rename to src/utility/include/units/math.h index e97babb9..c93e87b5 100644 --- a/src/core/include/units/math.h +++ b/src/utility/include/units/math.h @@ -22,6 +22,7 @@ #pragma once +#include #include #include #include @@ -354,4 +355,62 @@ template Q> } // namespace isq +namespace angular { + +template Q> + requires treat_as_floating_point +[[nodiscard]] inline quantity_of auto sin(const Q& q) noexcept + requires requires { sin(q.number()); } || requires { std::sin(q.number()); } +{ + using std::sin; + return quantity{sin(q[radian].number())}; +} + +template Q> + requires treat_as_floating_point +[[nodiscard]] inline quantity_of auto cos(const Q& q) noexcept + requires requires { cos(q.number()); } || requires { std::cos(q.number()); } +{ + using std::cos; + return quantity{cos(q[radian].number())}; +} + +template Q> + requires treat_as_floating_point +[[nodiscard]] inline quantity_of auto tan(const Q& q) noexcept + requires requires { tan(q.number()); } || requires { std::tan(q.number()); } +{ + using std::tan; + return quantity{tan(q[radian].number())}; +} + +template Q> + requires treat_as_floating_point +[[nodiscard]] inline quantity_of auto asin(const Q& q) noexcept + requires requires { asin(q.number()); } || requires { std::asin(q.number()); } +{ + using std::asin; + return asin(quantity_cast(q).number()) * angle[radian]; +} + +template Q> + requires treat_as_floating_point +[[nodiscard]] inline quantity_of auto acos(const Q& q) noexcept + requires requires { acos(q.number()); } || requires { std::acos(q.number()); } +{ + using std::acos; + return acos(quantity_cast(q).number()) * angle[radian]; +} + +template Q> + requires treat_as_floating_point +[[nodiscard]] inline quantity_of auto atan(const Q& q) noexcept + requires requires { atan(q.number()); } || requires { std::atan(q.number()); } +{ + using std::atan; + return atan(quantity_cast(q).number()) * angle[radian]; +} + +} // namespace angular + } // namespace units diff --git a/src/core/include/units/random.h b/src/utility/include/units/random.h similarity index 100% rename from src/core/include/units/random.h rename to src/utility/include/units/random.h