From f281e417e299466e7ed9e6c81b5131442de1af2d Mon Sep 17 00:00:00 2001 From: Andy Little Date: Thu, 14 May 2020 17:41:04 +0100 Subject: [PATCH] Experimental branch using angle as a dimension. Added dim_angle, Angle concept etc. Not really for merging, but fun to play with.(The main problem is that it doesnt conform to SI) See https://github.com/mpusz/units/issues/99 Could try adding degrees etc in same way as non-si units --- example/CMakeLists.txt | 1 + example/experimental_angle.cpp | 22 ++++++++++++ src/include/units/physical/dimensions.h | 12 +++++++ src/include/units/physical/si/angle.h | 47 ++++++++++++++++++++++++ src/include/units/physical/si/torque.h | 48 +++++++++++++++++++++++++ 5 files changed, 130 insertions(+) create mode 100644 example/experimental_angle.cpp create mode 100644 src/include/units/physical/si/angle.h create mode 100644 src/include/units/physical/si/torque.h diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 95137ace..7d0e2403 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -35,6 +35,7 @@ add_example(capacitor_time_curve) add_example(clcpp_response) add_example(conversion_factor) add_example(kalman_filter-alpha_beta_filter_example2) +add_example(experimental_angle) conan_check_testing(linear_algebra) add_example(linear_algebra) diff --git a/example/experimental_angle.cpp b/example/experimental_angle.cpp new file mode 100644 index 00000000..89a25f18 --- /dev/null +++ b/example/experimental_angle.cpp @@ -0,0 +1,22 @@ + + + +#include +#include +#include +#include +#include + +using namespace units; +using namespace units::physical::si::literals; + +int main() +{ + auto torque = 20.0q_Nm; + auto energy = 20.0q_J; + + physical::Angle angle = torque/energy; + + std::cout << angle <<'\n'; +} + diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 5a1a9cba..10a10a32 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -58,6 +58,9 @@ struct dim_substance : base_dimension<"N", U> {}; template struct dim_luminous_intensity : base_dimension<"J", U> {}; +template +struct dim_angle : base_dimension<"A", U> {}; + // ------------------------ derived dimensions ----------------------------- template T> @@ -84,6 +87,9 @@ struct dim_momentum : derived_dimension, exp> {}; template F, DimensionOf L> struct dim_energy : derived_dimension, exp> {}; +template E, DimensionOf A> +struct dim_torque : derived_dimension, exp> {}; + template M, DimensionOf L> struct dim_density : derived_dimension, exp> {}; @@ -197,6 +203,9 @@ concept Substance = QuantityOf; template concept LuminousIntensity = QuantityOf; +template +concept Angle = QuantityOf; + template concept Frequency = QuantityOf; @@ -221,6 +230,9 @@ concept Momentum = QuantityOf; template concept Energy = QuantityOf; +template +concept Torque = QuantityOf; + template concept Density = QuantityOf; diff --git a/src/include/units/physical/si/angle.h b/src/include/units/physical/si/angle.h new file mode 100644 index 00000000..f19158cb --- /dev/null +++ b/src/include/units/physical/si/angle.h @@ -0,0 +1,47 @@ +// 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 +#include + +namespace units::physical::si { + +struct radian : named_unit {}; + +struct dim_angle : physical::dim_angle {}; + +template +using angle = quantity; + +inline namespace literals { + +// rad +constexpr auto operator"" q_rad(unsigned long long l) { return length(l); } +constexpr auto operator"" q_rad(long double l) { return length(l); } + + +} // namespace literals + +} // namespace units::physical::si diff --git a/src/include/units/physical/si/torque.h b/src/include/units/physical/si/torque.h new file mode 100644 index 00000000..c6fbe4d8 --- /dev/null +++ b/src/include/units/physical/si/torque.h @@ -0,0 +1,48 @@ +// 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 +#include +#include +#include + +namespace units::physical::si { + +struct newton_metre : named_unit {}; + +struct dim_torque : physical::dim_torque {}; + +template +using torque = quantity; + +inline namespace literals { + +// Nm +constexpr auto operator"" q_Nm(unsigned long long l) { return torque(l); } +constexpr auto operator"" q_Nm(long double l) { return torque(l); } + +} // namespace literals + +} // namespace units::physical::si