mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-03 12:24:26 +02:00
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
This commit is contained in:
committed by
Mateusz Pusz
parent
51f3739e46
commit
f281e417e2
@@ -35,6 +35,7 @@ add_example(capacitor_time_curve)
|
|||||||
add_example(clcpp_response)
|
add_example(clcpp_response)
|
||||||
add_example(conversion_factor)
|
add_example(conversion_factor)
|
||||||
add_example(kalman_filter-alpha_beta_filter_example2)
|
add_example(kalman_filter-alpha_beta_filter_example2)
|
||||||
|
add_example(experimental_angle)
|
||||||
|
|
||||||
conan_check_testing(linear_algebra)
|
conan_check_testing(linear_algebra)
|
||||||
add_example(linear_algebra)
|
add_example(linear_algebra)
|
||||||
|
22
example/experimental_angle.cpp
Normal file
22
example/experimental_angle.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <units/physical/si/length.h>
|
||||||
|
#include <units/physical/si/torque.h>
|
||||||
|
#include <units/physical/si/energy.h>
|
||||||
|
#include <units/format.h>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
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';
|
||||||
|
}
|
||||||
|
|
@@ -58,6 +58,9 @@ struct dim_substance : base_dimension<"N", U> {};
|
|||||||
template<Unit U>
|
template<Unit U>
|
||||||
struct dim_luminous_intensity : base_dimension<"J", U> {};
|
struct dim_luminous_intensity : base_dimension<"J", U> {};
|
||||||
|
|
||||||
|
template<Unit U>
|
||||||
|
struct dim_angle : base_dimension<"A", U> {};
|
||||||
|
|
||||||
// ------------------------ derived dimensions -----------------------------
|
// ------------------------ derived dimensions -----------------------------
|
||||||
|
|
||||||
template<typename Child, Unit U, DimensionOf<dim_time> T>
|
template<typename Child, Unit U, DimensionOf<dim_time> T>
|
||||||
@@ -84,6 +87,9 @@ struct dim_momentum : derived_dimension<Child, U, exp<M, 1>, exp<V, 1>> {};
|
|||||||
template<typename Child, Unit U, DimensionOf<dim_force> F, DimensionOf<dim_length> L>
|
template<typename Child, Unit U, DimensionOf<dim_force> F, DimensionOf<dim_length> L>
|
||||||
struct dim_energy : derived_dimension<Child, U, exp<F, 1>, exp<L, 1>> {};
|
struct dim_energy : derived_dimension<Child, U, exp<F, 1>, exp<L, 1>> {};
|
||||||
|
|
||||||
|
template<typename Child, Unit U, DimensionOf<dim_energy> E, DimensionOf<dim_angle> A>
|
||||||
|
struct dim_torque : derived_dimension<Child, U, exp<E, 1>, exp<A, 1>> {};
|
||||||
|
|
||||||
template<typename Child, Unit U, DimensionOf<dim_mass> M, DimensionOf<dim_length> L>
|
template<typename Child, Unit U, DimensionOf<dim_mass> M, DimensionOf<dim_length> L>
|
||||||
struct dim_density : derived_dimension<Child, U, exp<M, 1>, exp<L, -3>> {};
|
struct dim_density : derived_dimension<Child, U, exp<M, 1>, exp<L, -3>> {};
|
||||||
|
|
||||||
@@ -197,6 +203,9 @@ concept Substance = QuantityOf<T, dim_substance>;
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept LuminousIntensity = QuantityOf<T, dim_luminous_intensity>;
|
concept LuminousIntensity = QuantityOf<T, dim_luminous_intensity>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
concept Angle = QuantityOf<T, dim_angle>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept Frequency = QuantityOf<T, dim_frequency>;
|
concept Frequency = QuantityOf<T, dim_frequency>;
|
||||||
|
|
||||||
@@ -221,6 +230,9 @@ concept Momentum = QuantityOf<T, dim_momentum>;
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
concept Energy = QuantityOf<T, dim_energy>;
|
concept Energy = QuantityOf<T, dim_energy>;
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
concept Torque = QuantityOf<T, dim_torque>;
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
concept Density = QuantityOf<T, dim_density>;
|
concept Density = QuantityOf<T, dim_density>;
|
||||||
|
|
||||||
|
47
src/include/units/physical/si/angle.h
Normal file
47
src/include/units/physical/si/angle.h
Normal file
@@ -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 <units/physical/dimensions.h>
|
||||||
|
#include <units/physical/si/prefixes.h>
|
||||||
|
#include <units/quantity.h>
|
||||||
|
|
||||||
|
namespace units::physical::si {
|
||||||
|
|
||||||
|
struct radian : named_unit<radian, "rad", prefix> {};
|
||||||
|
|
||||||
|
struct dim_angle : physical::dim_angle<radian> {};
|
||||||
|
|
||||||
|
template<Unit U, Scalar Rep = double>
|
||||||
|
using angle = quantity<dim_angle, U, Rep>;
|
||||||
|
|
||||||
|
inline namespace literals {
|
||||||
|
|
||||||
|
// rad
|
||||||
|
constexpr auto operator"" q_rad(unsigned long long l) { return length<metre, std::int64_t>(l); }
|
||||||
|
constexpr auto operator"" q_rad(long double l) { return length<metre, long double>(l); }
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace literals
|
||||||
|
|
||||||
|
} // namespace units::physical::si
|
48
src/include/units/physical/si/torque.h
Normal file
48
src/include/units/physical/si/torque.h
Normal file
@@ -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 <units/physical/dimensions.h>
|
||||||
|
#include <units/physical/si/energy.h>
|
||||||
|
#include <units/physical/si/angle.h>
|
||||||
|
#include <units/physical/si/prefixes.h>
|
||||||
|
#include <units/quantity.h>
|
||||||
|
|
||||||
|
namespace units::physical::si {
|
||||||
|
|
||||||
|
struct newton_metre : named_unit<newton_metre, "Nm", prefix> {};
|
||||||
|
|
||||||
|
struct dim_torque : physical::dim_torque<dim_torque, newton_metre, dim_energy, dim_angle> {};
|
||||||
|
|
||||||
|
template<Unit U, Scalar Rep = double>
|
||||||
|
using torque = quantity<dim_torque, U, Rep>;
|
||||||
|
|
||||||
|
inline namespace literals {
|
||||||
|
|
||||||
|
// Nm
|
||||||
|
constexpr auto operator"" q_Nm(unsigned long long l) { return torque<newton_metre, std::int64_t>(l); }
|
||||||
|
constexpr auto operator"" q_Nm(long double l) { return torque<newton_metre, long double>(l); }
|
||||||
|
|
||||||
|
} // namespace literals
|
||||||
|
|
||||||
|
} // namespace units::physical::si
|
Reference in New Issue
Block a user