Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
VectorArea.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_VECTOR_AREA_HPP
26 #define PHQ_VECTOR_AREA_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 
33 #include "Angle.hpp"
34 #include "Area.hpp"
35 #include "DimensionalVector.hpp"
36 #include "Direction.hpp"
37 #include "Unit/Area.hpp"
38 #include "Vector.hpp"
39 
40 namespace PhQ {
41 
42 /// \brief Three-dimensional Euclidean vector area. Contains three components in Cartesian
43 /// coordinates: x, y, and z. A vector area is an oriented area; it is the three-dimensional
44 /// Euclidean vector representation of an area. Any closed surface has a vector area: it is the
45 /// surface integral of its surface normal direction. For the scalar components of a vector area or
46 /// for the magnitude of a vector area, see PhQ::Area.
47 template <typename NumericType = double>
48 class VectorArea : public DimensionalVector<Unit::Area, NumericType> {
49 public:
50  /// \brief Default constructor. Constructs a vector area with an uninitialized value.
51  VectorArea() = default;
52 
53  /// \brief Constructor. Constructs a vector area with a given value expressed in a given area
54  /// unit.
56  : DimensionalVector<Unit::Area, NumericType>(value, unit) {}
57 
58  /// \brief Constructor. Constructs a vector area from a given set of area components.
60  : VectorArea<NumericType>({x.Value(), y.Value(), z.Value()}) {}
61 
62  /// \brief Constructor. Constructs a vector area from a given area and direction.
63  constexpr VectorArea(const Area<NumericType>& area, const Direction<NumericType>& direction)
64  : VectorArea<NumericType>(area.Value() * direction.Value()) {}
65 
66  /// \brief Destructor. Destroys this vector area.
67  ~VectorArea() noexcept = default;
68 
69  /// \brief Copy constructor. Constructs a vector area by copying another one.
70  constexpr VectorArea(const VectorArea<NumericType>& other) = default;
71 
72  /// \brief Copy constructor. Constructs a vector area by copying another one.
73  template <typename OtherNumericType>
74  explicit constexpr VectorArea(const VectorArea<OtherNumericType>& other)
75  : VectorArea(static_cast<Vector<NumericType>>(other.Value())) {}
76 
77  /// \brief Move constructor. Constructs a vector area by moving another one.
78  constexpr VectorArea(VectorArea<NumericType>&& other) noexcept = default;
79 
80  /// \brief Copy assignment operator. Assigns this vector area by copying another one.
81  constexpr VectorArea<NumericType>& operator=(const VectorArea<NumericType>& other) = default;
82 
83  /// \brief Copy assignment operator. Assigns this vector area by copying another one.
84  template <typename OtherNumericType>
86  this->value = static_cast<Vector<NumericType>>(other.Value());
87  return *this;
88  }
89 
90  /// \brief Move assignment operator. Assigns this vector area by moving another one.
91  constexpr VectorArea<NumericType>& operator=(VectorArea<NumericType>&& other) noexcept = default;
92 
93  /// \brief Statically creates a vector area of zero.
94  [[nodiscard]] static constexpr VectorArea<NumericType> Zero() {
96  }
97 
98  /// \brief Statically creates a vector area from the given x, y, and z Cartesian components
99  /// expressed in a given area unit.
100  template <Unit::Area Unit>
101  [[nodiscard]] static constexpr VectorArea<NumericType> Create(
102  const NumericType x, const NumericType y, const NumericType z) {
104  ConvertStatically<Unit::Area, Unit, Standard<Unit::Area>>(Vector<NumericType>{x, y, z})};
105  }
106 
107  /// \brief Statically creates a vector area from the given x, y, and z Cartesian components
108  /// expressed in a given area unit.
109  template <Unit::Area Unit>
110  [[nodiscard]] static constexpr VectorArea<NumericType> Create(
111  const std::array<NumericType, 3>& x_y_z) {
113  ConvertStatically<Unit::Area, Unit, Standard<Unit::Area>>(Vector<NumericType>{x_y_z})};
114  }
115 
116  /// \brief Statically creates a vector area with a given value expressed in a given area unit.
117  template <Unit::Area Unit>
118  [[nodiscard]] static constexpr VectorArea<NumericType> Create(const Vector<NumericType>& value) {
120  ConvertStatically<Unit::Area, Unit, Standard<Unit::Area>>(value)};
121  }
122 
123  /// \brief Returns the x Cartesian component of this vector area.
124  [[nodiscard]] constexpr Area<NumericType> x() const noexcept {
125  return Area<NumericType>{this->value.x()};
126  }
127 
128  /// \brief Returns the y Cartesian component of this vector area.
129  [[nodiscard]] constexpr Area<NumericType> y() const noexcept {
130  return Area<NumericType>{this->value.y()};
131  }
132 
133  /// \brief Returns the z Cartesian component of this vector area.
134  [[nodiscard]] constexpr Area<NumericType> z() const noexcept {
135  return Area<NumericType>{this->value.z()};
136  }
137 
138  /// \brief Returns the magnitude of this vector area.
139  [[nodiscard]] Area<NumericType> Magnitude() const {
140  return Area<NumericType>{this->value.Magnitude()};
141  }
142 
143  /// \brief Returns the direction of this vector area.
144  [[nodiscard]] PhQ::Direction<NumericType> Direction() const {
145  return this->value.Direction();
146  }
147 
148  /// \brief Returns the angle between this vector area and another one.
149  [[nodiscard]] PhQ::Angle<NumericType> Angle(const VectorArea<NumericType>& vector_area) const {
150  return PhQ::Angle<NumericType>{*this, vector_area};
151  }
152 
153  constexpr VectorArea<NumericType> operator+(const VectorArea<NumericType>& vector_area) const {
154  return VectorArea<NumericType>{this->value + vector_area.value};
155  }
156 
157  constexpr VectorArea<NumericType> operator-(const VectorArea<NumericType>& vector_area) const {
158  return VectorArea<NumericType>{this->value - vector_area.value};
159  }
160 
161  constexpr VectorArea<NumericType> operator*(const NumericType number) const {
162  return VectorArea<NumericType>{this->value * number};
163  }
164 
165  constexpr VectorArea<NumericType> operator/(const NumericType number) const {
166  return VectorArea<NumericType>{this->value / number};
167  }
168 
169  constexpr void operator+=(const VectorArea<NumericType>& vector_area) noexcept {
170  this->value += vector_area.value;
171  }
172 
173  constexpr void operator-=(const VectorArea<NumericType>& vector_area) noexcept {
174  this->value -= vector_area.value;
175  }
176 
177  constexpr void operator*=(const NumericType number) noexcept {
178  this->value *= number;
179  }
180 
181  constexpr void operator/=(const NumericType number) noexcept {
182  this->value /= number;
183  }
184 
185 private:
186  /// \brief Constructor. Constructs a vector area with a given value expressed in the standard area
187  /// unit.
188  explicit constexpr VectorArea(const Vector<NumericType>& value)
189  : DimensionalVector<Unit::Area, NumericType>(value) {}
190 };
191 
192 template <typename NumericType>
193 inline constexpr bool operator==(
194  const VectorArea<NumericType>& left, const VectorArea<NumericType>& right) noexcept {
195  return left.Value() == right.Value();
196 }
197 
198 template <typename NumericType>
199 inline constexpr bool operator!=(
200  const VectorArea<NumericType>& left, const VectorArea<NumericType>& right) noexcept {
201  return left.Value() != right.Value();
202 }
203 
204 template <typename NumericType>
205 inline constexpr bool operator<(
206  const VectorArea<NumericType>& left, const VectorArea<NumericType>& right) noexcept {
207  return left.Value() < right.Value();
208 }
209 
210 template <typename NumericType>
211 inline constexpr bool operator>(
212  const VectorArea<NumericType>& left, const VectorArea<NumericType>& right) noexcept {
213  return left.Value() > right.Value();
214 }
215 
216 template <typename NumericType>
217 inline constexpr bool operator<=(
218  const VectorArea<NumericType>& left, const VectorArea<NumericType>& right) noexcept {
219  return left.Value() <= right.Value();
220 }
221 
222 template <typename NumericType>
223 inline constexpr bool operator>=(
224  const VectorArea<NumericType>& left, const VectorArea<NumericType>& right) noexcept {
225  return left.Value() >= right.Value();
226 }
227 
228 template <typename NumericType>
229 inline std::ostream& operator<<(std::ostream& stream, const VectorArea<NumericType>& vector_area) {
230  stream << vector_area.Print();
231  return stream;
232 }
233 
234 template <typename NumericType>
236  const NumericType number, const VectorArea<NumericType>& vector_area) {
237  return vector_area * number;
238 }
239 
240 template <typename NumericType>
242  : Direction<NumericType>(vector_area.Value()) {}
243 
244 template <typename NumericType>
246  const VectorArea<NumericType>& vector_area_1, const VectorArea<NumericType>& vector_area_2)
247  : Angle<NumericType>(vector_area_1.Value(), vector_area_2.Value()) {}
248 
249 template <typename NumericType>
251  const Area<NumericType>& area) const {
252  return VectorArea<NumericType>{area, *this};
253 }
254 
255 template <typename NumericType>
257  const Direction<NumericType>& direction) const {
258  return VectorArea<NumericType>{*this, direction};
259 }
260 
261 } // namespace PhQ
262 
263 namespace std {
264 
265 template <typename NumericType>
266 struct hash<PhQ::VectorArea<NumericType>> {
267  inline size_t operator()(const PhQ::VectorArea<NumericType>& vector_area) const {
268  return hash<PhQ::Vector<NumericType>>()(vector_area.Value());
269  }
270 };
271 
272 } // namespace std
273 
274 #endif // PHQ_VECTOR_AREA_HPP
Plane angle between two lines or dihedral angle between two planes.
Definition: Angle.hpp:130
Angle()=default
Default constructor. Constructs an angle with an uninitialized value.
Surface area or cross-sectional area. Can also represent a scalar component of a vector area or the m...
Definition: Area.hpp:71
constexpr Area< NumericType > operator*(const NumericType number) const
Definition: Area.hpp:143
Abstract base class that represents any dimensional vector physical quantity. Such a physical quantit...
std::string Print() const
Prints this physical quantity as a string. This physical quantity's value is expressed in its standar...
static constexpr Unit::Area Unit()
Standard unit of measure for this physical quantity. This physical quantity's value is stored interna...
PhQ::Vector< double > value
Value of this physical quantity expressed in its standard unit of measure.
constexpr const PhQ::Vector< double > & Value() const noexcept
Value of this physical quantity expressed in its standard unit of measure.
Three-dimensional Euclidean direction vector. Contains three components in Cartesian coordinates: x,...
Definition: Direction.hpp:115
constexpr Direction()
Default constructor. Initializes a direction to the zero vector.
Definition: Direction.hpp:118
constexpr Acceleration< NumericType > operator*(const ScalarAcceleration< NumericType > &scalar_acceleration) const
Three-dimensional Euclidean vector area. Contains three components in Cartesian coordinates: x,...
Definition: VectorArea.hpp:48
constexpr void operator+=(const VectorArea< NumericType > &vector_area) noexcept
Definition: VectorArea.hpp:169
constexpr VectorArea< NumericType > & operator=(const VectorArea< NumericType > &other)=default
Copy assignment operator. Assigns this vector area by copying another one.
constexpr VectorArea< NumericType > operator-(const VectorArea< NumericType > &vector_area) const
Definition: VectorArea.hpp:157
static constexpr VectorArea< NumericType > Create(const NumericType x, const NumericType y, const NumericType z)
Statically creates a vector area from the given x, y, and z Cartesian components expressed in a given...
Definition: VectorArea.hpp:101
VectorArea(const Vector< NumericType > &value, const Unit::Area unit)
Constructor. Constructs a vector area with a given value expressed in a given area unit.
Definition: VectorArea.hpp:55
constexpr void operator/=(const NumericType number) noexcept
Definition: VectorArea.hpp:181
static constexpr VectorArea< NumericType > Create(const std::array< NumericType, 3 > &x_y_z)
Statically creates a vector area from the given x, y, and z Cartesian components expressed in a given...
Definition: VectorArea.hpp:110
constexpr Area< NumericType > z() const noexcept
Returns the z Cartesian component of this vector area.
Definition: VectorArea.hpp:134
~VectorArea() noexcept=default
Destructor. Destroys this vector area.
constexpr VectorArea(const Vector< NumericType > &value)
Constructor. Constructs a vector area with a given value expressed in the standard area unit.
Definition: VectorArea.hpp:188
VectorArea()=default
Default constructor. Constructs a vector area with an uninitialized value.
static constexpr VectorArea< NumericType > Zero()
Statically creates a vector area of zero.
Definition: VectorArea.hpp:94
constexpr Area< NumericType > x() const noexcept
Returns the x Cartesian component of this vector area.
Definition: VectorArea.hpp:124
VectorArea(const Area< NumericType > &x, const Area< NumericType > &y, const Area< NumericType > &z)
Constructor. Constructs a vector area from a given set of area components.
Definition: VectorArea.hpp:59
constexpr VectorArea< NumericType > operator+(const VectorArea< NumericType > &vector_area) const
Definition: VectorArea.hpp:153
PhQ::Angle< NumericType > Angle(const VectorArea< NumericType > &vector_area) const
Returns the angle between this vector area and another one.
Definition: VectorArea.hpp:149
constexpr VectorArea< NumericType > & operator=(VectorArea< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this vector area by moving another one.
static constexpr VectorArea< NumericType > Create(const Vector< NumericType > &value)
Statically creates a vector area with a given value expressed in a given area unit.
Definition: VectorArea.hpp:118
constexpr VectorArea(VectorArea< NumericType > &&other) noexcept=default
Move constructor. Constructs a vector area by moving another one.
Area< NumericType > Magnitude() const
Returns the magnitude of this vector area.
Definition: VectorArea.hpp:139
constexpr VectorArea(const Area< NumericType > &area, const Direction< NumericType > &direction)
Constructor. Constructs a vector area from a given area and direction.
Definition: VectorArea.hpp:63
constexpr Area< NumericType > y() const noexcept
Returns the y Cartesian component of this vector area.
Definition: VectorArea.hpp:129
constexpr VectorArea< NumericType > operator*(const NumericType number) const
Definition: VectorArea.hpp:161
constexpr void operator-=(const VectorArea< NumericType > &vector_area) noexcept
Definition: VectorArea.hpp:173
constexpr void operator*=(const NumericType number) noexcept
Definition: VectorArea.hpp:177
constexpr VectorArea< NumericType > operator/(const NumericType number) const
Definition: VectorArea.hpp:165
constexpr VectorArea< NumericType > & operator=(const VectorArea< OtherNumericType > &other)
Copy assignment operator. Assigns this vector area by copying another one.
Definition: VectorArea.hpp:85
PhQ::Direction< NumericType > Direction() const
Returns the direction of this vector area.
Definition: VectorArea.hpp:144
Three-dimensional Euclidean vector. Contains three components in Cartesian coordinates: x,...
Definition: Vector.hpp:60
NumericType Magnitude() const noexcept
Returns the magnitude (also known as the L2 norm) of this three-dimensional vector.
Definition: Vector.hpp:209
static constexpr Vector< NumericType > Zero()
Statically creates a three-dimensional vector with its x, y, and z Cartesian components initialized t...
Definition: Vector.hpp:126
constexpr NumericType x() const noexcept
Returns this three-dimensional vector's x Cartesian component.
Definition: Vector.hpp:139
PhQ::Direction< NumericType > Direction() const
Returns the direction of this three-dimensional vector.
Definition: Direction.hpp:377
constexpr NumericType y() const noexcept
Returns this three-dimensional vector's y Cartesian component.
Definition: Vector.hpp:144
constexpr NumericType z() const noexcept
Returns this three-dimensional vector's z Cartesian component.
Definition: Vector.hpp:149
Area
Area units.
Definition: Area.hpp:53
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 bool operator!=(const Acceleration< NumericType > &left, const Acceleration< NumericType > &right) noexcept
std::ostream & operator<<(std::ostream &stream, const Acceleration< NumericType > &acceleration)