Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
SolidAngle.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_SOLID_ANGLE_HPP
26 #define PHQ_UNIT_SOLID_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 
48 namespace PhQ {
49 
50 namespace Unit {
51 
52 /// \brief Solid angle units. Measures the field of view of a portion of the surface of the unit
53 /// sphere viewed from the center of the unit sphere. Typically measured in steradians (sr), which
54 /// are square radians. The unit sphere has a total solid angle of 4π steradians.
55 enum class SolidAngle : int8_t {
56  /// \brief Steradian (sr) solid angle unit, also known as square radian.
57  Steradian,
58 
59  /// \brief Square degree (deg^2) solid angle unit.
61 
62  /// \brief Square arcminute (arcmin^2) solid angle unit.
64 
65  /// \brief Square arcsecond (arcsec^2) solid angle unit.
67 };
68 
69 } // namespace Unit
70 
71 /// \brief Standard solid angle unit: steradian (sr).
72 template <>
73 inline constexpr const Unit::SolidAngle Standard<Unit::SolidAngle>{Unit::SolidAngle::Steradian};
74 
75 /// \brief Physical dimension set of solid angle units.
76 template <>
77 inline constexpr const Dimensions RelatedDimensions<Unit::SolidAngle>{Dimensionless};
78 
79 inline std::ostream& operator<<(std::ostream& stream, const Unit::SolidAngle unit) {
80  stream << Abbreviation(unit);
81  return stream;
82 }
83 
84 namespace Internal {
85 
86 template <>
87 inline const std::map<UnitSystem, Unit::SolidAngle> ConsistentUnits<Unit::SolidAngle>{
92 };
93 
94 template <>
95 inline const std::map<Unit::SolidAngle, UnitSystem> RelatedUnitSystems<Unit::SolidAngle>{};
96 
97 template <>
98 inline const std::map<Unit::SolidAngle, std::string_view> Abbreviations<Unit::SolidAngle>{
100  {Unit::SolidAngle::SquareDegree, "deg^2" },
101  {Unit::SolidAngle::SquareArcminute, "arcmin^2"},
102  {Unit::SolidAngle::SquareArcsecond, "arcsec^2"},
103 };
104 
105 // clang-format off
106 
107 template <>
108 inline const std::unordered_map<std::string_view, Unit::SolidAngle> Spellings<Unit::SolidAngle>{
110  {"rad^2", Unit::SolidAngle::SquareDegree },
112  {"radian^2", Unit::SolidAngle::SquareDegree },
113  {"radian2", Unit::SolidAngle::SquareDegree },
114  {"radians^2", Unit::SolidAngle::SquareDegree },
115  {"radians2", Unit::SolidAngle::SquareDegree },
116  {"deg^2", Unit::SolidAngle::SquareDegree },
118  {"degree^2", Unit::SolidAngle::SquareDegree },
119  {"degree2", Unit::SolidAngle::SquareDegree },
120  {"degrees^2", Unit::SolidAngle::SquareDegree },
121  {"degrees2", Unit::SolidAngle::SquareDegree },
128  {"arcmin^2", Unit::SolidAngle::SquareArcminute},
130  {"arcminute^2", Unit::SolidAngle::SquareArcminute},
131  {"arcminute2", Unit::SolidAngle::SquareArcminute},
132  {"arcminutes^2", Unit::SolidAngle::SquareArcminute},
133  {"arcminutes2", Unit::SolidAngle::SquareArcminute},
140  {"arcsec^2", Unit::SolidAngle::SquareArcsecond},
142  {"arcsecond^2", Unit::SolidAngle::SquareArcsecond},
143  {"arcsecond2", Unit::SolidAngle::SquareArcsecond},
144  {"arcseconds^2", Unit::SolidAngle::SquareArcsecond},
145  {"arcseconds2", Unit::SolidAngle::SquareArcsecond},
146 };
147 
148 // clang-format on
149 
150 template <>
151 template <typename NumericType>
152 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::Steradian>::FromStandard(
153  NumericType& /*value*/) noexcept {}
154 
155 template <>
156 template <typename NumericType>
157 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::Steradian>::ToStandard(
158  NumericType& /*value*/) noexcept {}
159 
160 template <>
161 template <typename NumericType>
162 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareDegree>::FromStandard(
163  NumericType& value) noexcept {
164  value *= static_cast<NumericType>(180.0L) * static_cast<NumericType>(180.0L)
165  / (Pi<NumericType> * Pi<NumericType>);
166 }
167 
168 template <>
169 template <typename NumericType>
170 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareDegree>::ToStandard(
171  NumericType& value) noexcept {
172  value *=
173  Pi<NumericType> * Pi<NumericType> / (static_cast<NumericType>(180.0L) * static_cast<NumericType>(180.0L));
174 }
175 
176 template <>
177 template <typename NumericType>
178 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareArcminute>::FromStandard(
179  NumericType& value) noexcept {
180  value *= static_cast<NumericType>(10800.0L) * static_cast<NumericType>(10800.0L)
181  / (Pi<NumericType> * Pi<NumericType>);
182 }
183 
184 template <>
185 template <typename NumericType>
186 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareArcminute>::ToStandard(
187  NumericType& value) noexcept {
188  value *=
189  Pi<NumericType> * Pi<NumericType> / (static_cast<NumericType>(10800.0L) * static_cast<NumericType>(10800.0L));
190 }
191 
192 template <>
193 template <typename NumericType>
194 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareArcsecond>::FromStandard(
195  NumericType& value) noexcept {
196  value *= static_cast<NumericType>(648000.0L) * static_cast<NumericType>(648000.0L)
197  / (Pi<NumericType> * Pi<NumericType>);
198 }
199 
200 template <>
201 template <typename NumericType>
202 inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareArcsecond>::ToStandard(
203  NumericType& value) noexcept {
204  value *=
205  Pi<NumericType> * Pi<NumericType> / (static_cast<NumericType>(648000.0L) * static_cast<NumericType>(648000.0L));
206 }
207 
208 template <typename NumericType>
209 inline const std::map<Unit::SolidAngle,
210  std::function<void(NumericType* values, const std::size_t size)>>
211  MapOfConversionsFromStandard<Unit::SolidAngle, NumericType>{
213  Conversions<Unit::SolidAngle, Unit::SolidAngle::Steradian>::FromStandard<NumericType> },
215  Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareDegree>::FromStandard<NumericType>},
217  Conversions<Unit::SolidAngle,
218  Unit::SolidAngle::SquareArcminute>::FromStandard<NumericType> },
220  Conversions<Unit::SolidAngle,
221  Unit::SolidAngle::SquareArcsecond>::FromStandard<NumericType> },
222 };
223 
224 template <typename NumericType>
225 inline const std::map<Unit::SolidAngle,
226  std::function<void(NumericType* const values, const std::size_t size)>>
227  MapOfConversionsToStandard<Unit::SolidAngle, NumericType>{
229  Conversions<Unit::SolidAngle, Unit::SolidAngle::Steradian>::ToStandard<NumericType> },
231  Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareDegree>::ToStandard<NumericType> },
233  Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareArcminute>::ToStandard<NumericType>},
235  Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareArcsecond>::ToStandard<NumericType>},
236 };
237 
238 } // namespace Internal
239 
240 } // namespace PhQ
241 
242 #endif // PHQ_UNIT_SOLID_ANGLE_HPP
SolidAngle
Solid angle units. Measures the field of view of a portion of the surface of the unit sphere viewed f...
Definition: SolidAngle.hpp:55
@ SquareArcminute
Square arcminute (arcmin^2) solid angle unit.
@ SquareArcsecond
Square arcsecond (arcsec^2) solid angle unit.
@ Steradian
Steradian (sr) solid angle unit, also known as square radian.
@ SquareDegree
Square degree (deg^2) solid angle unit.
Namespace that encompasses all of the Physical Quantities library's content.
@ 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....
Definition: Dimensions.hpp:406
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
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)