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_SOLID_ANGLE_HPP
26#define PHQ_SOLID_ANGLE_HPP
27
28#include <cmath>
29#include <cstddef>
30#include <functional>
31#include <ostream>
32
33#include "DimensionalScalar.hpp"
34#include "Unit/SolidAngle.hpp"
35
36namespace PhQ {
37
38/// \brief Solid angle. Measures the field of view of a portion of the surface of the unit sphere
39/// viewed from the center of the unit sphere. Typically measured in steradians (sr), which are
40/// square radians. The unit sphere has a total solid angle of 4π steradians.
41template <typename NumericType = double>
42class SolidAngle : public DimensionalScalar<Unit::SolidAngle, NumericType> {
43public:
44 /// \brief Default constructor. Constructs a solid angle with an uninitialized value.
45 SolidAngle() = default;
46
47 /// \brief Constructor. Constructs a solid angle with a given value expressed in a given solid
48 /// angle unit.
49 SolidAngle(const NumericType value, const Unit::SolidAngle unit)
50 : DimensionalScalar<Unit::SolidAngle, NumericType>(value, unit) {}
51
52 /// \brief Destructor. Destroys this solid angle.
53 ~SolidAngle() noexcept = default;
54
55 /// \brief Copy constructor. Constructs a solid angle by copying another one.
56 constexpr SolidAngle(const SolidAngle<NumericType>& other) = default;
57
58 /// \brief Copy constructor. Constructs a solid angle by copying another one.
59 template <typename OtherNumericType>
60 explicit constexpr SolidAngle(const SolidAngle<OtherNumericType>& other)
61 : SolidAngle(static_cast<NumericType>(other.Value())) {}
62
63 /// \brief Move constructor. Constructs a solid angle by moving another one.
64 constexpr SolidAngle(SolidAngle<NumericType>&& other) noexcept = default;
65
66 /// \brief Copy assignment operator. Assigns this solid angle by copying another one.
67 constexpr SolidAngle<NumericType>& operator=(const SolidAngle<NumericType>& other) = default;
68
69 /// \brief Copy assignment operator. Assigns this solid angle by copying another one.
70 template <typename OtherNumericType>
72 this->value = static_cast<NumericType>(other.Value());
73 return *this;
74 }
75
76 /// \brief Move assignment operator. Assigns this solid angle by moving another one.
77 constexpr SolidAngle<NumericType>& operator=(SolidAngle<NumericType>&& other) noexcept = default;
78
79 /// \brief Statically creates a solid angle of zero.
80 [[nodiscard]] static constexpr SolidAngle<NumericType> Zero() {
81 return SolidAngle<NumericType>{static_cast<NumericType>(0)};
82 }
83
84 /// \brief Statically creates a solid angle with a given value expressed in a given solid angle
85 /// unit.
86 template <Unit::SolidAngle Unit>
87 [[nodiscard]] static constexpr SolidAngle<NumericType> Create(const NumericType value) {
89 ConvertStatically<Unit::SolidAngle, Unit, Standard<Unit::SolidAngle>>(value)};
90 }
91
93 return SolidAngle<NumericType>{this->value + other.value};
94 }
95
97 return SolidAngle<NumericType>{this->value - other.value};
98 }
99
100 constexpr SolidAngle<NumericType> operator*(const NumericType number) const {
101 return SolidAngle<NumericType>{this->value * number};
102 }
103
104 constexpr SolidAngle<NumericType> operator/(const NumericType number) const {
105 return SolidAngle<NumericType>{this->value / number};
106 }
107
108 constexpr NumericType operator/(const SolidAngle<NumericType>& other) const noexcept {
109 return this->value / other.value;
110 }
111
112 constexpr void operator+=(const SolidAngle<NumericType>& other) noexcept {
113 this->value += other.value;
114 }
115
116 constexpr void operator-=(const SolidAngle<NumericType>& other) noexcept {
117 this->value -= other.value;
118 }
119
120 constexpr void operator*=(const NumericType number) noexcept {
121 this->value *= number;
122 }
123
124 constexpr void operator/=(const NumericType number) noexcept {
125 this->value /= number;
126 }
127
128private:
129 /// \brief Constructor. Constructs a solid angle with a given value expressed in the standard
130 /// solid angle unit.
131 explicit constexpr SolidAngle(const NumericType value)
132 : DimensionalScalar<Unit::SolidAngle, NumericType>(value) {}
133};
134
135template <typename NumericType>
136inline constexpr bool operator==(
137 const SolidAngle<NumericType>& left, const SolidAngle<NumericType>& right) noexcept {
138 return left.Value() == right.Value();
139}
140
141template <typename NumericType>
142inline constexpr bool operator!=(
143 const SolidAngle<NumericType>& left, const SolidAngle<NumericType>& right) noexcept {
144 return left.Value() != right.Value();
145}
146
147template <typename NumericType>
148inline constexpr bool operator<(
149 const SolidAngle<NumericType>& left, const SolidAngle<NumericType>& right) noexcept {
150 return left.Value() < right.Value();
151}
152
153template <typename NumericType>
154inline constexpr bool operator>(
155 const SolidAngle<NumericType>& left, const SolidAngle<NumericType>& right) noexcept {
156 return left.Value() > right.Value();
157}
158
159template <typename NumericType>
160inline constexpr bool operator<=(
161 const SolidAngle<NumericType>& left, const SolidAngle<NumericType>& right) noexcept {
162 return left.Value() <= right.Value();
163}
164
165template <typename NumericType>
166inline constexpr bool operator>=(
167 const SolidAngle<NumericType>& left, const SolidAngle<NumericType>& right) noexcept {
168 return left.Value() >= right.Value();
169}
170
171template <typename NumericType>
172inline std::ostream& operator<<(std::ostream& stream, const SolidAngle<NumericType>& solid_angle) {
173 stream << solid_angle.Print();
174 return stream;
175}
176
177template <typename NumericType>
179 const NumericType number, const SolidAngle<NumericType>& solid_angle) {
180 return solid_angle * number;
181}
182
183} // namespace PhQ
184
185namespace std {
186
187template <typename NumericType>
188struct hash<PhQ::SolidAngle<NumericType>> {
189 inline size_t operator()(const PhQ::SolidAngle<NumericType>& solid_angle) const {
190 return hash<NumericType>()(solid_angle.Value());
191 }
192};
193
194} // namespace std
195
196#endif // PHQ_SOLID_ANGLE_HPP
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
NumericType value
Value of this physical quantity expressed in its standard unit of measure.
constexpr NumericType Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr UnitType Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
Solid angle. Measures the field of view of a portion of the surface of the unit sphere viewed from th...
constexpr SolidAngle< NumericType > operator-(const SolidAngle< NumericType > &other) const
constexpr void operator/=(const NumericType number) noexcept
constexpr SolidAngle< NumericType > operator*(const NumericType number) const
constexpr void operator-=(const SolidAngle< NumericType > &other) noexcept
SolidAngle(const NumericType value, const Unit::SolidAngle unit)
Constructor. Constructs a solid angle with a given value expressed in a given solid angle unit.
constexpr SolidAngle< NumericType > & operator=(SolidAngle< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this solid angle by moving another one.
constexpr SolidAngle< NumericType > & operator=(const SolidAngle< NumericType > &other)=default
Copy assignment operator. Assigns this solid angle by copying another one.
constexpr SolidAngle(SolidAngle< NumericType > &&other) noexcept=default
Move constructor. Constructs a solid angle by moving another one.
constexpr void operator+=(const SolidAngle< NumericType > &other) noexcept
~SolidAngle() noexcept=default
Destructor. Destroys this solid angle.
constexpr SolidAngle< NumericType > operator+(const SolidAngle< NumericType > &other) const
SolidAngle()=default
Default constructor. Constructs a solid angle with an uninitialized value.
constexpr SolidAngle< NumericType > & operator=(const SolidAngle< OtherNumericType > &other)
Copy assignment operator. Assigns this solid angle by copying another one.
static constexpr SolidAngle< NumericType > Zero()
Statically creates a solid angle of zero.
constexpr NumericType operator/(const SolidAngle< NumericType > &other) const noexcept
constexpr void operator*=(const NumericType number) noexcept
constexpr SolidAngle(const NumericType value)
Constructor. Constructs a solid angle with a given value expressed in the standard solid angle unit.
constexpr SolidAngle< NumericType > operator/(const NumericType number) const
static constexpr SolidAngle< NumericType > Create(const NumericType value)
Statically creates a solid angle with a given value expressed in a given solid angle unit.
SolidAngle
Solid angle units. Measures the field of view of a portion of the surface of the unit sphere viewed f...
Namespace that encompasses all of the Physical Quantities library's content.
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
constexpr bool operator<(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator<=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr Acceleration< NumericType > operator*(const NumericType number, const Acceleration< NumericType > &acceleration)
constexpr bool operator==(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator>=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept