Physical Quantities  v1.0.0
C++ library of physical quantities, physical models, and units of measure for scientific computing. https://github.com/acodcha/phq
DimensionlessPlanarVector.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_DIMENSIONLESS_PLANAR_VECTOR_HPP
26 #define PHQ_DIMENSIONLESS_PLANAR_VECTOR_HPP
27 
28 #include <array>
29 #include <cstddef>
30 #include <functional>
31 #include <ostream>
32 #include <string>
33 #include <type_traits>
34 
35 #include "Base.hpp"
36 #include "Dimensions.hpp"
37 #include "PlanarVector.hpp"
38 
39 namespace PhQ {
40 
41 /// \brief Abstract base class that represents any dimensionless planar vector physical quantity.
42 /// Such a physical quantity is composed only of a value where the value is a two-dimensional planar
43 /// vector in the XY plane. Such a physical quantity has no unit of measure and no dimension set.
44 /// \tparam NumericType Floating-point numeric type: float, double, or long double. Defaults to
45 /// double if unspecified.
46 template <typename NumericType = double>
48  static_assert(std::is_floating_point<NumericType>::value,
49  "The NumericType template parameter of a physical quantity must be a numeric "
50  "floating-point type: float, double, or long double.");
51 
52 public:
53  /// \brief Physical dimension set of this physical quantity. Since this physical quantity is
54  /// dimensionless, its physical dimension set is simply the null set.
55  [[nodiscard]] static constexpr PhQ::Dimensions Dimensions() {
56  return PhQ::Dimensionless;
57  }
58 
59  /// \brief Value of this physical quantity.
60  [[nodiscard]] constexpr const PhQ::PlanarVector<NumericType>& Value() const noexcept {
61  return value;
62  }
63 
64  /// \brief Prints this physical quantity as a string.
65  [[nodiscard]] std::string Print() const {
66  return value.Print();
67  }
68 
69  /// \brief Serializes this physical quantity as a JSON message.
70  [[nodiscard]] std::string JSON() const {
71  return value.JSON();
72  }
73 
74  /// \brief Serializes this physical quantity as an XML message.
75  [[nodiscard]] std::string XML() const {
76  return value.XML();
77  }
78 
79  /// \brief Serializes this physical quantity as a YAML message.
80  [[nodiscard]] std::string YAML() const {
81  return value.YAML();
82  }
83 
84 protected:
85  /// \brief Default constructor. Constructs a dimensionless planar vector physical quantity with an
86  /// uninitialized value.
88 
89  /// \brief Constructor. Constructs a dimensionless planar vector physical quantity whose value has
90  /// the given x, y, and z Cartesian components.
91  constexpr DimensionlessPlanarVector(const NumericType x, const NumericType y) : value(x, y) {}
92 
93  /// \brief Constructor. Constructs a dimensionless planar vector physical quantity from a given
94  /// array representing its value's x and y Cartesian components.
95  explicit constexpr DimensionlessPlanarVector(const std::array<NumericType, 2>& x_y)
96  : value(x_y) {}
97 
98  /// \brief Constructor. Constructs a dimensionless planar vector physical quantity with a given
99  /// value.
101  : value(value) {}
102 
103  /// \brief Destructor. Destroys this dimensionless planar vector physical quantity.
104  ~DimensionlessPlanarVector() noexcept = default;
105 
106  /// \brief Copy constructor. Constructs a dimensionless planar vector physical quantity by copying
107  /// another one.
109  const DimensionlessPlanarVector<NumericType>& other) = default;
110 
111  /// \brief Copy constructor. Constructs a dimensionless planar vector physical quantity by copying
112  /// another one.
113  /// \tparam OtherNumericType Floating-point numeric type of the other physical quantity. Deduced
114  /// automatically.
115  template <typename OtherNumericType>
116  explicit constexpr DimensionlessPlanarVector(
117  const DimensionlessPlanarVector<OtherNumericType>& other)
118  : value(static_cast<PhQ::PlanarVector<NumericType>>(other.Value())) {}
119 
120  /// \brief Move constructor. Constructs a dimensionless planar vector physical quantity by moving
121  /// another one.
123  DimensionlessPlanarVector<NumericType>&& other) noexcept = default;
124 
125  /// \brief Copy assignment operator. Assigns this dimensionless planar vector physical quantity by
126  /// copying another one.
128  const DimensionlessPlanarVector<NumericType>& other) = default;
129 
130  /// \brief Copy assignment operator. Assigns this dimensionless planar vector physical quantity by
131  /// copying another one.
132  /// \tparam OtherNumericType Floating-point numeric type of the other physical quantity. Deduced
133  /// automatically.
134  template <typename OtherNumericType>
137  value = static_cast<PhQ::PlanarVector<NumericType>>(other.Value());
138  return *this;
139  }
140 
141  /// \brief Move assignment operator. Assigns this dimensionless planar vector physical quantity by
142  /// moving another one.
144  DimensionlessPlanarVector<NumericType>&& other) noexcept = default;
145 
146  /// \brief Value of this physical quantity.
148 };
149 
150 } // namespace PhQ
151 
152 #endif // PHQ_DIMENSIONLESS_PLANAR_VECTOR_HPP
Abstract base class that represents any dimensionless planar vector physical quantity....
static constexpr PhQ::Dimensions Dimensions()
Physical dimension set of this physical quantity. Since this physical quantity is dimensionless,...
constexpr DimensionlessPlanarVector< NumericType > & operator=(const DimensionlessPlanarVector< OtherNumericType > &other)
Copy assignment operator. Assigns this dimensionless planar vector physical quantity by copying anoth...
~DimensionlessPlanarVector() noexcept=default
Destructor. Destroys this dimensionless planar vector physical quantity.
std::string JSON() const
Serializes this physical quantity as a JSON message.
PhQ::PlanarVector< NumericType > value
Value of this physical quantity.
constexpr DimensionlessPlanarVector(const std::array< NumericType, 2 > &x_y)
Constructor. Constructs a dimensionless planar vector physical quantity from a given array representi...
constexpr DimensionlessPlanarVector< NumericType > & operator=(DimensionlessPlanarVector< NumericType > &&other) noexcept=default
Move assignment operator. Assigns this dimensionless planar vector physical quantity by moving anothe...
constexpr DimensionlessPlanarVector(const PhQ::PlanarVector< NumericType > &value)
Constructor. Constructs a dimensionless planar vector physical quantity with a given value.
constexpr const PhQ::PlanarVector< NumericType > & Value() const noexcept
Value of this physical quantity.
constexpr DimensionlessPlanarVector(const NumericType x, const NumericType y)
Constructor. Constructs a dimensionless planar vector physical quantity whose value has the given x,...
DimensionlessPlanarVector()=default
Default constructor. Constructs a dimensionless planar vector physical quantity with an uninitialized...
std::string XML() const
Serializes this physical quantity as an XML message.
constexpr DimensionlessPlanarVector(DimensionlessPlanarVector< NumericType > &&other) noexcept=default
Move constructor. Constructs a dimensionless planar vector physical quantity by moving another one.
constexpr DimensionlessPlanarVector< NumericType > & operator=(const DimensionlessPlanarVector< NumericType > &other)=default
Copy assignment operator. Assigns this dimensionless planar vector physical quantity by copying anoth...
std::string Print() const
Prints this physical quantity as a string.
std::string YAML() const
Serializes this physical quantity as a YAML message.
Physical dimension set of a unit of measure or physical quantity. Composed of the seven independent b...
Definition: Dimensions.hpp:49
Two-dimensional Euclidean vector in the XY plane. Contains two components in Cartesian coordinates: x...
Namespace that encompasses all of the Physical Quantities library's content.
constexpr Dimensions Dimensionless
Dimensionless physical dimension set. This dimension set has all base dimensions of zero....
Definition: Dimensions.hpp:406