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:
Andy Little
2020-05-14 17:41:04 +01:00
committed by Mateusz Pusz
parent 51f3739e46
commit f281e417e2
5 changed files with 130 additions and 0 deletions

View File

@@ -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)

View 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';
}

View File

@@ -58,6 +58,9 @@ struct dim_substance : base_dimension<"N", U> {};
template<Unit U>
struct dim_luminous_intensity : base_dimension<"J", U> {};
template<Unit U>
struct dim_angle : base_dimension<"A", U> {};
// ------------------------ derived dimensions -----------------------------
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>
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>
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>
concept LuminousIntensity = QuantityOf<T, dim_luminous_intensity>;
template <typename T>
concept Angle = QuantityOf<T, dim_angle>;
template<typename T>
concept Frequency = QuantityOf<T, dim_frequency>;
@@ -221,6 +230,9 @@ concept Momentum = QuantityOf<T, dim_momentum>;
template<typename T>
concept Energy = QuantityOf<T, dim_energy>;
template<typename T>
concept Torque = QuantityOf<T, dim_torque>;
template<typename T>
concept Density = QuantityOf<T, dim_density>;

View 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

View 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