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
vector_unit_nd.hpp
Go to the documentation of this file.
1#ifndef SCIFIR_UNITS_UNITS_VECTOR_UNIT_ND_HPP_INCLUDED
2#define SCIFIR_UNITS_UNITS_VECTOR_UNIT_ND_HPP_INCLUDED
3
4#include "./scalar_unit.hpp"
5#include "../meca_number/angle.hpp"
6#include "../util/is_number.hpp"
7#include "../coordinates/direction.hpp"
8
9#include "boost/algorithm/string.hpp"
10
11#include <cmath>
12#include <functional>
13#include <iostream>
14#include <list>
15#include <sstream>
16#include <string>
17#include <vector>
18
19#define VECTOR_UNIT_ND_HPP_BEGIN(name) class name##_nd : 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-=
70
71#define VECTOR_UNIT_ND_HPP_END() public: \
72 static const string dimensions_match; \
73 static const vector<dimension> real_dimensions; \
74 }
75
76#define VECTOR_UNIT_ND_HPP(name) class name##_nd : 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 }
131
132#define VECTOR_UNIT_ND_CPP(name,init_real_dimensions) name##_nd::name##_nd() : 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)
404
405using namespace std;
406
407namespace scifir
408{
410 {
411 public:
423 explicit vector_unit_nd(float new_value,const string& init_dimensions);
424 explicit vector_unit_nd(float new_value,const string& init_dimensions,const vector<float>& new_angles);
425 explicit vector_unit_nd(float new_value,const string& init_dimensions,const vector<angle>& new_angles);
426 explicit vector_unit_nd(double new_value,const string& init_dimensions);
427 explicit vector_unit_nd(double new_value,const string& init_dimensions,const vector<float>& new_angles);
428 explicit vector_unit_nd(double new_value,const string& init_dimensions,const vector<angle>& new_angles);
429 explicit vector_unit_nd(long double new_value,const string& init_dimensions);
430 explicit vector_unit_nd(long double new_value,const string& init_dimensions,const vector<float>& new_angles);
431 explicit vector_unit_nd(long double new_value,const string& init_dimensions,const vector<angle>& new_angles);
432 explicit vector_unit_nd(int new_value,const string& init_dimensions);
433 explicit vector_unit_nd(int new_value,const string& init_dimensions,const vector<float>& new_angles);
434 explicit vector_unit_nd(int new_value,const string& init_dimensions,const vector<angle>& new_angles);
441 explicit vector_unit_nd(long double new_value,const vector<dimension>& new_dimensions);
447 explicit vector_unit_nd(const scalar_unit& x);
448 explicit vector_unit_nd(const scalar_unit& x,const vector<float>& new_angles);
449 explicit vector_unit_nd(const scalar_unit& x,const vector<angle>& new_angles);
450 explicit vector_unit_nd(const string& init_scalar,const vector<float>& new_angles);
451 explicit vector_unit_nd(const string& init_scalar,const vector<angle>& new_angles);
452 explicit vector_unit_nd(const string& init_vector_nd);
453
454 static vector_unit_nd cartesian_2d(const string& init_dimensions,float new_x,float new_y)
455 {
456 float new_value = float(std::sqrt(std::pow(new_x,2) + std::pow(new_y,2)));
459 }
460
461 static vector_unit_nd cartesian_3d(const string& init_dimensions,float new_x,float new_y,float new_z)
462 {
463 float new_value = float(std::sqrt(std::pow(new_x,2) + std::pow(new_y,2) + std::pow(new_z,2)));
467 }
468
470 {
471 float new_value = float(std::sqrt(std::pow(new_p,2) + std::pow(new_z,2)));
474 }
475
481
482 bool operator ==(vector_unit_nd x) const;
483
485
486 void operator +=(const vector_unit_nd& x);
488
491
492 vector_unit_nd operator *(const scalar_unit& x) const;
493 vector_unit_nd operator /(const scalar_unit& x) const;
494 vector_unit_nd operator ^(const scalar_unit& x) const;
495
498 {
499 vector_unit_nd y = *this;
500 y += x;
501 return y;
502 }
503
506 {
507 vector_unit_nd y = *this;
508 y -= x;
509 return y;
510 }
511
514 {
515 vector_unit_nd y = *this;
516 y *= x;
517 return y;
518 }
519
522 {
523 vector_unit_nd y = *this;
524 y /= x;
525 return y;
526 }
527
530 {
532 }
533
536 {
538 }
539
542 {
544 }
545
548 {
549 scalar_unit::value *= std::abs(x);
550 if(x < 0)
551 {
552 invert();
553 }
554 }
555
558 {
559 scalar_unit::value /= std::abs(x);
560 if(x < 0)
561 {
562 invert();
563 }
564 }
565
566 inline bool is_nd(unsigned int i) const
567 {
568 return angles.size() == (i - 1);
569 }
570
571 inline int get_nd() const
572 {
573 return int(angles.size() + 1);
574 }
575
576 scalar_unit n_projection(int i) const;
580
581 void invert();
582
583 string vectorial_display(int number_of_decimals = 2) const;
584 string vectorial_base_display(int number_of_decimals = 2) const;
585 string vectorial_custom_display(const string& init_dimensions,int number_of_decimals = 2) const;
586
588
589 protected:
591 };
592
593 string to_string(const vector_unit_nd& x);
596 vector_unit_nd sqrt_nth(const vector_unit_nd& x,int index);
600 bool same_nd(const vector_unit_nd& x,const vector_unit_nd& y);
601 bool same_direction(const vector_unit_nd& x,const vector_unit_nd& y);
602 bool parallel(const vector_unit_nd& x,const vector_unit_nd& y);
603 bool orthogonal(const vector_unit_nd& x,const vector_unit_nd& y);
604}
605
607
608template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
610{
612 z += y;
613 return z;
614}
615
616template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
621
622template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
624{
626 z *= y;
627 return z;
628}
629
630template<typename T, typename = typename enable_if<scifir::is_number<T>::value>::type>
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}
640
642
643bool operator ==(const scifir::vector_unit_nd& x, const string& init_vector_nd);
644bool operator !=(const scifir::vector_unit_nd& x, const string& init_vector_nd);
645
646bool operator ==(const string& init_vector_nd, const scifir::vector_unit_nd& x);
647bool operator !=(const string& init_vector_nd, const scifir::vector_unit_nd& x);
648
649void operator +=(string& x, const scifir::vector_unit_nd& y);
650string operator +(const string& x, const scifir::vector_unit_nd& y);
651string operator +(const scifir::vector_unit_nd& y, const string& x);
652
653ostream& operator <<(ostream& os, const scifir::vector_unit_nd& x);
654istream& operator >>(istream& is, scifir::vector_unit_nd& x);
655
656#endif // SCIFIR_UNITS_UNITS_VECTOR_UNIT_ND_HPP_INCLUDED
657
Class that allows to work with angles. Each angle sizes 4 bytes. Initialization string example: "20°"...
Definition angle.hpp:77
Class that represents dimensions of the SI system of units. Each dimension sizes 6 bytes,...
Definition dimension.hpp:31
position
Represents the position of the dimension, which can be at the numerator or at the denominator....
Definition dimension.hpp:38
@ NUMERATOR
The dimension is at the numerator.
Definition dimension.hpp:38
type
Represents a dimension of the SI system of units. All the dimensions of the SI system of units are su...
Definition dimension.hpp:34
type
Represents a prefix of the SI system of units. All the prefixes of the SI system of units are support...
Definition prefix.hpp:16
Class that allows to create scalar units, which are composed of a value (as a float) and dimensions....
const vector< dimension > & get_dimensions() const
Read-only getter of the dimensions.
float value
Value of the scalar_unit. It changes automatically when the dimensions change.
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 ...
vector_unit_nd()
Default constructor. The value is 0, the dimensions are empty and the angles are empty.
scalar_unit n_projection(int i) const
Returns the x projection, the y projection or the z projection, depending if i is 1 (it returns x),...
string vectorial_display(int number_of_decimals=2) const
Displays the vector as the string representation of the scalar unit adding also all the angles.
vector_unit_nd & operator=(const vector_unit_nd &x)
Copy assignment. The member-variables are copied from vector_unit_nd x.
void operator+=(const vector_unit_nd &x)
The vector_unit_nd is summed as vector in 2D, 3D, or more coordinates. It's summed as scalar in 1D.
int get_nd() const
Returns the number of dimensions.
bool is_nd(unsigned int i) const
Returns true if the vector is at the same number of dimensions as i.
bool operator==(vector_unit_nd x) const
Comparison operator. Two vector_unit_nd are equal if their value, dimensions and angles are the same.
vector< angle > angles
The angles. A total of one angle means the vector is in 2D in polar coordinates, two angles means it'...
string vectorial_base_display(int number_of_decimals=2) const
Displays the vector as the string representation of the scalar unit adding also all the angles....
scalar_unit x_projection() const
It creates the x projection of the vector, returning it as a scalar_unit of the same dimensions,...
vector_unit_nd operator+(const vector_unit_nd &x) const
Addition of vectors in 2D, 3D, or more coordinates. It's an addition of scalars in 1D....
void operator/=(T x)
It divides the numeric type x to the value. The angles are not changed.
scalar_unit y_projection() const
It creates the y projection of the vector, returning it as a scalar_unit of the same dimensions,...
vector_unit_nd operator/(const scalar_unit &x) const
It creates a new vector_unit_3d scaling a vector_unit_3d by the inverse of the scalar_unit x.
void operator-=(vector_unit_nd x)
The vector_unit_nd is substracted as vector in 2D, 3D, or more coordinates. It's substracted as scala...
static vector_unit_nd cylindrical(const string &init_dimensions, float new_p, angle new_theta, float new_z)
The dimensions are initialized from the initialization string of dimensions new_dimensions,...
static vector_unit_nd cartesian_3d(const string &init_dimensions, float new_x, float new_y, float new_z)
The dimensions are initialized from the initialization string of dimensions new_dimensions,...
vector_unit_nd operator-(vector_unit_nd x) const
Substraction of vectors in 2D, 3D, or more coordinates. It's a substraction of scalars in 1D....
void point_to(direction::name x)
The angles are set to the direction specified in 1D, 2D or 3D, depending on the current ND of vector_...
vector_unit_nd operator*(const scalar_unit &x) const
It creates a new vector_unit_nd scaling a vector_unit_nd by the scalar_unit x.
scalar_unit z_projection() const
It creates the z projection of the vector, returning it as a scalar_unit of the same dimensions,...
string vectorial_custom_display(const string &init_dimensions, int number_of_decimals=2) const
Displays the vector as the string representation of the scalar unit adding also all the angles....
vector_unit_nd operator^(const scalar_unit &x) const
It powers a vector by a scalar_unit x if that scalar_unit has empty dimensions.
void operator*=(T x)
It multiplies the numeric type x to the value. The angles are not changed.
static vector_unit_nd cartesian_2d(const string &init_dimensions, float new_x, float new_y)
The dimensions are initialized from the initialization string of dimensions new_dimensions,...
void initialize_from_string(string init_vector_nd)
Initializes the member-variables with the initialization string of vector_unit_nd init_vector_nd.
The namespace scifir contains all scifir-units, excepting the string literals, which are outside.
Definition address.cpp:6
angle angle_between(const vector_unit_2d &x, const vector_unit_2d &y)
Returns the angle between two vectors x and y inside a 2D space.
angle sqrt_nth(const angle &x, int index)
Calculates the nth root of the angle x and returns that new angle.
Definition angle.cpp:421
bool same_direction(const vector_unit_2d &x, const vector_unit_2d &y)
Checks if two vectors x and y have the same direction.
bool orthogonal(const angle &x, const angle &y)
Checks if two angles in a 2D correspond to orthogonal lines (or orthogonal vectors).
Definition angle.cpp:403
float atan_degree(float x)
Calculates the atan receiving x in degrees. It uses the atan() function of the standard library of C+...
Definition angle.hpp:252
string to_string(const aid &x)
Creates a string representation of aid, it's for aid equivalent to the display() function of aid.
Definition aid.cpp:582
bool same_nd(const vector_unit_nd &x, const vector_unit_nd &y)
Checks if two vectors have the same number of dimensions.
float acos_degree(float x)
Calculates the acos receiving x in degrees. It uses the acos() function of the standard library of C+...
Definition angle.hpp:247
scalar_unit dot_product(const vector_unit_2d &x, const vector_unit_2d &y)
Creates a scalar_unit as the dot product of the two vectors x and y.
vector_unit_3d cross_product(const vector_unit_3d &x, const vector_unit_3d &y)
Creates a vector_unit_3d as the cross product of the two vectors x and y.
scalar_unit norm(const vector_unit_2d &x)
It returns the value of the vector in polar coordinates, p.
angle sqrt(const angle &x)
Calculates the square root of the angle x and returns that new angle.
Definition angle.cpp:416
bool parallel(const angle &x, const angle &y)
Checks if two angles in a 2D correspond to parallel lines (or parallel vectors).
Definition angle.cpp:391
vector< dimension > power_dimensions(const vector< dimension > &x, int exponent)
Powers the dimensions by an exponent.
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 differ...
istream & operator>>(istream &is, scifir::vector_unit_nd &x)
Allows that an istream initializes by string a vector_unit_nd x.
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 ch...
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....
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.
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.
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 change...
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 chan...
void operator+=(string &x, const scifir::vector_unit_nd &y)
Concatenates the string representation of the vector_unit_nd y to the string x.