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
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
48namespace PhQ {
49
50namespace 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.
55enum class SolidAngle : int8_t {
56 /// \brief Steradian (sr) solid angle unit, also known as square radian.
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).
72template <>
73inline constexpr const Unit::SolidAngle Standard<Unit::SolidAngle>{Unit::SolidAngle::Steradian};
74
75/// \brief Physical dimension set of solid angle units.
76template <>
77inline constexpr const Dimensions RelatedDimensions<Unit::SolidAngle>{Dimensionless};
78
79inline std::ostream& operator<<(std::ostream& stream, const Unit::SolidAngle unit) {
80 stream << Abbreviation(unit);
81 return stream;
82}
83
84namespace Internal {
85
86template <>
87inline const std::map<UnitSystem, Unit::SolidAngle> ConsistentUnits<Unit::SolidAngle>{
92};
93
94template <>
95inline const std::map<Unit::SolidAngle, UnitSystem> RelatedUnitSystems<Unit::SolidAngle>{};
96
97template <>
98inline const std::map<Unit::SolidAngle, std::string_view> Abbreviations<Unit::SolidAngle>{
103};
104
105// clang-format off
106
107template <>
108inline const std::unordered_map<std::string_view, Unit::SolidAngle> Spellings<Unit::SolidAngle>{
112 {"radian^2", Unit::SolidAngle::SquareDegree },
113 {"radian2", Unit::SolidAngle::SquareDegree },
114 {"radians^2", Unit::SolidAngle::SquareDegree },
115 {"radians2", 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 },
130 {"arcminute^2", Unit::SolidAngle::SquareArcminute},
131 {"arcminute2", Unit::SolidAngle::SquareArcminute},
132 {"arcminutes^2", Unit::SolidAngle::SquareArcminute},
133 {"arcminutes2", Unit::SolidAngle::SquareArcminute},
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
150template <>
151template <typename NumericType>
152inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::Steradian>::FromStandard(
153 NumericType& /*value*/) noexcept {}
154
155template <>
156template <typename NumericType>
157inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::Steradian>::ToStandard(
158 NumericType& /*value*/) noexcept {}
159
160template <>
161template <typename NumericType>
162inline 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
168template <>
169template <typename NumericType>
170inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareDegree>::ToStandard(
171 NumericType& value) noexcept {
172 value *= Pi<NumericType> * Pi<NumericType>
173 / (static_cast<NumericType>(180.0L) * static_cast<NumericType>(180.0L));
174}
175
176template <>
177template <typename NumericType>
178inline 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
184template <>
185template <typename NumericType>
186inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareArcminute>::ToStandard(
187 NumericType& value) noexcept {
188 value *= Pi<NumericType> * Pi<NumericType>
189 / (static_cast<NumericType>(10800.0L) * static_cast<NumericType>(10800.0L));
190}
191
192template <>
193template <typename NumericType>
194inline 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
200template <>
201template <typename NumericType>
202inline constexpr void Conversion<Unit::SolidAngle, Unit::SolidAngle::SquareArcsecond>::ToStandard(
203 NumericType& value) noexcept {
204 value *= Pi<NumericType> * Pi<NumericType>
205 / (static_cast<NumericType>(648000.0L) * static_cast<NumericType>(648000.0L));
206}
207
208template <typename NumericType>
209inline 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, Unit::SolidAngle::SquareArcminute>::FromStandard<NumericType>},
219 Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareArcsecond>::FromStandard<NumericType>},
220};
221
222template <typename NumericType>
223inline const std::map<Unit::SolidAngle,
224 std::function<void(NumericType* const values, const std::size_t size)>>
225 MapOfConversionsToStandard<Unit::SolidAngle, NumericType>{
227 Conversions<Unit::SolidAngle, Unit::SolidAngle::Steradian>::ToStandard<NumericType> },
229 Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareDegree>::ToStandard<NumericType> },
231 Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareArcminute>::ToStandard<NumericType>},
233 Conversions<Unit::SolidAngle, Unit::SolidAngle::SquareArcsecond>::ToStandard<NumericType>},
234};
235
236} // namespace Internal
237
238} // namespace PhQ
239
240#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...
@ 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.
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