NDEVR
API Documentation
VectorFunctions.hpp
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{
43 {};
44
58 template<class t_vector_type, uint01 t_dims, class t_type>
59 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, t_type>, t_vector_type>::value, t_vector_type>::type
60 operator+(const t_vector_type& vec_a, const Vector<t_dims, t_type>& vec_b)
61 {
62 t_vector_type sum;
63 for (uint01 dim = 0; dim < t_dims; ++dim)
64 sum[dim] = vec_a[dim] + vec_b[dim];
65 return sum;
66 }
67
82 template<uint01 t_dims, class t_type>
83 constexpr Vector<t_dims, t_type> operator+(const t_type& scaler_a, const Vector<t_dims, t_type>& vec_b)
84 {
86 for (uint01 dim = 0; dim < t_dims; ++dim)
87 sum[dim] = scaler_a + vec_b[dim];
88 return sum;
89 }
90
105 template<class t_vector_type, class t_type>
106 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
107 operator+(const t_vector_type& vec_a, const t_type& scaler_b)
108 {
109 t_vector_type sum;
110 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
111 sum[dim] = vec_a[dim] + scaler_b;
112 return sum;
113 }
114 template<class t_vector_type, class t_type>
115 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
116 operator+(const t_type& scaler_a, const t_vector_type& vec_b)
117 {
118 t_vector_type sum;
119 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
120 sum[dim] = scaler_a + vec_b[dim];
121 return sum;
122 }
123
138 template<uint01 t_dims, class t_type>
140 {
141 for (uint01 dim = 0; dim < t_dims; ++dim)
142 vec_a[dim] += vec_b[dim];
143 return vec_a;
144 }
145
160 template<uint01 t_dims, class t_type>
161 constexpr Vector<t_dims, t_type>& operator+=(Vector<t_dims, t_type>& vec_a, t_type scaler_b)
162 {
163 for (uint01 dim = 0; dim < t_dims; ++dim)
164 vec_a[dim] += scaler_b;
165 return vec_a;
166 }
167
182 template<class t_vector_type, uint01 t_dims, class t_type>
183 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, t_type>, t_vector_type>::value, t_vector_type>::type
184 operator-(const t_vector_type& vec_a, const Vector<t_dims, t_type>& vec_b)
185 {
186 t_vector_type difference;
187 for (uint01 dim = 0; dim < t_dims; ++dim)
188 difference[dim] = vec_a[dim] - vec_b[dim];
189 return difference;
190 }
191
206 template<uint01 t_dims, class t_type>
207 constexpr Vector<t_dims, t_type> operator-(const t_type& value_a, const Vector<t_dims, t_type>& vec_b)
208 {
210 for (uint01 dim = 0; dim < t_dims; ++dim)
211 difference[dim] = value_a - vec_b[dim];
212 return difference;
213 }
214
229 template<class t_vector_type, class t_type>
230 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
231 operator-(const t_vector_type& vec_a, const t_type& value_b)
232 {
233 t_vector_type difference;
234 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
235 difference[dim] = vec_a[dim] - value_b;
236 return difference;
237 }
238
253 template<uint01 t_dims, class t_type>
255 {
256 for (uint01 dim = 0; dim < t_dims; ++dim)
257 vec_a[dim] -= vec_b[dim];
258 return vec_a;
259 }
260
275 template<uint01 t_dims, class t_type>
277 {
278 for (uint01 dim = 0; dim < t_dims; ++dim)
279 vec_a[dim] -= value_b;
280 return vec_a;
281 }
282
297 template<uint01 t_dims, class t_type>
299 {
301 for (uint01 dim = 0; dim < t_dims; ++dim)
302 product[dim] = vec_a[dim] * vec_b[dim];
303 return product;
304 }
305
320 template<class t_vector_type, class t_type>
321 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
322 operator*(const t_type& value_a, const t_vector_type& vec_b)
323 {
324 t_vector_type product;
325 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
326 product[dim] = value_a * vec_b[dim];
327 return product;
328 }
329
344 template<class t_vector_type, class t_type>
345 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
346 operator*(const t_vector_type& vec_a, const t_type& value_b)
347 {
348 t_vector_type product;
349 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
350 product[dim] = vec_a[dim] * value_b;
351 return product;
352 }
353
368 template<uint01 t_dims, class t_type>
370 {
371 for (uint01 dim = 0; dim < t_dims; ++dim)
372 vec_a[dim] *= vec_b[dim];
373 return vec_a;
374 }
375
390 template<uint01 t_dims, class t_type>
392 {
393 for (uint01 dim = 0; dim < t_dims; ++dim)
394 vec_a[dim] *= value_b;
395 return vec_a;
396 }
397
412 template<uint01 t_dims, class t_type>
414 {
415 Vector<t_dims, t_type> quotient;
416 for (uint01 dim = 0; dim < t_dims; ++dim)
417 quotient[dim] = vec_a[dim] / vec_b[dim];
418 return quotient;
419 }
420
435 template<class t_vector_type, class t_type>
436 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
437 operator/(const t_type& value_a, const t_vector_type& vec_b)
438 {
439 t_vector_type quotient;
440 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
441 quotient[dim] = value_a / vec_b[dim];
442 return quotient;
443 }
444
459 template<class t_vector_type, class t_type>
460 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>::type
461 operator/(const t_vector_type& vec_a, const t_type& value_b)
462 {
463 t_vector_type quotient;
464 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
465 quotient[dim] = vec_a[dim] / value_b;
466 return quotient;
467 }
468
469
484 /*template<uint01 t_dims, class t_type>
485 constexpr Vector<t_dims, t_type> operator^(const Vector<t_dims, t_type>& vec_a, const Vector<t_dims, t_type>& vec_b)
486 {
487 Vector<t_dims, t_type> xor;
488 for (uint01 dim = 0; dim < t_dims; ++dim)
489 xor[dim] = vec_a[dim] ^ vec_b[dim];
490 return xor;
491 }*/
492
493
494 template<uint01 t_dims, class t_type>
496 {
498 for (uint01 dim = 0; dim < t_dims; ++dim)
499 mod [dim] = std::fmod(vec_a[dim], vec_b[dim]);
500 return mod;
501 }
502 template<uint01 t_dims, class t_type>
503 constexpr Vector<t_dims, t_type> operator%(const Vector<t_dims, t_type>& vec_a, const t_type& value_b)
504 {
505 Vector<t_dims, t_type> mod;
506 for (uint01 dim = 0; dim < t_dims; ++dim)
507 mod[dim] = cast<t_type>(::fmod(vec_a[dim], value_b));
508 return mod;
509 }
510
511
526 template<uint01 t_dims, class t_type>
528 {
529 for (uint01 dim = 0; dim < t_dims; ++dim)
530 vec_a[dim] = vec_a[dim] / vec_b[dim];
531 return vec_a;
532 }
533
534
549 template<uint01 t_dims, class t_type>
551 {
552 for (uint01 dim = 0; dim < t_dims; ++dim)
553 vec_a[dim] = vec_a[dim] / value_b;
554 return vec_a;
555 }
556
557 template<class t_vector_type, class t_type>
558 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
559 operator==(const t_vector_type& v, const t_type& s)
560 {
561 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
562 {
563 if (v[dim] != s)
564 return false;
565 }
566 return true;
567 }
568 template<class t_vector_type, class t_type>
569 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
570 operator==(const t_type& s, const t_vector_type& v)
571 {
572 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
573 {
574 if (v[dim] != s)
575 return false;
576 }
577 return true;
578 }
579 template<class t_vector_type>
580 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
581 operator==(const t_vector_type& v_a, const t_vector_type& v_b)
582 {
583 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
584 {
585 if (v_a[dim] != v_b[dim])
586 return false;
587 }
588 return true;
589 }
590 template<class t_type>
591 constexpr typename std::enable_if<!IsVec<t_type>::value, bool>::type
592 AreSame(const t_type& a, const t_type& b)
593 {
594 return (a == b) || (IsInvalid(a) && IsInvalid(b));
595 }
596 template<class t_type>
597 constexpr typename std::enable_if<!IsVec<t_type>::value, bool>::type
598 AreSame(const t_type& a, const t_type& b, const t_type& epsilon)
599 {
600 return (IsInvalid(a) && IsInvalid(b))
601 || ::abs(a - b) < epsilon;
602 }
603 //Equal but with nans
604 template<class t_vector_type>
605 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
606 AreSame(const t_vector_type& v_a, const t_vector_type& v_b)
607 {
608 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
609 {
610 if (!AreSame(v_a[dim], v_b[dim]))
611 return false;
612 }
613 return true;
614 }
615 template<class t_vector_type, class t_type>
616 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
617 AreSame(const t_vector_type& v_a, const t_vector_type& v_b, const t_type& epsilon)
618 {
619 return (IsInvalid(v_a) && IsInvalid(v_b))
620 || abs(v_a - v_b) < epsilon;
621 }
622 template<class t_vector_type>
623 constexpr typename std::enable_if<IsVec<t_vector_type>::value, bool>::type
624 operator!=(const t_vector_type& v_a, const t_vector_type& v_b)
625 {
626 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
627 {
628 if (v_a[dim] != v_b[dim])
629 return true;
630 }
631 return false;
632 }
633 template<class t_vector_type, class t_type>
634 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
635 operator!=(const t_vector_type& v, const t_type& s)
636 {
637 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
638 {
639 if (v[dim] != s)
640 return true;
641 }
642 return false;
643 }
644 template<class t_vector_type, class t_type>
645 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
646 operator!=(const t_type& s, const t_vector_type& v)
647 {
648 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
649 {
650 if (v[dim] != s)
651 return true;
652 }
653 return false;
654 }
655
670 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
672 {
673 const uint01 min_val = getMin(vec_1_size, vec_2_size);
674 for (uint01 dim = 0; dim < min_val; ++dim)
675 {
676 if (!(v1[dim] >= v2[dim]))
677 return false;
678 }
679 return true;
680 }
681
682 template<uint01 t_dims, class t_type>
683 constexpr bool operator>=(const Vector<t_dims, t_type>& v1, const t_type& s)
684 {
685 for (uint01 dim = 0; dim < t_dims; ++dim)
686 {
687 if (!(v1[dim] >= s))
688 return false;
689 }
690 return true;
691 }
692
693
708 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
710 {
711 const uint01 min_val = getMin(vec_1_size, vec_2_size);
712 for (uint01 dim = 0; dim < min_val; ++dim)
713 {
714 if (!(v1[dim] > v2[dim]))
715 return false;
716 }
717 return true;
718 }
719
720 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
721 constexpr bool operator<(const Vector<vec_1_size, t_type>& v1, const Vector<vec_2_size, t_type>& v2)
722 {
723 const t_type min_val = getMin(vec_1_size, vec_2_size);
724 for (uint01 dim = 0; dim < min_val; ++dim)
725 {
726 if (!(v1[dim] < v2[dim]))
727 return false;
728 }
729 return true;
730 }
731 template<uint01 vec_1_size, uint01 vec_2_size, class t_type>
732 constexpr bool operator<=(const Vector<vec_1_size, t_type>& v1, const Vector<vec_2_size, t_type>& v2)
733 {
734 const uint01 min_val = getMin(vec_1_size, vec_2_size);
735 for (uint01 dim = 0; dim < min_val; ++dim)
736 {
737 if (!(v1[dim] <= v2[dim]))
738 return false;
739 }
740 return true;
741 }
742
756 template<uint01 t_dims, class t_type>
757 constexpr bool operator>=(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
758 {
759 for (uint01 dim = 0; dim < t_dims; ++dim)
760 {
761 if (!(v1[dim] >= v2[dim]))
762 return false;
763 }
764 return true;
765 }
766
767
768
782 template<uint01 t_dims, class t_type>
783 constexpr bool operator>(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
784 {
785 for (uint01 dim = 0; dim < t_dims; dim++)
786 {
787 if (!(v1[dim] > v2[dim]))
788 return false;
789 }
790 return true;
791 }
792
793 template<uint01 t_dims, class t_type>
794 constexpr bool operator<(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
795 {
796 for (uint01 dim = 0; dim < t_dims; dim++)
797 {
798 if (!(v1[dim] < v2[dim]))
799 return false;
800 }
801 return true;
802 }
803
804 template<class t_vector_type, class t_type>
805 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
806 operator<(const t_vector_type& v, const t_type& s)
807 {
808 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
809 {
810 if (!(v[dim] < s))
811 return false;
812 }
813 return true;
814 }
815 template<class t_vector_type, class t_type>
816 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
817 operator<(const t_type& s, const t_vector_type& v)
818 {
819 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
820 {
821 if (!(s < v[dim]))
822 return false;
823 }
824 return true;
825 }
826 template<class t_vector_type, class t_type>
827 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
828 operator<=(const t_type& s, const t_vector_type& v)
829 {
830 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
831 {
832 if (!(s <= v[dim]))
833 return false;
834 }
835 return true;
836 }
837
838 template<class t_vector_type, class t_type>
839 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
840 operator<=(const t_vector_type& v, const t_type& s)
841 {
842 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
843 {
844 if (!(v[dim] <= s))
845 return false;
846 }
847 return true;
848 }
849 template<class t_vector_type, class t_type>
850 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
851 operator>(const t_vector_type& v, const t_type& s)
852 {
853 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
854 {
855 if (!(v[dim] > s))
856 return false;
857 }
858 return true;
859 }
860 template<class t_vector_type, class t_type>
861 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, bool>::type
862 operator>(const t_type& s, const t_vector_type& v)
863 {
864 for (uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
865 {
866 if (!(s > v[dim]))
867 return false;
868 }
869 return true;
870 }
871
872 template<uint01 t_dims, class t_type>
873 constexpr bool operator<=(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
874 {
875 for (uint01 dim = 0; dim < t_dims; dim++)
876 {
877 if (!(v1[dim] <= v2[dim]))
878 return false;
879 }
880 return true;
881 }
882
883
898 template<class t_type>
900 {
901 return Vector<1, t_type>(1);
902 }
903 template<class t_type>
904 constexpr t_type cross(const Vector<2, t_type>& v1, const Vector<2, t_type>& v2)
905 {
906 return v1[X] * v2[Y] - v1[Y] * v2[X];
907 }
908 template<class t_type>
909 constexpr Vector<2, t_type> cross(const Vector<2, t_type>& v1, const t_type& v2)
910 {
911 return Vector<2, t_type>(v2 * v1[Y], -v2 * v1[X]);
912 }
913 template<class t_type>
914 constexpr Vector<3, t_type> cross(const Vector<3, t_type>& v1, const Vector<3, t_type>& v2)
915 {
917 cross[X] = ((v1[Y] * v2[Z]) - (v1[Z] * v2[Y]));
918 cross[Y] = ((v1[Z] * v2[X]) - (v1[X] * v2[Z]));
919 cross[Z] = ((v1[X] * v2[Y]) - (v1[Y] * v2[X]));
920 return cross;
921 }
922
937 template<uint01 t_dims, class t_type>
939 {
941 for (uint01 dim = 0; dim < t_dims; dim++)
942 {
943 vec[dim] = getMax(v1[dim], v2[dim]);
944 }
945 return vec;
946 }
947
962 template<uint01 t_dims, class t_type>
964 {
966 for (uint01 dim = 0; dim < t_dims; dim++)
967 {
968 vec[dim] = getMin(v1[dim], v2[dim]);
969 }
970 return vec;
971 }
972
987 template<uint01 t_dims, class t_type>
989 {
990 return (v1[X] * v2[Y]) - (v1[Y] * v2[X]);
991 }
992
1008 template<uint01 t_dims, class t_type>
1010 {
1011 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]));
1012 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]));
1013 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]));
1014 return x_det - y_det + z_det;
1015 }
1016
1030 template<uint01 t_dims, class t_type>
1032 {
1033 t_type value = 0;
1034 for (uint01 dim = 0; dim < t_dims; ++dim)
1035 value += v1[dim] * v2[dim];
1036 return value;
1037 }
1038
1053 template<uint01 t_dims, class t_type>
1055 {
1056 t_type magnitude_1 = v1.getMagnitudeSquared();
1057 t_type magnitude_2 = v2.getMagnitudeSquared();
1058 return v2 * v2 * (magnitude_1) == v1 * v1 * magnitude_2;
1059 }
1060
1076 template<uint01 t_dims, class t_type>
1077 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))
1078 {
1079 return (abs(left - right) < epsilon);
1080 }
1081
1086 template<class t_type>
1087 constexpr typename std::enable_if<!IsVec<t_type>::value, t_type>::type
1088 abs(const t_type& value)
1089 {
1090 return std::abs(value);
1091 }
1092
1097 template<class t_type>
1098 constexpr typename std::enable_if<IsVec<t_type>::value, t_type>::type
1099 abs(const t_type& value)
1100 {
1101 t_type abs_value;
1102 for (uint01 dim = 0; dim < t_type::NumberOfDimensions(); ++dim)
1103 abs_value[dim] = abs(value[dim]);
1104 return abs_value;
1105 }
1106
1107 template<class t_to, class t_from>
1108 constexpr t_to cast(Vector<1, t_from>& value)
1109 {
1110 return static_cast<t_to>(value[0]);
1111 }
1112
1117 template<>
1118 constexpr uint01 abs(const uint01& value)
1119 {
1120 return value;
1121 }
1122
1127 template<>
1128 constexpr uint02 abs(const uint02& value)
1129 {
1130 return value;
1131 }
1132
1137 template<>
1138 constexpr uint04 abs(const uint04& value)
1139 {
1140 return value;
1141 }
1142
1143
1148 template<>
1149 constexpr uint08 abs(const uint08& value)
1150 {
1151 return value;
1152 }
1153
1154
1159 template<uint01 t_dims, class t_type>
1161 {
1163 for (uint01 dim = 0; dim < t_dims; ++dim)
1164 value[dim] = abs(vector[dim]);
1165 return value;
1166 }
1167
1180 template<class t_type>
1181 t_type sqrt(const t_type& value)
1182 {
1183 return ::sqrt(value);
1184 }
1185
1198 template<uint01 t_dims, class t_type>
1200 {
1202 for (uint01 dim = 0; dim < t_dims; ++dim)
1203 {
1204 vec[dim] = std::sqrt(vector[dim]);
1205 }
1206 return vec;
1207 }
1208
1223 template<uint01 t_dims, class t_type>
1224 t_type distanceSquared(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
1225 {
1226 t_type value = 0;
1227 for (uint01 dim = 0; dim < t_dims; ++dim)
1228 {
1229 const t_type dn = (v1[dim] - v2[dim]);
1230 value += dn * dn;
1231 }
1232 return value;
1233 }
1234
1249 template<uint01 t_dims, class t_type>
1250 t_type distance(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
1251 {
1252 return sqrt(distanceSquared(v1, v2));
1253 }
1254
1273 template<class t_distance_type, uint01 t_dims, class t_type>
1274 t_distance_type distance(const Vector<t_dims, t_type>& v1, const Vector<t_dims, t_type>& v2)
1275 {
1276 return sqrt(cast<t_distance_type>(distanceSquared(v1, v2)));
1277 }
1278
1279 template <uint01 t_dims, typename t_type>
1280 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)
1281 {
1282 Vector<t_dims, t_type> clipped;
1283 for (uint01 i = 0; i < t_dims; i++)
1284 {
1285 clipped[i] = clip(value[i], lower_bound[i], upper_bound[i]);
1286 }
1287 return clipped;
1288 }
1289}
Provides free functions for vector arithmetic and geometric operations.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
The primary namespace for the NDEVR SDK.
static constexpr Angle< t_angle_type > & operator-=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &sub)
Subtraction assignment operator for Angles.
@ type
The type identifier string for this model node.
Definition Model.h:58
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Inequality operator.
Definition Vector.hpp:673
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...
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 > ...
t_type determinate(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
static constexpr bool operator<=(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Less-than-or-equal comparison operator.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool operator>=(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Greater-than-or-equal comparison operator.
static constexpr Angle< t_type > operator*(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Multiplication operator.
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
static constexpr Angle< t_type > operator-(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Subtraction operator.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr Angle< t_angle_type > & operator+=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &add)
Addition assignment operator for Angles.
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
Definition Angle.h:388
static constexpr Angle< t_angle_type > & operator/=(Angle< t_angle_type > &angle, const t_type &mult)
Division assignment operator for an Angle and a scalar.
static constexpr bool operator<(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Less-than comparison operator.
static constexpr Angle< t_type > difference(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Calculates minimal absolute signed angle between two angles.
static constexpr Angle< t_angle_type > & operator*=(Angle< t_angle_type > &angle, const t_type &mult)
Multiplication assignment operator for an Angle and a scalar.
bool AreParallel(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
static constexpr Angle< t_type > operator+(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Addition operator.
t_type sqrt(const t_type &value)
static constexpr fltp08 operator/(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Division operator.
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))
Tests if objects are considered equal.
Definition Line.hpp:791
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)
Element-wise modulo operator for two Vectors of Angles.
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.
static constexpr bool operator>(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Greater-than comparison operator.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408