API Documentation
Loading...
Searching...
No Matches
VectorFunctions.hpp
Go to the documentation of this file.
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: VectorFunctions
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Vector.h>
34#include <cmath>
35
36namespace NDEVR
37{
38 /**--------------------------------------------------------------------------------------------------
39 \brief Dummy class to include functions related to vector math
40 **/
42 {};
43 /**--------------------------------------------------------------------------------------------------
44
45 \brief Addition operator.
46
47 Author: Tyler Parke
48
49 Date: 2017-11-13
50
51 Parameters:
52 vec_a - The first value.
53 vec_b - A value to add to it.
54
55 \returns The result of the operation.
56 **/
57 template<class t_vector_type, uint01 t_dims, class t_type>
58 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, t_type>, t_vector_type>::value, t_vector_type>::type
59 operator+(const t_vector_type& vec_a, const Vector<t_dims, t_type>& vec_b)
60 {
61 t_vector_type sum;
62 for (uint01 dim = 0; dim < t_dims; ++dim)
63 sum[dim] = vec_a[dim] + vec_b[dim];
64 return sum;
65 }
66
67 /**--------------------------------------------------------------------------------------------------
68
69 Addition operator.
70
71 Author: Tyler Parke
72
73 Date: 2017-11-13
74
75 Parameters:
76 scaler_a - The first value.
77 vec_b - A value to add to it.
78
79 \returns The result of the operation.
80 **/
81 template<uint01 t_dims, class t_type>
82 constexpr Vector<t_dims, t_type> operator+(const t_type& scaler_a, const Vector<t_dims, t_type>& vec_b)
83 {
85 for (uint01 dim = 0; dim < t_dims; ++dim)
86 sum[dim] = scaler_a + vec_b[dim];
87 return sum;
88 }
89
90 /**--------------------------------------------------------------------------------------------------
91
92 Addition operator.
93
94 Author: Tyler Parke
95
96 Date: 2017-11-13
97
98 Parameters:
99 vec_a - The first value.
100 scaler_b - A value to add to it.
101
102 \returns The result of the operation.
103 **/
104 template<class t_vector_type, class t_type>
105 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
106 operator+(const t_vector_type& vec_a, const t_type& scaler_b)
107 {
108 t_vector_type sum;
109 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
110 sum[dim] = vec_a[dim] + scaler_b;
111 return sum;
112 }
113 template<class t_vector_type, class t_type>
114 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
115 operator+(const t_type& scaler_a, const t_vector_type& vec_b)
116 {
117 t_vector_type sum;
118 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
119 sum[dim] = scaler_a + vec_b[dim];
120 return sum;
121 }
122
123 /**--------------------------------------------------------------------------------------------------
124
125 Addition assignment operator.
126
127 Author: Tyler Parke
128
129 Date: 2017-11-13
130
131 Parameters:
132 vec_a - [in,out] The vector a.
133 vec_b - The vector b.
134
135 \returns The result of the operation.
136 **/
137 template<uint01 t_dims, class t_type>
139 {
140 for (uint01 dim = 0; dim < t_dims; ++dim)
141 vec_a[dim] += vec_b[dim];
142 return vec_a;
143 }
144
145 /**--------------------------------------------------------------------------------------------------
146
147 Addition assignment operator.
148
149 Author: Tyler Parke
150
151 Date: 2017-11-13
152
153 Parameters:
154 vec_a - [in,out] The vector a.
155 scaler_b - The scaler b.
156
157 \returns The result of the operation.
158 **/
159 template<uint01 t_dims, class t_type>
160 constexpr Vector<t_dims, t_type>& operator+=(Vector<t_dims, t_type>& vec_a, t_type scaler_b)
161 {
162 for (uint01 dim = 0; dim < t_dims; ++dim)
163 vec_a[dim] += scaler_b;
164 return vec_a;
165 }
166
167 /**--------------------------------------------------------------------------------------------------
168
169 Subtraction operator.
170
171 Author: Tyler Parke
172
173 Date: 2017-11-13
174
175 Parameters:
176 vec_a - The first value.
177 vec_b - A value to subtract from it.
178
179 \returns The result of the operation.
180 **/
181 template<class t_vector_type, uint01 t_dims, class t_type>
182 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, t_type>, t_vector_type>::value, t_vector_type>::type
183 operator-(const t_vector_type& vec_a, const Vector<t_dims, t_type>& vec_b)
184 {
185 t_vector_type difference;
186 for (uint01 dim = 0; dim < t_dims; ++dim)
187 difference[dim] = vec_a[dim] - vec_b[dim];
188 return difference;
189 }
190
191 /**--------------------------------------------------------------------------------------------------
192
193 Subtraction operator.
194
195 Author: Tyler Parke
196
197 Date: 2017-11-13
198
199 Parameters:
200 value_a - The first value.
201 vec_b - A value to subtract from it.
202
203 \returns The result of the operation.
204 **/
205 template<uint01 t_dims, class t_type>
206 constexpr Vector<t_dims, t_type> operator-(const t_type& value_a, const Vector<t_dims, t_type>& vec_b)
207 {
208 Vector<t_dims, t_type> difference;
209 for (uint01 dim = 0; dim < t_dims; ++dim)
210 difference[dim] = value_a - vec_b[dim];
211 return difference;
212 }
213
214 /**--------------------------------------------------------------------------------------------------
215
216 Subtraction operator.
217
218 Author: Tyler Parke
219
220 Date: 2017-11-13
221
222 Parameters:
223 vec_a - The first value.
224 value_b - A value to subtract from it.
225
226 \returns The result of the operation.
227 **/
228 template<class t_vector_type, class t_type>
229 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
230 operator-(const t_vector_type& vec_a, const t_type& value_b)
231 {
232 t_vector_type difference;
233 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
234 difference[dim] = vec_a[dim] - value_b;
235 return difference;
236 }
237
238 /**--------------------------------------------------------------------------------------------------
239
240 Subtraction assignment operator.
241
242 Author: Tyler Parke
243
244 Date: 2017-11-13
245
246 Parameters:
247 vec_a - [in,out] The vector a.
248 vec_b - The vector b.
249
250 \returns The result of the operation.
251 **/
252 template<uint01 t_dims, class t_type>
254 {
255 for (uint01 dim = 0; dim < t_dims; ++dim)
256 vec_a[dim] -= vec_b[dim];
257 return vec_a;
258 }
259
260 /**--------------------------------------------------------------------------------------------------
261
262 Subtraction assignment operator.
263
264 Author: Tyler Parke
265
266 Date: 2017-11-13
267
268 Parameters:
269 vec_a - [in,out] The vector a.
270 value_b - The value b.
271
272 \returns The result of the operation.
273 **/
274 template<uint01 t_dims, class t_type>
276 {
277 for (uint01 dim = 0; dim < t_dims; ++dim)
278 vec_a[dim] -= value_b;
279 return vec_a;
280 }
281
282 /**--------------------------------------------------------------------------------------------------
283
284 Multiplication operator.
285
286 Author: Tyler Parke
287
288 Date: 2017-11-13
289
290 Parameters:
291 vec_a - The first value to multiply.
292 vec_b - The second value to multiply.
293
294 \returns The result of the operation.
295 **/
296 template<uint01 t_dims, class t_type>
298 {
300 for (uint01 dim = 0; dim < t_dims; ++dim)
301 product[dim] = vec_a[dim] * vec_b[dim];
302 return product;
303 }
304
305 /**--------------------------------------------------------------------------------------------------
306
307 Multiplication operator.
308
309 Author: Tyler Parke
310
311 Date: 2017-11-13
312
313 Parameters:
314 value_a - The first value to multiply.
315 vec_b - The second value to multiply.
316
317 \returns The result of the operation.
318 **/
319 template<class t_vector_type, class t_type>
320 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
321 operator*(const t_type& value_a, const t_vector_type& vec_b)
322 {
323 t_vector_type product;
324 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
325 product[dim] = value_a * vec_b[dim];
326 return product;
327 }
328
329 /**--------------------------------------------------------------------------------------------------
330
331 Multiplication operator.
332
333 Author: Tyler Parke
334
335 Date: 2017-11-13
336
337 Parameters:
338 vec_a - The first value to multiply.
339 value_b - The second value to multiply.
340
341 \returns The result of the operation.
342 **/
343 template<class t_vector_type, class t_type>
344 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
345 operator*(const t_vector_type& vec_a, const t_type& value_b)
346 {
347 t_vector_type product;
348 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
349 product[dim] = vec_a[dim] * value_b;
350 return product;
351 }
352
353 /**--------------------------------------------------------------------------------------------------
354
355 Multiplication assignment operator.
356
357 Author: Tyler Parke
358
359 Date: 2017-11-13
360
361 Parameters:
362 vec_a - [in,out] The vector a.
363 vec_b - The vector b.
364
365 \returns The result of the operation.
366 **/
367 template<uint01 t_dims, class t_type>
369 {
370 for (uint01 dim = 0; dim < t_dims; ++dim)
371 vec_a[dim] *= vec_b[dim];
372 return vec_a;
373 }
374
375 /**--------------------------------------------------------------------------------------------------
376
377 Multiplication assignment operator.
378
379 Author: Tyler Parke
380
381 Date: 2017-11-13
382
383 Parameters:
384 vec_a - [in,out] The vector a.
385 value_b - The value b.
386
387 \returns The result of the operation.
388 **/
389 template<uint01 t_dims, class t_type>
391 {
392 for (uint01 dim = 0; dim < t_dims; ++dim)
393 vec_a[dim] *= value_b;
394 return vec_a;
395 }
396
397 /**--------------------------------------------------------------------------------------------------
398
399 Division operator.
400
401 Author: Tyler Parke
402
403 Date: 2017-11-13
404
405 Parameters:
406 vec_a - The numerator.
407 vec_b - The denominator.
408
409 \returns The result of the operation.
410 **/
411 template<uint01 t_dims, class t_type>
413 {
414 Vector<t_dims, t_type> quotient;
415 for (uint01 dim = 0; dim < t_dims; ++dim)
416 quotient[dim] = vec_a[dim] / vec_b[dim];
417 return quotient;
418 }
419
420 /**--------------------------------------------------------------------------------------------------
421
422 Division operator.
423
424 Author: Tyler Parke
425
426 Date: 2017-11-13
427
428 Parameters:
429 value_a - The numerator.
430 vec_b - The denominator.
431
432 \returns The result of the operation.
433 **/
434 template<class t_vector_type, class t_type>
435 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
436 operator/(const t_type& value_a, const t_vector_type& vec_b)
437 {
438 t_vector_type quotient;
439 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
440 quotient[dim] = value_a / vec_b[dim];
441 return quotient;
442 }
443
444 /**--------------------------------------------------------------------------------------------------
445
446 Division operator.
447
448 Author: Tyler Parke
449
450 Date: 2017-11-13
451
452 Parameters:
453 vec_a - The numerator.
454 value_b - The denominator.
455
456 \returns The result of the operation.
457 **/
458 template<class t_vector_type, class t_type>
459 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
460 operator/(const t_vector_type& vec_a, const t_type& value_b)
461 {
462 t_vector_type quotient;
463 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
464 quotient[dim] = vec_a[dim] / value_b;
465 return quotient;
466 }
467
468
469 /**--------------------------------------------------------------------------------------------------
470
471 Xor operator.
472
473 Author: Tyler Parke
474
475 Date: 2018-04-10
476
477 Parameters:
478 vec_a - The first value to xor.
479 vec_b - The second value to xor.
480
481 \returns The result of the operation.
482 **/
483 /*template<uint01 t_dims, class t_type>
484 constexpr Vector<t_dims, t_type> operator^(const Vector<t_dims, t_type>& vec_a, const Vector<t_dims, t_type>& vec_b)
485 {
486 Vector<t_dims, t_type> xor;
487 for (uint01 dim = 0; dim < t_dims; ++dim)
488 xor[dim] = vec_a[dim] ^ vec_b[dim];
489 return xor;
490 }*/
491
492
493 template<uint01 t_dims, class t_type>
495 {
497 for (uint01 dim = 0; dim < t_dims; ++dim)
498 mod [dim] = std::fmod(vec_a[dim], vec_b[dim]);
499 return mod;
500 }
501 template<uint01 t_dims, class t_type>
502 constexpr Vector<t_dims, t_type> operator%(const Vector<t_dims, t_type>& vec_a, const t_type& value_b)
503 {
505 for (uint01 dim = 0; dim < t_dims; ++dim)
506 mod[dim] = cast<t_type>(::fmod(vec_a[dim], value_b));
507 return mod;
508 }
509
510
511 /**--------------------------------------------------------------------------------------------------
512
513 Division assignment operator.
514
515 Author: Tyler Parke
516
517 Date: 2017-11-13
518
519 Parameters:
520 vec_a - [in,out] The vector a.
521 vec_b - The vector b.
522
523 \returns The result of the operation.
524 **/
525 template<uint01 t_dims, class t_type>
527 {
528 for (uint01 dim = 0; dim < t_dims; ++dim)
529 vec_a[dim] = vec_a[dim] / vec_b[dim];
530 return vec_a;
531 }
532
533
534 /**--------------------------------------------------------------------------------------------------
535
536 Division assignment operator.
537
538 Author: Tyler Parke
539
540 Date: 2017-11-13
541
542 Parameters:
543 vec_a - [in,out] The vector a.
544 value_b - The value b.
545
546 \returns The result of the operation.
547 **/
548 template<uint01 t_dims, class t_type>
550 {
551 for (uint01 dim = 0; dim < t_dims; ++dim)
552 vec_a[dim] = vec_a[dim] / value_b;
553 return vec_a;
554 }
555
556 template<class t_vector_type, class t_type>
557 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
558 operator==(const t_vector_type& v, const t_type& s)
559 {
560 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
561 {
562 if (v[dim] != s)
563 return false;
564 }
565 return true;
566 }
567 template<class t_vector_type, class t_type>
568 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
569 operator==(const t_type& s, const t_vector_type& v)
570 {
571 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
572 {
573 if (v[dim] != s)
574 return false;
575 }
576 return true;
577 }
578 template<class t_vector_type>
579 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
580 operator==(const t_vector_type& v_a, const t_vector_type& v_b)
581 {
582 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
583 {
584 if (v_a[dim] != v_b[dim])
585 return false;
586 }
587 return true;
588 }
589 template<class t_type>
590 constexpr typename std::enable_if<!IsVec<t_type>::value, bool>::type
591 AreSame(const t_type& a, const t_type& b)
592 {
593 return (a == b) || (IsInvalid(a) && IsInvalid(b));
594 }
595 template<class t_type>
596 constexpr typename std::enable_if<!IsVec<t_type>::value, bool>::type
597 AreSame(const t_type& a, const t_type& b, const t_type& epsilon)
598 {
599 return (IsInvalid(a) && IsInvalid(b))
600 || ::abs(a - b) < epsilon;
601 }
602 //Equal but with nans
603 template<class t_vector_type>
604 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
605 AreSame(const t_vector_type& v_a, const t_vector_type& v_b)
606 {
607 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
608 {
609 if (!AreSame(v_a[dim], v_b[dim]))
610 return false;
611 }
612 return true;
613 }
614 template<class t_vector_type, class t_type>
615 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
616 AreSame(const t_vector_type& v_a, const t_vector_type& v_b, const t_type& epsilon)
617 {
618 return (IsInvalid(v_a) && IsInvalid(v_b))
619 || abs(v_a - v_b) < epsilon;
620 }
621 template<class t_vector_type>
622 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
623 operator!=(const t_vector_type& v_a, const t_vector_type& v_b)
624 {
625 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
626 {
627 if (v_a[dim] != v_b[dim])
628 return true;
629 }
630 return false;
631 }
632 template<class t_vector_type, class t_type>
633 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
634 operator!=(const t_vector_type& v, const t_type& s)
635 {
636 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
637 {
638 if (v[dim] != s)
639 return true;
640 }
641 return false;
642 }
643 template<class t_vector_type, class t_type>
644 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
645 operator!=(const t_type& s, const t_vector_type& v)
646 {
647 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
648 {
649 if (v[dim] != s)
650 return true;
651 }
652 return false;
653 }
654
655 /**--------------------------------------------------------------------------------------------------
656
657 Greater-than-or-equal comparison operator.
658
659 Author: Tyler Parke
660
661 Date: 2017-11-13
662
663 Parameters:
664 v1 - The first instance to compare.
665 v2 - The second instance to compare.
666
667 \returns True if the first parameter is greater than or equal to the second.
668 **/
669 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
671 {
672 const uint01 min_val = getMin(vec_1_size, vec_2_size);
673 for (uint01 dim = 0; dim < min_val; ++dim)
674 {
675 if (!(v1[dim] >= v2[dim]))
676 return false;
677 }
678 return true;
679 }
680
681 template<uint01 t_dims, class t_type>
682 constexpr bool operator>=(const Vector<t_dims, t_type>& v1, const t_type& s)
683 {
684 for (uint01 dim = 0; dim < t_dims; ++dim)
685 {
686 if (!(v1[dim] >= s))
687 return false;
688 }
689 return true;
690 }
691
692
693 /**--------------------------------------------------------------------------------------------------
694
695 Greater-than comparison operator.
696
697 Author: Tyler Parke
698
699 Date: 2017-11-13
700
701 Parameters:
702 v1 - The first instance to compare.
703 v2 - The second instance to compare.
704
705 \returns True if the first parameter is greater than to the second.
706 **/
707 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
709 {
710 const uint01 min_val = getMin(vec_1_size, vec_2_size);
711 for (uint01 dim = 0; dim < min_val; ++dim)
712 {
713 if (!(v1[dim] > v2[dim]))
714 return false;
715 }
716 return true;
717 }
718
719 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
721 {
722 const t_type min_val = getMin(vec_1_size, vec_2_size);
723 for (uint01 dim = 0; dim < min_val; ++dim)
724 {
725 if (!(v1[dim] < v2[dim]))
726 return false;
727 }
728 return true;
729 }
730 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
732 {
733 const uint01 min_val = getMin(vec_1_size, vec_2_size);
734 for (uint01 dim = 0; dim < min_val; ++dim)
735 {
736 if (!(v1[dim] <= v2[dim]))
737 return false;
738 }
739 return true;
740 }
741
742 /**--------------------------------------------------------------------------------------------------
743 Greater-than-or-equal comparison operator.
744
745 Author: Tyler Parke
746
747 Date: 2017-11-13
748
749 Parameters:
750 v1 - The first instance to compare.
751 v2 - The second instance to compare.
752
753 \returns True if the first parameter is greater than or equal to the second.
754 **/
755 template<uint01 t_dims, class t_type>
756 constexpr bool operator>=(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
757 {
758 for (uint01 dim = 0; dim < t_dims; ++dim)
759 {
760 if (!(v1[dim] >= v2[dim]))
761 return false;
762 }
763 return true;
764 }
765
766
767
768 /**--------------------------------------------------------------------------------------------------
769 Greater-than comparison operator.
770
771 Author: Tyler Parke
772
773 Date: 2017-11-13
774
775 Parameters:
776 v1 - The first instance to compare.
777 v2 - The second instance to compare.
778
779 \returns True if the first parameter is greater than to the second.
780 **/
781 template<uint01 t_dims, class t_type>
782 constexpr bool operator>(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
783 {
784 for (uint01 dim = 0; dim < t_dims; dim++)
785 {
786 if (!(v1[dim] > v2[dim]))
787 return false;
788 }
789 return true;
790 }
791
792 template<uint01 t_dims, class t_type>
793 constexpr bool operator<(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
794 {
795 for (uint01 dim = 0; dim < t_dims; dim++)
796 {
797 if (!(v1[dim] < v2[dim]))
798 return false;
799 }
800 return true;
801 }
802
803 template<class t_vector_type, class t_type>
804 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
805 operator<(const t_vector_type& v, const t_type& s)
806 {
807 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
808 {
809 if (!(v[dim] < s))
810 return false;
811 }
812 return true;
813 }
814 template<class t_vector_type, class t_type>
815 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
816 operator<(const t_type& s, const t_vector_type& v)
817 {
818 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
819 {
820 if (!(s < v[dim]))
821 return false;
822 }
823 return true;
824 }
825 template<class t_vector_type, class t_type>
826 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
827 operator<=(const t_type& s, const t_vector_type& v)
828 {
829 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
830 {
831 if (!(s <= v[dim]))
832 return false;
833 }
834 return true;
835 }
836
837 template<class t_vector_type, class t_type>
838 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
839 operator<=(const t_vector_type& v, const t_type& s)
840 {
841 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
842 {
843 if (!(v[dim] <= s))
844 return false;
845 }
846 return true;
847 }
848 template<class t_vector_type, class t_type>
849 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
850 operator>(const t_vector_type& v, const t_type& s)
851 {
852 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
853 {
854 if (!(v[dim] > s))
855 return false;
856 }
857 return true;
858 }
859 template<class t_vector_type, class t_type>
860 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
861 operator>(const t_type& s, const t_vector_type& v)
862 {
863 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
864 {
865 if (!(s > v[dim]))
866 return false;
867 }
868 return true;
869 }
870
871 template<uint01 t_dims, class t_type>
872 constexpr bool operator<=(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
873 {
874 for (uint01 dim = 0; dim < t_dims; dim++)
875 {
876 if (!(v1[dim] <= v2[dim]))
877 return false;
878 }
879 return true;
880 }
881
882
883 /**--------------------------------------------------------------------------------------------------
884
885 Returns the cross product of 2 numbers. Note cross product is defined only for certain dimensions
886
887 Author: Tyler Parke
888
889 Date: 2017-05-17
890
891 Parameters:
892 v1 - The first Vector&lt;t_dims,t_type&gt;
893 v2 - The second Vector&lt;t_dims,t_type&gt;
894
895 \returns A Vector&lt;t_dims,t_type&gt of v1 X v2;
896 **/
897 template<class t_type>
899 {
900 return Vector<1, t_type>(1);
901 }
902 template<class t_type>
903 constexpr t_type cross(const Vector<2, t_type>& v1, const Vector<2, t_type>& v2)
904 {
905 return v1[X] * v2[Y] - v1[Y] * v2[X];
906 }
907 template<class t_type>
908 constexpr Vector<2, t_type> cross(const Vector<2, t_type>& v1, const t_type& v2)
909 {
910 return Vector<2, t_type>(v2 * v1[Y], -v2 * v1[X]);
911 }
912 template<class t_type>
914 {
916 cross[X] = ((v1[Y] * v2[Z]) - (v1[Z] * v2[Y]));
917 cross[Y] = ((v1[Z] * v2[X]) - (v1[X] * v2[Z]));
918 cross[Z] = ((v1[X] * v2[Y]) - (v1[Y] * v2[X]));
919 return cross;
920 }
921
922 /**--------------------------------------------------------------------------------------------------
923
924 Finds the max of the given arguments.
925
926 Author: Tyler Parke
927
928 Date: 2017-11-13
929
930 Parameters:
931 v1 - The first Vector&lt;t_dims,t_type&gt;
932 v2 - The second Vector&lt;t_dims,t_type&gt;
933
934 \returns The calculated maximum.
935 **/
936 template<uint01 t_dims, class t_type>
938 {
940 for (uint01 dim = 0; dim < t_dims; dim++)
941 {
942 vec[dim] = getMax(v1[dim], v2[dim]);
943 }
944 return vec;
945 }
946
947 /**--------------------------------------------------------------------------------------------------
948
949 Finds the min of the given arguments.
950
951 Author: Tyler Parke
952
953 Date: 2017-11-13
954
955 Parameters:
956 v1 - The first Vector&lt;t_dims,t_type&gt;
957 v2 - The second Vector&lt;t_dims,t_type&gt;
958
959 \returns The calculated minimum.
960 **/
961 template<uint01 t_dims, class t_type>
963 {
965 for (uint01 dim = 0; dim < t_dims; dim++)
966 {
967 vec[dim] = getMin(v1[dim], v2[dim]);
968 }
969 return vec;
970 }
971
972 /**--------------------------------------------------------------------------------------------------
973
974 Determinates.
975
976 Author: Tyler Parke
977
978 Date: 2017-11-13
979
980 Parameters:
981 v1 - The first Vector&lt;t_dims,t_type&gt;
982 v2 - The second Vector&lt;t_dims,t_type&gt;
983
984 \returns A t_type.
985 **/
986 template<uint01 t_dims, class t_type>
988 {
989 return (v1[X] * v2[Y]) - (v1[Y] * v2[X]);
990 }
991
992 /**--------------------------------------------------------------------------------------------------
993
994 Determinates.
995
996 Author: Tyler Parke
997
998 Date: 2017-11-13
999
1000 Parameters:
1001 v1 - The first Vector&lt;t_dims,t_type&gt;
1002 v2 - The second Vector&lt;t_dims,t_type&gt;
1003 v3 - The third Vector&lt;t_dims,t_type&gt;
1004
1005 \returns A t_type.
1006 **/
1007 template<uint01 t_dims, class t_type>
1009 {
1010 t_type x_det = v1[X] * determinate(Vector<2, t_type>(v2.dim[Y], v2.dim[Z]), Vector<2, t_type>(v3.dim[Y], v3.dim[Z]));
1011 t_type y_det = v1[Y] * determinate(Vector<2, t_type>(v2.dim[X], v2.dim[Z]), Vector<2, t_type>(v3.dim[X], v3.dim[Z]));
1012 t_type z_det = v1[Z] * determinate(Vector<2, t_type>(v2.dim[X], v2.dim[Y]), Vector<2, t_type>(v3.dim[X], v3.dim[Y]));
1013 return x_det - y_det + z_det;
1014 }
1015
1016 /**--------------------------------------------------------------------------------------------------
1017 Dots.
1018
1019 Author: Tyler Parke
1020
1021 Date: 2017-11-13
1022
1023 Parameters:
1024 v1 - The first Vector&lt;t_dims,t_type&gt;
1025 v2 - The second Vector&lt;t_dims,t_type&gt;
1026
1027 \returns A t_type.
1028 **/
1029 template<uint01 t_dims, class t_type>
1031 {
1032 t_type value = 0;
1033 for (uint01 dim = 0; dim < t_dims; ++dim)
1034 value += v1[dim] * v2[dim];
1035 return value;
1036 }
1037
1038 /**--------------------------------------------------------------------------------------------------
1039
1040 Determine if we are parallel.
1041
1042 Author: Tyler Parke
1043
1044 Date: 2017-11-13
1045
1046 Parameters:
1047 v1 - The first Vector&lt;t_dims,t_type&gt;
1048 v2 - The second Vector&lt;t_dims,t_type&gt;
1049
1050 \returns True if parallel, false if not.
1051 **/
1052 template<uint01 t_dims, class t_type>
1054 {
1055 t_type magnitude_1 = v1.getMagnitudeSquared();
1056 t_type magnitude_2 = v2.getMagnitudeSquared();
1057 return v2 * v2 * (magnitude_1) == v1 * v1 * magnitude_2;
1058 }
1059
1060 /**--------------------------------------------------------------------------------------------------
1061
1062 Tests if objects are considered equal.
1063
1064 Author: Tyler Parke
1065
1066 Date: 2017-11-13
1067
1068 Parameters:
1069 left - Constant vector&lt;t dims,t type&gt;&amp; to be compared.
1070 right - Constant vector&lt;t dims,t type&gt;&amp; to be compared.
1071 epsilon - (Optional) Constant type&amp; to be compared.
1072
1073 \returns True if the objects are considered equal, false if they are not.
1074 **/
1075 template<uint01 t_dims, class t_type>
1076 constexpr bool equals(const Vector<t_dims, t_type>& left, const Vector<t_dims, t_type>& right, const t_type& epsilon = cast<t_type>(0))
1077 {
1078 return (abs(left - right) < epsilon);
1079 }
1080
1081 /**--------------------------------------------------------------------------------------------------
1082 Abs the given value.
1083
1084 Author: Tyler Parke
1085
1086 Date: 2017-11-13
1087
1088 Parameters:
1089 value - The value.
1090
1091 \returns A t_type.
1092 **/
1093
1094 template<class t_type>
1095 constexpr typename std::enable_if<!IsVec<t_type>::value, t_type>::type
1096 abs(const t_type& value)
1097 {
1098 return std::abs(value);
1099 }
1100
1101 template<class t_type>
1102 constexpr typename std::enable_if<IsVec<t_type>::value, t_type>::type
1103 abs(const t_type& value)
1104 {
1105 t_type abs_value;
1106 for (uint01 dim = 0; dim < t_type::NumberOfDimensions(); ++dim)
1107 abs_value[dim] = abs(value[dim]);
1108 return abs_value;
1109 }
1110
1111 template<class t_to, class t_from>
1112 constexpr t_to cast(Vector<1, t_from>& value)
1113 {
1114 return static_cast<t_to>(value[0]);
1115 }
1116
1117 /**--------------------------------------------------------------------------------------------------
1118 Abs the given value.
1119
1120 Author: Tyler Parke
1121
1122 Date: 2017-11-13
1123
1124 Parameters:
1125 value - The value.
1126
1127 \returns An uint01.
1128 **/
1129 template<>
1130 constexpr uint01 abs(const uint01& value)
1131 {
1132 return value;
1133 }
1134
1135 /**--------------------------------------------------------------------------------------------------
1136 Abs the given value.
1137
1138 Author: Tyler Parke
1139
1140 Date: 2017-11-13
1141
1142 Parameters:
1143 value - The value.
1144
1145 \returns An uint02.
1146 **/
1147 template<>
1148 constexpr uint02 abs(const uint02& value)
1149 {
1150 return value;
1151 }
1152
1153 /**--------------------------------------------------------------------------------------------------
1154 Abs the given value.
1155
1156 Author: Tyler Parke
1157
1158 Date: 2017-11-13
1159
1160 Parameters:
1161 value - The value.
1162
1163 \returns An uint04.
1164 **/
1165 template<>
1166 constexpr uint04 abs(const uint04& value)
1167 {
1168 return value;
1169 }
1170
1171
1172 /**--------------------------------------------------------------------------------------------------
1173 Abs the given value.
1174
1175 Author: Tyler Parke
1176
1177 Date: 2017-11-13
1178
1179 Parameters:
1180 value - The value.
1181
1182 \returns An uint08.
1183 **/
1184 template<>
1185 constexpr uint08 abs(const uint08& value)
1186 {
1187 return value;
1188 }
1189
1190
1191 /**--------------------------------------------------------------------------------------------------
1192 Abs the given vector.
1193
1194 Author: Tyler Parke
1195
1196 Date: 2017-11-13
1197
1198 Parameters:
1199 vector - The vector.
1200
1201 \returns A Vector&lt;t_dims,t_type&gt;
1202 **/
1203 template<uint01 t_dims, class t_type>
1205 {
1207 for (uint01 dim = 0; dim < t_dims; ++dim)
1208 value[dim] = abs(vector[dim]);
1209 return value;
1210 }
1211
1212 /**--------------------------------------------------------------------------------------------------
1213 Sqrts the given value.
1214
1215 Author: Tyler Parke
1216
1217 Date: 2017-11-13
1218
1219 Parameters:
1220 value - The value.
1221
1222 \returns A t_type.
1223 **/
1224 template<class t_type>
1225 t_type sqrt(const t_type& value)
1226 {
1227 return ::sqrt(value);
1228 }
1229
1230 /**--------------------------------------------------------------------------------------------------
1231 Sqrts the given vector.
1232
1233 Author: Tyler Parke
1234
1235 Date: 2017-11-13
1236
1237 Parameters:
1238 vector - The vector.
1239
1240 \returns A Vector&lt;t_dims,t_type&gt;
1241 **/
1242 template<uint01 t_dims, class t_type>
1244 {
1246 for (uint01 dim = 0; dim < t_dims; ++dim)
1247 {
1248 vec[dim] = std::sqrt(vector[dim]);
1249 }
1250 return vec;
1251 }
1252
1253 /**--------------------------------------------------------------------------------------------------
1254
1255 Distance squared.
1256
1257 Author: Tyler Parke
1258
1259 Date: 2017-11-13
1260
1261 Parameters:
1262 v1 - The first Vector&lt;t_dims,t_type&gt;
1263 v2 - The second Vector&lt;t_dims,t_type&gt;
1264
1265 \returns A t_type.
1266 **/
1267 template<uint01 t_dims, class t_type>
1269 {
1270 t_type value = 0;
1271 for (uint01 dim = 0; dim < t_dims; ++dim)
1272 {
1273 const t_type dn = (v1[dim] - v2[dim]);
1274 value += dn * dn;
1275 }
1276 return value;
1277 }
1278
1279 /**--------------------------------------------------------------------------------------------------
1280
1281 Distances.
1282
1283 Author: Tyler Parke
1284
1285 Date: 2017-11-13
1286
1287 Parameters:
1288 v1 - The first Vector&lt;t_dims,t_type&gt;
1289 v2 - The second Vector&lt;t_dims,t_type&gt;
1290
1291 \returns A t_type.
1292 **/
1293 template<uint01 t_dims, class t_type>
1295 {
1296 return sqrt(distanceSquared(v1, v2));
1297 }
1298
1299 /**--------------------------------------------------------------------------------------------------
1300
1301 Distances.
1302
1303 Author: Tyler Parke
1304
1305 Date: 2017-11-13
1306
1307 Typeparams:
1308 t_distance_type - Type of the distance type.
1309 t_dims - Type of the dims.
1310 t_type - Type of the type.
1311 Parameters:
1312 v1 - The first Vector&lt;t_dims,t_type&gt;
1313 v2 - The second Vector&lt;t_dims,t_type&gt;
1314
1315 \returns A t_distance_type.
1316 **/
1317 template<class t_distance_type, uint01 t_dims, class t_type>
1318 t_distance_type distance(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
1319 {
1321 }
1322
1323 template <uint01 t_dims, typename t_type>
1324 constexpr Vector<t_dims, t_type> clip(const Vector<t_dims, t_type>& value, const Vector<t_dims, t_type>& lower_bound, const Vector<t_dims, t_type>& upper_bound)
1325 {
1326 Vector<t_dims, t_type> clipped;
1327 for (uint01 i = 0; i < t_dims; i++)
1328 {
1329 clipped[i] = clip(value[i], lower_bound[i], upper_bound[i]);
1330 }
1331 return clipped;
1332 }
1333}
Dummy class to include functions related to vector math.
Definition VectorFunctions.hpp:42
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
Definition ACIColor.h:37
constexpr bool IsInvalid(const t_type &value)
Query if 'value' is valid or invalid. Invalid values should return invalid if used for calculations o...
Definition BaseFunctions.hpp:170
constexpr Vector< t_dims, t_type > operator/=(Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Definition VectorFunctions.hpp:526
bool operator==(const char(&v1)[t_size], const String &v2)
Definition String.h:912
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
Definition BaseFunctions.hpp:94
constexpr std::enable_if<!IsVec< t_type >::value, bool >::type AreSame(const t_type &a, const t_type &b)
Definition VectorFunctions.hpp:591
constexpr std::enable_if< IsVecType< t_vector_type, Angle< fltp08 > >::value, t_vector_type >::type operator*(const t_vector_type &angle, const t_type &mult)
Multiplication operator for a Vector of Angles.
Definition AngleFunctions.h:326
constexpr t_type clip(const t_type &value, const t_type &lower_bound, const t_type &upper_bound)
Clips the value given so that that the returned value falls between upper and lower bound.
Definition BaseFunctions.hpp:207
constexpr bool operator<(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:720
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1030
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Definition Vector.hpp:668
TimeSpan operator-(const Time &time, const Time &value)
constexpr bool operator<=(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:731
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:80
t_type determinate(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:987
String operator+(const String &string_a, const String &string_b)
Definition String.h:827
t_type distanceSquared(const Bounds< t_dims, t_type, t_vertex > &bounds, const Vector< t_dims, t_type > &vertex)
Definition Distance.hpp:46
String & operator+=(String &string, const String &value)
Definition String.h:889
constexpr bool operator>=(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:670
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
Definition BaseValues.hpp:106
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
Definition VectorFunctions.hpp:898
constexpr std::enable_if< IsVecType< t_vector_type, Angle< t_angle_type > >::value, t_vector_type >::type operator/(const t_vector_type &angle, const t_type &den)
Division operator for a Vector of Angles.
Definition AngleFunctions.h:456
constexpr bool operator>(const Vector< vec_1_size, t_type > &v1, const Vector< vec_2_size, t_type > &v2)
Definition VectorFunctions.hpp:708
constexpr RGBColor & operator*=(RGBColor &color, const t_type &value)
Definition RGBColor.h:222
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
t_type sqrt(const t_type &value)
Definition VectorFunctions.hpp:1225
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
constexpr t_type distance(const t_vertex &vertex, const LineSegment< t_dims, t_type, t_vertex > &line)
Definition Distance.hpp:171
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:88
constexpr bool equals(const LineSegment< t_dims, t_type, t_vertex > &left, const LineSegment< t_dims, t_type, t_vertex > &right, const t_type &epsilon=cast< t_type >(0))
Definition Line.hpp:757
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
Definition AngleFunctions.h:645
bool AreParallel(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
Definition VectorFunctions.hpp:1053
Time & operator-=(Time &time, const TimeSpan &value)
constexpr Vector< t_dims, Angle< t_angle_type > > operator%(const Vector< t_dims, Angle< t_angle_type > > &vec_a, const Vector< t_dims, Angle< t_angle_type > > &vec_b)
Definition AngleFunctions.h:617
@ Y
Definition BaseValues.hpp:169
@ X
Definition BaseValues.hpp:167
@ Z
Definition BaseValues.hpp:171
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
Definition BaseFunctions.hpp:56