scifir-units 2.0.0
scifir-units is a library of units of measurement, angles, coordinates, fields, and related data, all lightweight, that help in the development of scientific software and scientific machines
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Functions
vector_unit_nd.hpp File Reference
#include "./scalar_unit.hpp"
#include "../meca_number/angle.hpp"
#include "../util/is_number.hpp"
#include "../coordinates/direction.hpp"
#include "boost/algorithm/string.hpp"
#include <cmath>
#include <functional>
#include <iostream>
#include <list>
#include <sstream>
#include <string>
#include <vector>
Include dependency graph for vector_unit_nd.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  scifir::vector_unit_nd
 Class that creates a vector in ND, which means a variable number of dimensions. A vector_unit_nd can change to be in 1D, in 2D or in 3D, but it cannot be in more than one dimension at the same time. The member-variables of vector_unit_nd are the value and the vector<dimension> of scalar_unit, and a vector<angle> angles. The number of angles is equal to the number of dimensions vector unit has - 1. In 1D vector_unit_nd doesn't has angles, in 2D vector_unit_nd is in polar coordinates and has 1 angle, and in 3D vector_unit_nd is in spherical coordinates and has 2 angles. All base and derived vectorial unit classes in ND inherit from vector_unit_nd, and add the suffix **_nd** in their name. Initialization string example: "1 N 20° 30° 40°". '°' is the Unicode Character U+00B0. More...
 

Namespaces

namespace  scifir
 The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
 

Macros

#define VECTOR_UNIT_ND_HPP_BEGIN(name)
 
#define VECTOR_UNIT_ND_HPP_END()
 
#define VECTOR_UNIT_ND_HPP(name)
 
#define VECTOR_UNIT_ND_CPP(name, init_real_dimensions)
 

Functions

string scifir::to_string (const vector_unit_nd &x)
 It generates a string representation of vector_unit_nd.
 
scalar_unit scifir::norm (const vector_unit_nd &x)
 It returns the value of the vector, which is the value in 1D, p in 2D (polar coordinates), or r in 3D (spherical coordinates).
 
vector_unit_nd scifir::sqrt (const vector_unit_nd &x)
 It squares the vector, creating a vector_unit_nd with the value squared and always the same angles. The dimensions are squared with the same rules for the square of dimensions than scalar_unit classes.
 
vector_unit_nd scifir::sqrt_nth (const vector_unit_nd &x, int index)
 It takes the root of the vector with the index given, creating a vector_unit_nd with the value rooted to that index and always maintains the same angles. The dimensions are squared with the same rules for the square of dimensions than scalar_unit classes.
 
scalar_unit scifir::dot_product (const vector_unit_nd &x, const vector_unit_nd &y)
 Creates a scalar_unit as the dot product of the two vectors x and y.
 
vector_unit_nd scifir::cross_product (const vector_unit_nd &x, const vector_unit_nd &y)
 Creates a vector_unit_nd as the cross product of the two vectors x and y. If both vectors aren't in 3D, it returns an empty vector_unit_nd, because the cross product doesn't exists outside 3D.
 
angle scifir::angle_between (const vector_unit_nd &x, const vector_unit_nd &y)
 Returns the angle between two vectors x and y inside the ND space, which can be 2D or 3D, depending on the ND of the vectors. If the vectors have different ND, it returns an empty vector_unit_nd instead.
 
bool scifir::same_nd (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors have the same number of dimensions.
 
bool scifir::same_direction (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors x and y have the same direction. Both vectors must have the same ND, otherwise it returns an empty vector_unit_nd instead.
 
bool scifir::parallel (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors x and y are parallel, which means that their direction is the same or the exact opposite. Both vectors must have the same ND, otherwise it returns an empty vector_unit_nd instead.
 
bool scifir::orthogonal (const vector_unit_nd &x, const vector_unit_nd &y)
 Checks if two vectors x and y are orthogonal, that's, if they have 90 degrees between them. Both vectors must have the same ND, otherwise it returns an empty vector_unit_nd instead.
 
scifir::vector_unit_nd operator* (const scifir::scalar_unit &x, const scifir::vector_unit_nd &y)
 It creates a new vector_unitn3d scaling a vector_unit_nd by the scalar_unit x.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator+ (const T y, const scifir::vector_unit_nd &x)
 It creates a new vector as the addition of the numeric type x to the value. The angles are not changed.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator- (const T y, const scifir::vector_unit_nd &x)
 It creates a new vector as the substraction of the numeric type x to the value. The angles are not changed.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator* (const T y, const scifir::vector_unit_nd &x)
 It creates a new vector as the multiplication of the numeric type x to the value. The angles are not changed.
 
template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator/ (const T y, const scifir::vector_unit_nd &x)
 It creates a new vector as the division of the value with the numeric type x. The angles are not changed.
 
bool operator!= (const scifir::vector_unit_nd &x, const scifir::vector_unit_nd &y)
 Comparison operator. Two vector_unit_nd are not equal if their value, dimensions or angles are different.
 
bool operator== (const scifir::vector_unit_nd &x, const string &init_vector_nd)
 Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator!= (const scifir::vector_unit_nd &x, const string &init_vector_nd)
 Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator== (const string &init_vector_nd, const scifir::vector_unit_nd &x)
 Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
bool operator!= (const string &init_vector_nd, const scifir::vector_unit_nd &x)
 Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.
 
void operator+= (string &x, const scifir::vector_unit_nd &y)
 Concatenates the string representation of the vector_unit_nd y to the string x.
 
string operator+ (const string &x, const scifir::vector_unit_nd &y)
 Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.
 
string operator+ (const scifir::vector_unit_nd &y, const string &x)
 Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.
 
ostream & operator<< (ostream &os, const scifir::vector_unit_nd &x)
 Adds the string representation of the vector_unit_nd x to an output stream os.
 
istream & operator>> (istream &is, scifir::vector_unit_nd &x)
 Allows that an istream initializes by string a vector_unit_nd x.
 

Macro Definition Documentation

◆ VECTOR_UNIT_ND_CPP

#define VECTOR_UNIT_ND_CPP (   name,
  init_real_dimensions 
)

Definition at line 132 of file vector_unit_nd.hpp.

132 : vector_unit_nd() {} \
133 name##_nd::name##_nd(const name##_nd& x) : vector_unit_nd(x) {} \
134 name##_nd::name##_nd(name##_nd&& x) : vector_unit_nd(std::move(x)) {} \
135 name##_nd::name##_nd(float new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
136 { \
137 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
138 for(const float& x_angle : new_angles) \
139 { \
140 angles.push_back(angle(x_angle)); \
141 } \
142 } \
143\
144 name##_nd::name##_nd(float new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
145 { \
146 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
147 } \
148\
149 name##_nd::name##_nd(double new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
150 { \
151 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
152 for(const float& x_angle : new_angles) \
153 { \
154 angles.push_back(angle(x_angle)); \
155 } \
156 } \
157\
158 name##_nd::name##_nd(double new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
159 { \
160 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
161 } \
162\
163 name##_nd::name##_nd(long double new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
164 { \
165 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
166 for(const float& x_angle : new_angles) \
167 { \
168 angles.push_back(angle(x_angle)); \
169 } \
170 } \
171\
172 name##_nd::name##_nd(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
173 { \
174 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
175 } \
176\
177 name##_nd::name##_nd(int new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
178 { \
179 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
180 for(const float& x_angle : new_angles) \
181 { \
182 angles.push_back(angle(x_angle)); \
183 } \
184 } \
185\
186 name##_nd::name##_nd(int new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position) : vector_unit_nd(new_value,new_dimension,new_prefix,new_angles,new_position) \
187 { \
188 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
189 } \
190\
191 name##_nd::name##_nd(float new_value,const string& init_dimensions) : vector_unit_nd(new_value,init_dimensions) \
192 { \
193 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
194 } \
195\
196 name##_nd::name##_nd(float new_value,const string& init_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,init_dimensions) \
197 { \
198 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
199 for(const float& x_angle : new_angles) \
200 { \
201 angles.push_back(angle(x_angle)); \
202 } \
203 } \
204\
205 name##_nd::name##_nd(float new_value,const string& init_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,init_dimensions,new_angles) \
206 { \
207 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
208 } \
209\
210 name##_nd::name##_nd(double new_value,const string& init_dimensions) : vector_unit_nd(new_value,init_dimensions) \
211 { \
212 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
213 } \
214\
215 name##_nd::name##_nd(double new_value,const string& init_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,init_dimensions) \
216 { \
217 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
218 for(const float& x_angle : new_angles) \
219 { \
220 angles.push_back(angle(x_angle)); \
221 } \
222 } \
223\
224 name##_nd::name##_nd(double new_value,const string& init_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,init_dimensions,new_angles) \
225 { \
226 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
227 } \
228\
229 name##_nd::name##_nd(long double new_value,const string& init_dimensions) : vector_unit_nd(new_value,init_dimensions) \
230 { \
231 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
232 } \
233\
234 name##_nd::name##_nd(long double new_value,const string& init_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,init_dimensions) \
235 { \
236 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
237 for(const float& x_angle : new_angles) \
238 { \
239 angles.push_back(angle(x_angle)); \
240 } \
241 } \
242\
243 name##_nd::name##_nd(long double new_value,const string& init_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,init_dimensions,new_angles) \
244 { \
245 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
246 } \
247\
248 name##_nd::name##_nd(int new_value,const string& init_dimensions) : vector_unit_nd(new_value,init_dimensions) \
249 { \
250 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
251 } \
252\
253 name##_nd::name##_nd(int new_value,const string& init_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,init_dimensions) \
254 { \
255 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
256 for(const float& x_angle : new_angles) \
257 { \
258 angles.push_back(angle(x_angle)); \
259 } \
260 } \
261\
262 name##_nd::name##_nd(int new_value,const string& init_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,init_dimensions,new_angles) \
263 { \
264 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
265 } \
266\
267 name##_nd::name##_nd(float new_value,const vector<dimension>& new_dimensions) : vector_unit_nd(new_value,new_dimensions) \
268 { \
269 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
270 } \
271\
272 name##_nd::name##_nd(float new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,new_dimensions) \
273 { \
274 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
275 for(const float& x_angle : new_angles) \
276 { \
277 angles.push_back(angle(x_angle)); \
278 } \
279 } \
280\
281 name##_nd::name##_nd(float new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,new_dimensions,new_angles) \
282 { \
283 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
284 } \
285\
286 name##_nd::name##_nd(double new_value,const vector<dimension>& new_dimensions) : vector_unit_nd(new_value,new_dimensions) \
287 { \
288 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
289 } \
290\
291 name##_nd::name##_nd(double new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,new_dimensions) \
292 { \
293 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
294 for(const float& x_angle : new_angles) \
295 { \
296 angles.push_back(angle(x_angle)); \
297 } \
298 } \
299\
300 name##_nd::name##_nd(double new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,new_dimensions,new_angles) \
301 { \
302 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
303 } \
304\
305 name##_nd::name##_nd(long double new_value,const vector<dimension>& new_dimensions) : vector_unit_nd(new_value,new_dimensions) \
306 { \
307 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
308 } \
309\
310 name##_nd::name##_nd(long double new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,new_dimensions) \
311 { \
312 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
313 for(const float& x_angle : new_angles) \
314 { \
315 angles.push_back(angle(x_angle)); \
316 } \
317 } \
318\
319 name##_nd::name##_nd(long double new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,new_dimensions,new_angles) \
320 { \
321 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
322 } \
323\
324 name##_nd::name##_nd(int new_value,const vector<dimension>& new_dimensions) : vector_unit_nd(new_value,new_dimensions) \
325 { \
326 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
327 } \
328\
329 name##_nd::name##_nd(int new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles) : vector_unit_nd(new_value,new_dimensions) \
330 { \
331 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
332 for(const float& x_angle : new_angles) \
333 { \
334 angles.push_back(angle(x_angle)); \
335 } \
336 } \
337\
338 name##_nd::name##_nd(int new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles) : vector_unit_nd(new_value,new_dimensions,new_angles) \
339 { \
340 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
341 } \
342\
343 name##_nd::name##_nd(const scalar_unit& x) : vector_unit_nd(x) \
344 { \
345 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
346 } \
347\
348 name##_nd::name##_nd(const scalar_unit& x,const vector<float>& new_angles) : vector_unit_nd(x) \
349 { \
350 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
351 for(const float& x_angle : new_angles) \
352 { \
353 angles.push_back(angle(x_angle)); \
354 } \
355 } \
356\
357 name##_nd::name##_nd(const scalar_unit& x,const vector<angle>& new_angles) : vector_unit_nd(x,new_angles) \
358 { \
359 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
360 } \
361\
362 name##_nd::name##_nd(const string& init_scalar,const vector<float>& new_angles) : vector_unit_nd(init_scalar) \
363 { \
364 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
365 for(const float& x_angle : new_angles) \
366 { \
367 angles.push_back(angle(x_angle)); \
368 } \
369 } \
370\
371 name##_nd::name##_nd(const string& init_scalar,const vector<angle>& new_angles) : vector_unit_nd(init_scalar,new_angles) \
372 { \
373 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
374 } \
375\
376 name##_nd::name##_nd(const string& init_vector_nd) : vector_unit_nd() \
377 { \
378 vector_unit_nd::initialize_from_string(init_vector_nd); \
379 } \
380\
381 name##_nd::name##_nd(const vector_unit_nd& x) : vector_unit_nd(x) \
382 { \
383 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
384 } \
385\
386 name##_nd::name##_nd(vector_unit_nd&& x) : vector_unit_nd(x) \
387 { \
388 scalar_unit::check_dimensions(name##_nd::real_dimensions); \
389 } \
390\
391 name##_nd& name##_nd::operator =(const name##_nd& x) \
392 { \
393 vector_unit_nd::operator =(x); \
394 return *this; \
395 } \
396\
397 name##_nd& name##_nd::operator =(name##_nd&& x) \
398 { \
399 vector_unit_nd::operator =(std::move(x)); \
400 return *this; \
401 } \
402const string name##_nd::dimensions_match = init_real_dimensions; \
403const vector<dimension> name##_nd::real_dimensions = create_base_dimensions(init_real_dimensions)
vector< dimension > create_base_dimensions(const string &init_dimensions)
Creates the base dimensions from an initialization string of dimensions.

◆ VECTOR_UNIT_ND_HPP

#define VECTOR_UNIT_ND_HPP (   name)

Definition at line 76 of file vector_unit_nd.hpp.

76 : public vector_unit_nd \
77 { \
78 public: \
79 name##_nd(); \
80 name##_nd(const name##_nd&); \
81 name##_nd(name##_nd&&); \
82 explicit name##_nd(float new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles,dimension::position new_position = dimension::NUMERATOR); \
83 explicit name##_nd(float new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
84 explicit name##_nd(double new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position = dimension::NUMERATOR); \
85 explicit name##_nd(double new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
86 explicit name##_nd(long double new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position = dimension::NUMERATOR); \
87 explicit name##_nd(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
88 explicit name##_nd(int new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position = dimension::NUMERATOR); \
89 explicit name##_nd(int new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
90 explicit name##_nd(float new_value,const string& init_dimensions); \
91 explicit name##_nd(float new_value,const string& init_dimensions,const vector<float>& new_angles); \
92 explicit name##_nd(float new_value,const string& init_dimensions,const vector<angle>& new_angles); \
93 explicit name##_nd(double new_value,const string& init_dimensions); \
94 explicit name##_nd(double new_value,const string& init_dimensions,const vector<float>& new_angles); \
95 explicit name##_nd(double new_value,const string& init_dimensions,const vector<angle>& new_angles); \
96 explicit name##_nd(long double new_value,const string& init_dimensions); \
97 explicit name##_nd(long double new_value,const string& init_dimensions,const vector<float>& new_angles); \
98 explicit name##_nd(long double new_value,const string& init_dimensions,const vector<angle>& new_angles); \
99 explicit name##_nd(int new_value,const string& init_dimensions); \
100 explicit name##_nd(int new_value,const string& init_dimensions,const vector<float>& new_angles); \
101 explicit name##_nd(int new_value,const string& init_dimensions,const vector<angle>& new_angles); \
102 explicit name##_nd(float new_value,const vector<dimension>& new_dimensions); \
103 explicit name##_nd(float new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
104 explicit name##_nd(float new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
105 explicit name##_nd(double new_value,const vector<dimension>& new_dimensions); \
106 explicit name##_nd(double new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
107 explicit name##_nd(double new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
108 explicit name##_nd(long double new_value,const vector<dimension>& new_dimensions); \
109 explicit name##_nd(long double new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
110 explicit name##_nd(long double new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
111 explicit name##_nd(int new_value,const vector<dimension>& new_dimensions); \
112 explicit name##_nd(int new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
113 explicit name##_nd(int new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
114 explicit name##_nd(const scalar_unit& x); \
115 explicit name##_nd(const scalar_unit& x,const vector<float>& new_angles); \
116 explicit name##_nd(const scalar_unit& x,const vector<angle>& new_angles); \
117 explicit name##_nd(const string& init_scalar,const vector<float>& new_angles); \
118 explicit name##_nd(const string& init_scalar,const vector<angle>& new_angles); \
119 explicit name##_nd(const string& init_vector_nd); \
120 explicit name##_nd(const vector_unit_nd& x); \
121 explicit name##_nd(vector_unit_nd&& x); \
122 name##_nd& operator =(const name##_nd& x); \
123 name##_nd& operator =(name##_nd&& x); \
124 using vector_unit_nd::operator =; \
125 using vector_unit_nd::operator+=; \
126 using vector_unit_nd::operator-=; \
127\
128 static const string dimensions_match; \
129 static const vector<dimension> real_dimensions; \
130 }

◆ VECTOR_UNIT_ND_HPP_BEGIN

#define VECTOR_UNIT_ND_HPP_BEGIN (   name)

Definition at line 19 of file vector_unit_nd.hpp.

19 : public vector_unit_nd \
20 { \
21 public: \
22 name##_nd(); \
23 name##_nd(const name##_nd&); \
24 name##_nd(name##_nd&&); \
25 explicit name##_nd(float new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles,dimension::position new_position = dimension::NUMERATOR); \
26 explicit name##_nd(float new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
27 explicit name##_nd(double new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position = dimension::NUMERATOR); \
28 explicit name##_nd(double new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
29 explicit name##_nd(long double new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position = dimension::NUMERATOR); \
30 explicit name##_nd(long double new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
31 explicit name##_nd(int new_value, dimension::type new_dimension, prefix::type new_prefix, vector<float> new_angles, dimension::position new_position = dimension::NUMERATOR); \
32 explicit name##_nd(int new_value, dimension::type new_dimension, prefix::type new_prefix, const vector<angle>& new_angles, dimension::position new_position = dimension::NUMERATOR); \
33 explicit name##_nd(float new_value,const string& init_dimensions); \
34 explicit name##_nd(float new_value,const string& init_dimensions,const vector<float>& new_angles); \
35 explicit name##_nd(float new_value,const string& init_dimensions,const vector<angle>& new_angles); \
36 explicit name##_nd(double new_value,const string& init_dimensions); \
37 explicit name##_nd(double new_value,const string& init_dimensions,const vector<float>& new_angles); \
38 explicit name##_nd(double new_value,const string& init_dimensions,const vector<angle>& new_angles); \
39 explicit name##_nd(long double new_value,const string& init_dimensions); \
40 explicit name##_nd(long double new_value,const string& init_dimensions,const vector<float>& new_angles); \
41 explicit name##_nd(long double new_value,const string& init_dimensions,const vector<angle>& new_angles); \
42 explicit name##_nd(int new_value,const string& init_dimensions); \
43 explicit name##_nd(int new_value,const string& init_dimensions,const vector<float>& new_angles); \
44 explicit name##_nd(int new_value,const string& init_dimensions,const vector<angle>& new_angles); \
45 explicit name##_nd(float new_value,const vector<dimension>& new_dimensions); \
46 explicit name##_nd(float new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
47 explicit name##_nd(float new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
48 explicit name##_nd(double new_value,const vector<dimension>& new_dimensions); \
49 explicit name##_nd(double new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
50 explicit name##_nd(double new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
51 explicit name##_nd(long double new_value,const vector<dimension>& new_dimensions); \
52 explicit name##_nd(long double new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
53 explicit name##_nd(long double new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
54 explicit name##_nd(int new_value,const vector<dimension>& new_dimensions); \
55 explicit name##_nd(int new_value,const vector<dimension>& new_dimensions,const vector<float>& new_angles); \
56 explicit name##_nd(int new_value,const vector<dimension>& new_dimensions,const vector<angle>& new_angles); \
57 explicit name##_nd(const scalar_unit& x); \
58 explicit name##_nd(const scalar_unit& x,const vector<float>& new_angles); \
59 explicit name##_nd(const scalar_unit& x,const vector<angle>& new_angles); \
60 explicit name##_nd(const string& init_scalar,const vector<float>& new_angles); \
61 explicit name##_nd(const string& init_scalar,const vector<angle>& new_angles); \
62 explicit name##_nd(const string& init_vector_nd); \
63 explicit name##_nd(const vector_unit_nd& x); \
64 explicit name##_nd(vector_unit_nd&& x); \
65 name##_nd& operator =(const name##_nd& x); \
66 name##_nd& operator =(name##_nd&& x); \
67 using vector_unit_nd::operator =; \
68 using vector_unit_nd::operator+=; \
69 using vector_unit_nd::operator-=

◆ VECTOR_UNIT_ND_HPP_END

#define VECTOR_UNIT_ND_HPP_END ( )
Value:
public: \
static const string dimensions_match; \
static const vector<dimension> real_dimensions; \
}

Definition at line 71 of file vector_unit_nd.hpp.

71 : \
72 static const string dimensions_match; \
73 static const vector<dimension> real_dimensions; \
74 }

Function Documentation

◆ operator!=() [1/3]

bool operator!= ( const scifir::vector_unit_nd x,
const scifir::vector_unit_nd y 
)

Comparison operator. Two vector_unit_nd are not equal if their value, dimensions or angles are different.

Definition at line 947 of file vector_unit_nd.cpp.

948{
949 return !(x == y);
950}

◆ operator!=() [2/3]

bool operator!= ( const scifir::vector_unit_nd x,
const string &  init_vector_nd 
)

Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 958 of file vector_unit_nd.cpp.

959{
960 return !(x == init_vector_nd);
961}

◆ operator!=() [3/3]

bool operator!= ( const string &  init_vector_nd,
const scifir::vector_unit_nd x 
)

Returns true if x is not equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 969 of file vector_unit_nd.cpp.

970{
971 return !(init_vector_nd == x);
972}

◆ operator*() [1/2]

scifir::vector_unit_nd operator* ( const scifir::scalar_unit x,
const scifir::vector_unit_nd y 
)

It creates a new vector_unitn3d scaling a vector_unit_nd by the scalar_unit x.

Definition at line 925 of file vector_unit_nd.cpp.

926{
927 long double new_value = y.get_value() * x.get_value();
928 vector<scifir::dimension> new_dimensions = multiply_dimensions(y.get_dimensions(), x.get_dimensions(),new_value);
929 if(y.is_nd(1))
930 {
931 return scifir::vector_unit_nd(float(new_value), new_dimensions);
932 }
933 else if(y.is_nd(2))
934 {
935 return scifir::vector_unit_nd(float(new_value), new_dimensions, {y.angles[0]});
936 }
937 else if(y.is_nd(3))
938 {
939 return scifir::vector_unit_nd(float(new_value), new_dimensions, {y.angles[0], y.angles[1]});
940 }
941 else
942 {
943 return scifir::vector_unit_nd(float(new_value), new_dimensions, y.angles);
944 }
945}
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
const float & get_value() const
Read-only getter of the value.
Class that creates a vector in ND, which means a variable number of dimensions. A vector_unit_nd can ...
bool is_nd(unsigned int i) const
Returns true if the vector is at the same number of dimensions as i.
vector< angle > angles
The angles. A total of one angle means the vector is in 2D in polar coordinates, two angles means it'...
vector< dimension > multiply_dimensions(const vector< dimension > &x, const vector< dimension > &y)
Multiplies two vectors of dimensions. The result is normalized after, which means that equal dimensio...

◆ operator*() [2/2]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator* ( const T  y,
const scifir::vector_unit_nd x 
)

It creates a new vector as the multiplication of the numeric type x to the value. The angles are not changed.

Definition at line 623 of file vector_unit_nd.hpp.

624{
626 z *= y;
627 return z;
628}

◆ operator+() [1/3]

string operator+ ( const scifir::vector_unit_nd y,
const string &  x 
)

Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.

Definition at line 989 of file vector_unit_nd.cpp.

990{
991 ostringstream output;
992 output << y;
993 output << x;
994 return output.str();
995}

◆ operator+() [2/3]

string operator+ ( const string &  x,
const scifir::vector_unit_nd y 
)

Creates a new string as the concatenation of the string x with the representation string of the vector_unit_nd y.

Definition at line 981 of file vector_unit_nd.cpp.

982{
983 ostringstream output;
984 output << x;
985 output << y;
986 return output.str();
987}

◆ operator+() [3/3]

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator+ ( const T  y,
const scifir::vector_unit_nd x 
)

It creates a new vector as the addition of the numeric type x to the value. The angles are not changed.

Definition at line 609 of file vector_unit_nd.hpp.

610{
612 z += y;
613 return z;
614}

◆ operator+=()

void operator+= ( string &  x,
const scifir::vector_unit_nd y 
)

Concatenates the string representation of the vector_unit_nd y to the string x.

Definition at line 974 of file vector_unit_nd.cpp.

975{
976 ostringstream output;
977 output << y;
978 x += output.str();
979}

◆ operator-()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator- ( const T  y,
const scifir::vector_unit_nd x 
)

It creates a new vector as the substraction of the numeric type x to the value. The angles are not changed.

Definition at line 617 of file vector_unit_nd.hpp.

618{
620}

◆ operator/()

template<typename T , typename = typename enable_if<scifir::is_number<T>::value>::type>
scifir::vector_unit_nd operator/ ( const T  y,
const scifir::vector_unit_nd x 
)

It creates a new vector as the division of the value with the numeric type x. The angles are not changed.

Definition at line 631 of file vector_unit_nd.hpp.

632{
633 vector<scifir::dimension> new_dimensions = x.get_dimensions();
634 for (scifir::dimension& new_dimension : new_dimensions)
635 {
636 new_dimension.invert();
637 }
638 return scifir::vector_unit_nd(y / x.get_value(),new_dimensions,x.angles);
639}
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31

◆ operator<<()

ostream & operator<< ( ostream &  os,
const scifir::vector_unit_nd x 
)

Adds the string representation of the vector_unit_nd x to an output stream os.

Definition at line 997 of file vector_unit_nd.cpp.

998{
999 ostringstream angles_text;
1000 if (!x.is_nd(1))
1001 {
1002 for(const auto& x_angle : x.angles)
1003 {
1004 angles_text << " ";
1005 angles_text << x_angle;
1006 }
1007 }
1008 return os << x.get_value() << " " << x.display_dimensions() << angles_text.str();
1009}
string display_dimensions() const
Generates an string of the dimensions of the scalar_unit, with the same format as the initialization ...

◆ operator==() [1/2]

bool operator== ( const scifir::vector_unit_nd x,
const string &  init_vector_nd 
)

Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 952 of file vector_unit_nd.cpp.

953{
954 scifir::vector_unit_nd y(init_vector_nd);
955 return (x == y);
956}

◆ operator==() [2/2]

bool operator== ( const string &  init_vector_nd,
const scifir::vector_unit_nd x 
)

Returns true if x is equal to the vector_unit_nd initialized with the string being compared. The vectorial_display() function is not used, and so the values are compared with all its decimal numbers.

Definition at line 963 of file vector_unit_nd.cpp.

964{
965 scifir::vector_unit_nd y(init_vector_nd);
966 return (y == x);
967}

◆ operator>>()

istream & operator>> ( istream &  is,
scifir::vector_unit_nd x 
)

Allows that an istream initializes by string a vector_unit_nd x.

Definition at line 1011 of file vector_unit_nd.cpp.

1012{
1013 char a[256];
1014 is.getline(a, 256);
1015 string b(a);
1016 boost::trim(b);
1018 return is;
1019}