Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
Loading...
Searching...
No Matches
Angle.hpp
Go to the documentation of this file.
1// Copyright © 2020-2024 Alexandre Coderre-Chabot
2//
3// This file is part of Physical Quantities (PhQ), a C++ library of physical quantities, physical
4// models, and units of measure for scientific computing.
5//
6// Physical Quantities is hosted at:
7// https://github.com/acodcha/phq
8//
9// Physical Quantities is licensed under the MIT License:
10// https://mit-license.org
11//
12// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
13// associated documentation files (the "Software"), to deal in the Software without restriction,
14// including without limitation the rights to use, copy, modify, merge, publish, distribute,
15// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17// - The above copyright notice and this permission notice shall be included in all copies or
18// substantial portions of the Software.
19// - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
20// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM
23// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25#ifndef PHQ_UNIT_ANGLE_HPP
26#define PHQ_UNIT_ANGLE_HPP
27
28#include <cstddef>
29#include <cstdint>
30#include <functional>
31#include <map>
32#include <ostream>
33#include <string_view>
34#include <unordered_map>
35
36#include "../Base.hpp"
37#include "../Dimension/ElectricCurrent.hpp"
38#include "../Dimension/Length.hpp"
39#include "../Dimension/LuminousIntensity.hpp"
40#include "../Dimension/Mass.hpp"
41#include "../Dimension/SubstanceAmount.hpp"
42#include "../Dimension/Temperature.hpp"
43#include "../Dimension/Time.hpp"
44#include "../Dimensions.hpp"
45#include "../Unit.hpp"
46#include "../UnitSystem.hpp"
47
48namespace PhQ {
49
50namespace Unit {
51
52/// \brief Angle units.
53enum class Angle : int8_t {
54 /// \brief Radian (rad) angle unit.
55 Radian,
56
57 /// \brief Degree (deg) angle unit.
58 Degree,
59
60 /// \brief Arcminute (arcmin) angle unit.
62
63 /// \brief Arcsecond (arcsec) angle unit.
65
66 /// \brief Revolution (rev) angle unit.
68};
69
70} // namespace Unit
71
72/// \brief Standard angle unit: radian (rad).
73template <>
74inline constexpr const Unit::Angle Standard<Unit::Angle>{Unit::Angle::Radian};
75
76/// \brief Physical dimension set of angle units.
77template <>
78inline constexpr const Dimensions RelatedDimensions<Unit::Angle>{Dimensionless};
79
80inline std::ostream& operator<<(std::ostream& stream, const Unit::Angle unit) {
81 stream << Abbreviation(unit);
82 return stream;
83}
84
85namespace Internal {
86
87template <>
88inline const std::map<UnitSystem, Unit::Angle> ConsistentUnits<Unit::Angle>{
93};
94
95template <>
96inline const std::map<Unit::Angle, UnitSystem> RelatedUnitSystems<Unit::Angle>{};
97
98template <>
99inline const std::map<Unit::Angle, std::string_view> Abbreviations<Unit::Angle>{
100 {Unit::Angle::Radian, "rad" },
101 {Unit::Angle::Degree, "deg" },
102 {Unit::Angle::Arcminute, "arcmin"},
103 {Unit::Angle::Arcsecond, "arcsec"},
104 {Unit::Angle::Revolution, "rev" },
105};
106
107// clang-format off
108
109template <>
110inline const std::unordered_map<std::string_view, Unit::Angle> Spellings<Unit::Angle>{
111 {"rad", Unit::Angle::Radian },
112 {"radian", Unit::Angle::Radian },
113 {"radians", Unit::Angle::Radian },
114 {"deg", Unit::Angle::Degree },
115 {"degree", Unit::Angle::Degree },
116 {"degrees", Unit::Angle::Degree },
117 {"°", Unit::Angle::Degree },
119 {"am", Unit::Angle::Arcminute },
120 {"arcmin", Unit::Angle::Arcminute },
121 {"arcminute", Unit::Angle::Arcminute },
122 {"arcminutes", Unit::Angle::Arcminute },
123 {"\"", Unit::Angle::Arcsecond },
124 {"as", Unit::Angle::Arcsecond },
125 {"arcs", Unit::Angle::Arcsecond },
126 {"arcsec", Unit::Angle::Arcsecond },
127 {"arcsecond", Unit::Angle::Arcsecond },
128 {"arcseconds", Unit::Angle::Arcsecond },
130 {"revolution", Unit::Angle::Revolution},
131 {"revolutions", Unit::Angle::Revolution},
132};
133
134// clang-format on
135
136template <>
137template <typename NumericType>
138inline constexpr void Conversion<Unit::Angle, Unit::Angle::Radian>::FromStandard(
139 NumericType& /*value*/) noexcept {}
140
141template <>
142template <typename NumericType>
143inline constexpr void Conversion<Unit::Angle, Unit::Angle::Radian>::ToStandard(
144 NumericType& /*value*/) noexcept {}
145
146template <>
147template <typename NumericType>
148inline constexpr void Conversion<Unit::Angle, Unit::Angle::Degree>::FromStandard(
149 NumericType& value) noexcept {
150 value *= static_cast<NumericType>(180.0L) / Pi<NumericType>;
151}
152
153template <>
154template <typename NumericType>
155inline constexpr void Conversion<Unit::Angle, Unit::Angle::Degree>::ToStandard(
156 NumericType& value) noexcept {
157 value *= Pi<NumericType> / static_cast<NumericType>(180.0L);
158}
159
160template <>
161template <typename NumericType>
162inline constexpr void Conversion<Unit::Angle, Unit::Angle::Arcminute>::FromStandard(
163 NumericType& value) noexcept {
164 value *= static_cast<NumericType>(10800.0L) / Pi<NumericType>;
165}
166
167template <>
168template <typename NumericType>
169inline constexpr void Conversion<Unit::Angle, Unit::Angle::Arcminute>::ToStandard(
170 NumericType& value) noexcept {
171 value *= Pi<NumericType> / static_cast<NumericType>(10800.0L);
172}
173
174template <>
175template <typename NumericType>
176inline constexpr void Conversion<Unit::Angle, Unit::Angle::Arcsecond>::FromStandard(
177 NumericType& value) noexcept {
178 value *= static_cast<NumericType>(648000.0L) / Pi<NumericType>;
179}
180
181template <>
182template <typename NumericType>
183inline constexpr void Conversion<Unit::Angle, Unit::Angle::Arcsecond>::ToStandard(
184 NumericType& value) noexcept {
185 value *= Pi<NumericType> / static_cast<NumericType>(648000.0L);
186}
187
188template <>
189template <typename NumericType>
190inline constexpr void Conversion<Unit::Angle, Unit::Angle::Revolution>::FromStandard(
191 NumericType& value) noexcept {
192 value *= static_cast<NumericType>(0.5L) / Pi<NumericType>;
193}
194
195template <>
196template <typename NumericType>
197inline constexpr void Conversion<Unit::Angle, Unit::Angle::Revolution>::ToStandard(
198 NumericType& value) noexcept {
199 value *= static_cast<NumericType>(2.0L) * Pi<NumericType>;
200}
201
202template <typename NumericType>
203inline const std::map<Unit::Angle, std::function<void(NumericType* values, const std::size_t size)>>
204 MapOfConversionsFromStandard<Unit::Angle, NumericType>{
206 Conversions<Unit::Angle, Unit::Angle::Radian>::FromStandard<NumericType> },
208 Conversions<Unit::Angle, Unit::Angle::Degree>::FromStandard<NumericType> },
210 Conversions<Unit::Angle, Unit::Angle::Arcminute>::FromStandard<NumericType> },
212 Conversions<Unit::Angle, Unit::Angle::Arcsecond>::FromStandard<NumericType> },
214 Conversions<Unit::Angle, Unit::Angle::Revolution>::FromStandard<NumericType>},
215};
216
217template <typename NumericType>
218inline const std::
219 map<Unit::Angle, std::function<void(NumericType* const values, const std::size_t size)>>
220 MapOfConversionsToStandard<Unit::Angle, NumericType>{
222 Conversions<Unit::Angle, Unit::Angle::Radian>::ToStandard<NumericType> },
224 Conversions<Unit::Angle, Unit::Angle::Degree>::ToStandard<NumericType> },
226 Conversions<Unit::Angle, Unit::Angle::Arcminute>::ToStandard<NumericType> },
228 Conversions<Unit::Angle, Unit::Angle::Arcsecond>::ToStandard<NumericType> },
230 Conversions<Unit::Angle, Unit::Angle::Revolution>::ToStandard<NumericType>},
231};
232
233} // namespace Internal
234
235} // namespace PhQ
236
237#endif // PHQ_UNIT_ANGLE_HPP
Angle
Angle units.
Definition Angle.hpp:53
@ Radian
Radian (rad) angle unit.
@ Degree
Degree (deg) angle unit.
@ Arcminute
Arcminute (arcmin) angle unit.
@ Arcsecond
Arcsecond (arcsec) angle unit.
@ Revolution
Revolution (rev) angle unit.
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
@ FootPoundSecondRankine
Foot-pound-second-rankine (ft·lbf·s·°R) system.
@ MillimetreGramSecondKelvin
Millimetre-gram-second-kelvin (mm·g·s·K) system.
@ MetreKilogramSecondKelvin
Metre-kilogram-second-kelvin (m·kg·s·K) system.
@ InchPoundSecondRankine
Inch-pound-second-rankine (in·lbf·s·°R) system.
constexpr Dimensions Dimensionless
Dimensionless physical dimension set. This dimension set has all base dimensions of zero....
std::string_view Abbreviation(const Enumeration enumeration)
Returns the abbreviation of a given enumeration value. For example, PhQ::Abbreviation(PhQ::Unit::Time...
Definition Base.hpp:89