Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
ScalarAngularAcceleration.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_SCALAR_ANGULAR_ACCELERATION_HPP
26 #define PHQ_SCALAR_ANGULAR_ACCELERATION_HPP
27 
28 #include <cstddef>
29 #include <functional>
30 #include <ostream>
31 
32 #include "AngularSpeed.hpp"
33 #include "DimensionalScalar.hpp"
34 #include "Frequency.hpp"
35 #include "Time.hpp"
37 
38 namespace PhQ {
39 
40 /// @brief Scalar angular acceleration. Represents the time rate of change of an angular speed; see
41 /// also PhQ::AngularSpeed, PhQ::Time, and PhQ::Frequency. Can also represent a component or the
42 /// magnitude of an angular acceleration pseudovector.
43 template <typename NumericType = double>
44 class ScalarAngularAcceleration : public DimensionalScalar<Unit::AngularAcceleration, NumericType> {
45 public:
46  /// \brief Default constructor. Constructs a scalar angular acceleration with an uninitialized
47  /// value.
49 
50  /// \brief Constructor. Constructs a scalar angular acceleration with a given value expressed in a
51  /// given angular acceleration unit.
53  : DimensionalScalar<Unit::AngularAcceleration, NumericType>(value, unit) {}
54 
55  /// \brief Constructor. Constructs a scalar angular acceleration from a given angular speed and
56  /// time using the definition of angular acceleration.
58  const AngularSpeed<NumericType>& angular_speed, const Time<NumericType>& time)
59  : ScalarAngularAcceleration<NumericType>(angular_speed.Value() / time.Value()) {}
60 
61  /// \brief Constructor. Constructs a scalar angular acceleration from a given angular speed and
62  /// frequency using the definition of angular acceleration.
64  const AngularSpeed<NumericType>& angular_speed, const Frequency<NumericType>& frequency)
65  : ScalarAngularAcceleration<NumericType>(angular_speed.Value() * frequency.Value()) {}
66 
67  /// \brief Destructor. Destroys this scalar angular acceleration.
68  ~ScalarAngularAcceleration() noexcept = default;
69 
70  /// \brief Copy constructor. Constructs a scalar angular acceleration by copying another one.
72  const ScalarAngularAcceleration<NumericType>& other) = default;
73 
74  /// \brief Copy constructor. Constructs a scalar angular acceleration by copying another one.
75  template <typename OtherNumericType>
76  explicit constexpr ScalarAngularAcceleration(
77  const ScalarAngularAcceleration<OtherNumericType>& other)
78  : ScalarAngularAcceleration(static_cast<NumericType>(other.Value())) {}
79 
80  /// \brief Move constructor. Constructs a scalar angular acceleration by moving another one.
82  ScalarAngularAcceleration<NumericType>&& other) noexcept = default;
83 
84  /// \brief Copy assignment operator. Assigns this scalar angular acceleration by copying another
85  /// one.
87  const ScalarAngularAcceleration<NumericType>& other) = default;
88 
89  /// \brief Copy assignment operator. Assigns this scalar angular acceleration by copying another
90  /// one.
91  template <typename OtherNumericType>
94  this->value = static_cast<NumericType>(other.Value());
95  return *this;
96  }
97 
98  /// \brief Move assignment operator. Assigns this scalar angular acceleration by moving another
99  /// one.
101  ScalarAngularAcceleration<NumericType>&& other) noexcept = default;
102 
103  /// \brief Statically creates a scalar angular acceleration of zero.
104  [[nodiscard]] static constexpr ScalarAngularAcceleration<NumericType> Zero() {
105  return ScalarAngularAcceleration<NumericType>{static_cast<NumericType>(0)};
106  }
107 
108  /// \brief Statically creates a scalar angular acceleration with a given value expressed in a
109  /// given angular acceleration unit.
110  template <Unit::AngularAcceleration Unit>
111  [[nodiscard]] static constexpr ScalarAngularAcceleration<NumericType> Create(
112  const NumericType value) {
114  ConvertStatically<Unit::AngularAcceleration, Unit, Standard<Unit::AngularAcceleration>>(
115  value)};
116  }
117 
119  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const {
120  return ScalarAngularAcceleration<NumericType>{this->value + scalar_angular_acceleration.value};
121  }
122 
124  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const {
125  return ScalarAngularAcceleration<NumericType>{this->value - scalar_angular_acceleration.value};
126  }
127 
128  constexpr ScalarAngularAcceleration<NumericType> operator*(const NumericType number) const {
129  return ScalarAngularAcceleration<NumericType>{this->value * number};
130  }
131 
133  return AngularSpeed<NumericType>{*this, time};
134  }
135 
136  constexpr ScalarAngularAcceleration<NumericType> operator/(const NumericType number) const {
137  return ScalarAngularAcceleration<NumericType>{this->value / number};
138  }
139 
140  constexpr AngularSpeed<NumericType> operator/(const Frequency<NumericType>& frequency) const {
141  return AngularSpeed<NumericType>{*this, frequency};
142  }
143 
144  constexpr Frequency<NumericType> operator/(const AngularSpeed<NumericType>& angular_speed) const {
145  return Frequency<NumericType>{*this, angular_speed};
146  }
147 
148  constexpr NumericType operator/(
149  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const noexcept {
150  return this->value / scalar_angular_acceleration.value;
151  }
152 
153  constexpr void operator+=(
154  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) noexcept {
155  this->value += scalar_angular_acceleration.value;
156  }
157 
158  constexpr void operator-=(
159  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) noexcept {
160  this->value -= scalar_angular_acceleration.value;
161  }
162 
163  constexpr void operator*=(const NumericType number) noexcept {
164  this->value *= number;
165  }
166 
167  constexpr void operator/=(const NumericType number) noexcept {
168  this->value /= number;
169  }
170 
171 private:
172  /// \brief Constructor. Constructs a scalar angular acceleration with a given value expressed in
173  /// the standard angular acceleration unit.
174  explicit constexpr ScalarAngularAcceleration(const NumericType value)
175  : DimensionalScalar<Unit::AngularAcceleration, NumericType>(value) {}
176 };
177 
178 template <typename NumericType>
179 inline constexpr bool operator==(const ScalarAngularAcceleration<NumericType>& left,
180  const ScalarAngularAcceleration<NumericType>& right) noexcept {
181  return left.Value() == right.Value();
182 }
183 
184 template <typename NumericType>
185 inline constexpr bool operator!=(const ScalarAngularAcceleration<NumericType>& left,
186  const ScalarAngularAcceleration<NumericType>& right) noexcept {
187  return left.Value() != right.Value();
188 }
189 
190 template <typename NumericType>
191 inline constexpr bool operator<(const ScalarAngularAcceleration<NumericType>& left,
192  const ScalarAngularAcceleration<NumericType>& right) noexcept {
193  return left.Value() < right.Value();
194 }
195 
196 template <typename NumericType>
197 inline constexpr bool operator>(const ScalarAngularAcceleration<NumericType>& left,
198  const ScalarAngularAcceleration<NumericType>& right) noexcept {
199  return left.Value() > right.Value();
200 }
201 
202 template <typename NumericType>
203 inline constexpr bool operator<=(const ScalarAngularAcceleration<NumericType>& left,
204  const ScalarAngularAcceleration<NumericType>& right) noexcept {
205  return left.Value() <= right.Value();
206 }
207 
208 template <typename NumericType>
209 inline constexpr bool operator>=(const ScalarAngularAcceleration<NumericType>& left,
210  const ScalarAngularAcceleration<NumericType>& right) noexcept {
211  return left.Value() >= right.Value();
212 }
213 
214 template <typename NumericType>
215 inline std::ostream& operator<<(
216  std::ostream& stream,
217  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) {
218  stream << scalar_angular_acceleration.Print();
219  return stream;
220 }
221 
222 template <typename NumericType>
224  const NumericType number,
225  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) {
226  return scalar_angular_acceleration * number;
227 }
228 
229 template <typename NumericType>
230 inline constexpr Time<NumericType>::Time(
231  const AngularSpeed<NumericType>& angular_speed,
232  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration)
233  : Time<NumericType>(angular_speed.Value() / scalar_angular_acceleration.Value()) {}
234 
235 template <typename NumericType>
236 inline constexpr Frequency<NumericType>::Frequency(
237  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration,
238  const AngularSpeed<NumericType>& angular_speed)
239  : Frequency<NumericType>(scalar_angular_acceleration.Value() / angular_speed.Value()) {}
240 
241 template <typename NumericType>
243  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration,
244  const Time<NumericType>& time)
245  : AngularSpeed<NumericType>(scalar_angular_acceleration.Value() * time.Value()) {}
246 
247 template <typename NumericType>
249  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration,
250  const Frequency<NumericType>& frequency)
251  : AngularSpeed<NumericType>(scalar_angular_acceleration.Value() / frequency.Value()) {}
252 
253 template <typename NumericType>
254 inline constexpr AngularSpeed<NumericType> Time<NumericType>::operator*(
255  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const {
256  return AngularSpeed<NumericType>(scalar_angular_acceleration, *this);
257 }
258 
259 template <typename NumericType>
260 inline constexpr ScalarAngularAcceleration<NumericType> Frequency<NumericType>::operator*(
261  const AngularSpeed<NumericType>& angular_speed) const {
262  return ScalarAngularAcceleration<NumericType>{angular_speed, *this};
263 }
264 
265 template <typename NumericType>
266 inline constexpr ScalarAngularAcceleration<NumericType> AngularSpeed<NumericType>::operator*(
267  const Frequency<NumericType>& frequency) const {
268  return ScalarAngularAcceleration<NumericType>{*this, frequency};
269 }
270 
271 template <typename NumericType>
272 inline constexpr ScalarAngularAcceleration<NumericType> AngularSpeed<NumericType>::operator/(
273  const Time<NumericType>& time) const {
274  return ScalarAngularAcceleration<NumericType>{*this, time};
275 }
276 
277 template <typename NumericType>
278 inline constexpr Time<NumericType> AngularSpeed<NumericType>::operator/(
279  const ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const {
280  return Time<NumericType>{*this, scalar_angular_acceleration};
281 }
282 
283 } // namespace PhQ
284 
285 namespace std {
286 
287 template <typename NumericType>
288 struct hash<PhQ::ScalarAngularAcceleration<NumericType>> {
289  inline size_t operator()(
290  const PhQ::ScalarAngularAcceleration<NumericType>& scalar_angular_acceleration) const {
291  return hash<NumericType>()(scalar_angular_acceleration.Value());
292  }
293 };
294 
295 } // namespace std
296 
297 #endif // PHQ_SCALAR_ANGULAR_ACCELERATION_HPP
Angular speed, also known as angular rate or angular frequency. Represents the time rate of change of...
Abstract base class that represents any dimensional scalar physical quantity. Such a physical quantit...
double value
Value of this physical quantity expressed in its standard unit of measure.
constexpr double Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
static constexpr Unit::AngularAcceleration 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...
Frequency. Inverse of a time duration. See also PhQ::Time.
Definition: Frequency.hpp:40
Scalar angular acceleration. Represents the time rate of change of an angular speed; see also PhQ::An...
ScalarAngularAcceleration(const NumericType value, const Unit::AngularAcceleration unit)
Constructor. Constructs a scalar angular acceleration with a given value expressed in a given angular...
constexpr NumericType operator/(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration) const noexcept
constexpr ScalarAngularAcceleration< NumericType > & operator=(ScalarAngularAcceleration< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this scalar angular acceleration by moving another one.
constexpr ScalarAngularAcceleration< NumericType > operator-(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration) const
static constexpr ScalarAngularAcceleration< NumericType > Zero()
Statically creates a scalar angular acceleration of zero.
constexpr void operator/=(const NumericType number) noexcept
constexpr ScalarAngularAcceleration< NumericType > & operator=(const ScalarAngularAcceleration< NumericType > &other)=default
Copy assignment operator. Assigns this scalar angular acceleration by copying another one.
constexpr AngularSpeed< NumericType > operator*(const Time< NumericType > &time) const
constexpr ScalarAngularAcceleration(ScalarAngularAcceleration< NumericType > &&other) noexcept=default
Move constructor. Constructs a scalar angular acceleration by moving another one.
constexpr ScalarAngularAcceleration(const AngularSpeed< NumericType > &angular_speed, const Frequency< NumericType > &frequency)
Constructor. Constructs a scalar angular acceleration from a given angular speed and frequency using ...
constexpr ScalarAngularAcceleration< NumericType > & operator=(const ScalarAngularAcceleration< OtherNumericType > &other)
Copy assignment operator. Assigns this scalar angular acceleration by copying another one.
constexpr ScalarAngularAcceleration< NumericType > operator+(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration) const
constexpr Frequency< NumericType > operator/(const AngularSpeed< NumericType > &angular_speed) const
constexpr ScalarAngularAcceleration< NumericType > operator*(const NumericType number) const
constexpr void operator+=(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration) noexcept
constexpr void operator*=(const NumericType number) noexcept
~ScalarAngularAcceleration() noexcept=default
Destructor. Destroys this scalar angular acceleration.
constexpr ScalarAngularAcceleration< NumericType > operator/(const NumericType number) const
constexpr ScalarAngularAcceleration(const AngularSpeed< NumericType > &angular_speed, const Time< NumericType > &time)
Constructor. Constructs a scalar angular acceleration from a given angular speed and time using the d...
ScalarAngularAcceleration()=default
Default constructor. Constructs a scalar angular acceleration with an uninitialized value.
static constexpr ScalarAngularAcceleration< NumericType > Create(const NumericType value)
Statically creates a scalar angular acceleration with a given value expressed in a given angular acce...
constexpr AngularSpeed< NumericType > operator/(const Frequency< NumericType > &frequency) const
constexpr void operator-=(const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration) noexcept
constexpr ScalarAngularAcceleration(const NumericType value)
Constructor. Constructs a scalar angular acceleration with a given value expressed in the standard an...
Time. Can represent either a point in time, a time duration, or a period. For the inverse of time,...
Definition: Time.hpp:172
Time()=default
Default constructor. Constructs a time quantity with an uninitialized value.
Frequency
Frequency units.
Definition: Frequency.hpp:53
AngularAcceleration
Angular acceleration units.
Time
Time units.
Definition: Time.hpp:53
AngularSpeed
Angular speed units.
Namespace that encompasses all of the Physical Quantities library's content.
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
constexpr Dyad< NumericType > operator/(const Dyad< NumericType > &dyad, const OtherNumericType number)
Definition: Dyad.hpp:696
constexpr bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)
constexpr ScalarAngularAcceleration< NumericType > operator*(const NumericType number, const ScalarAngularAcceleration< NumericType > &scalar_angular_acceleration)