Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
vecg.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2000-2022 Inria
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * * Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * * Neither the name of the ALICE Project-Team nor the names of its
14 * contributors may be used to endorse or promote products derived from this
15 * software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contact: Bruno Levy
30 *
31 * https://www.inria.fr/fr/bruno-levy
32 *
33 * Inria,
34 * Domaine de Voluceau,
35 * 78150 Le Chesnay - Rocquencourt
36 * FRANCE
37 *
38 */
39
40#ifndef GEOGRAM_BASIC_VECG
41#define GEOGRAM_BASIC_VECG
42
48#include <initializer_list>
49
50#include <iostream>
51#include <cfloat>
52#include <cmath>
53
54#ifndef GOMGEN
55#include <type_traits>
56#endif
57
63namespace GEO {
64
73 template <index_t DIM, class T>
74 class vecng {
75 public:
77 static constexpr index_t dim = DIM;
78
81
83 typedef T value_type;
84
90 for(index_t i = 0; i < DIM; i++) {
91 data_[i] = T(0);
92 }
93 }
94
95 // This one should never be called :
96 // a template constructor cannot be a copy constructor
97
107 template <class T2>
108 explicit vecng(const vecng<DIM, T2>& v) {
109 for(index_t i = 0; i < DIM; i++) {
110 data_[i] = T(v[i]);
111 }
112 }
113
114 // to avoid compilation problems
115 template <class T2, index_t DIM2>
116 explicit vecng(
117 const vecng<DIM2, T2>& v
118 ) {
119 geo_debug_assert(DIM2 == DIM);
120 for(index_t i = 0; i < DIM; i++) {
121 data_[i] = T(v[i]);
122 }
123 }
124
133 template <class T2>
134 explicit vecng(const T2* v) {
135 for(index_t i = 0; i < DIM; i++) {
136 data_[i] = T(v[i]);
137 }
138 }
139
144 vecng(const std::initializer_list<T>& Vi) {
145 index_t i = 0;
146 for(auto& it: Vi) {
147 geo_debug_assert(i < DIM);
148 data()[i] = it;
149 ++i;
150 }
151 }
152
158 return DIM;
159 }
160
165 T* data() {
166 return data_;
167 }
168
173 const T* data() const {
174 return data_;
175 }
176
182 inline T& operator[] (index_t i) {
183 geo_debug_assert(i < DIM);
184 return data()[i];
185 }
186
192 inline const T& operator[] (index_t i) const {
193 geo_debug_assert(i < DIM);
194 return data()[i];
195 }
196
200 inline T length2() const {
201 T result = T(0);
202 for(index_t i = 0; i < DIM; i++) {
203 result += data_[i] * data_[i];
204 }
205 return result;
206 }
207
211 inline T length() const {
212 return sqrt(length2());
213 }
214
220 inline T distance2(const vector_type& v) const {
221 T result(0);
222 for(index_t i = 0; i < DIM; i++) {
223 result += geo_sqr(v.data_[i] - data_[i]);
224 }
225 return result;
226 }
227
233 inline T distance(const vector_type& v) const {
234 return sqrt(distance2(v));
235 }
236
237 // operators
238
247 for(index_t i = 0; i < DIM; i++) {
248 data_[i] += v.data_[i];
249 }
250 return *this;
251 }
252
261 for(index_t i = 0; i < DIM; i++) {
262 data_[i] -= v.data_[i];
263 }
264 return *this;
265 }
266
276 template <class T2>
277 inline vector_type& operator*= (T2 s) {
278 for(index_t i = 0; i < DIM; i++) {
279 data_[i] *= T(s);
280 }
281 return *this;
282 }
283
293 template <class T2>
294 inline vector_type& operator/= (T2 s) {
295 for(index_t i = 0; i < DIM; i++) {
296 data_[i] /= T(s);
297 }
298 return *this;
299 }
300
308 inline vector_type operator+ (const vector_type& v) const {
309 vector_type result(*this);
310 for(index_t i = 0; i < DIM; i++) {
311 result.data_[i] += v.data_[i];
312 }
313 return result;
314 }
315
323 inline vector_type operator- (const vector_type& v) const {
324 vector_type result(*this);
325 for(index_t i = 0; i < DIM; i++) {
326 result.data_[i] -= v.data_[i];
327 }
328 return result;
329 }
330
331
341 template <class T2>
342 inline vector_type operator/ (T2 s) const {
343 vector_type result(*this);
344 for(index_t i = 0; i < DIM; i++) {
345 result.data_[i] /= T(s);
346 }
347 return result;
348 }
349
355 inline vector_type operator- () const {
356 vector_type result;
357 for(index_t i = 0; i < DIM; i++) {
358 result.data_[i] = -data_[i];
359 }
360 return result;
361 }
362
363 private:
364 T data_[DIM];
365 };
366
374 template <index_t DIM, class T>
375 inline T dot(
376 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
377 ) {
378 T result = 0;
379 for(index_t i = 0; i < DIM; i++) {
380 result += v1[i] * v2[i];
381 }
382 return result;
383 }
384
385#ifndef GOMGEN
397 template <
398 class T2, index_t DIM, class T,
399 typename = std::enable_if_t<is_scalar<T2>::value>
401 T2 s, const vecng<DIM, T>& v
402 ) {
403 vecng<DIM, T> result;
404 for(index_t i = 0; i < DIM; i++) {
405 result[i] = T(s) * v[i];
406 }
407 return result;
408 }
409
410
422 template <
423 class T2, index_t DIM, class T,
424 typename = std::enable_if_t<is_scalar<T2>::value>
426 const vecng<DIM, T>& v, T2 s
427 ) {
428 vecng<DIM, T> result;
429 for(index_t i = 0; i < DIM; i++) {
430 result[i] = T(s) * v[i];
431 }
432 return result;
433 }
434#endif
435
436 // Compatibility with GLSL
437
445 template <index_t DIM, class T>
446 inline T length(const vecng<DIM, T>& v) {
447 return v.length();
448 }
449
457 template <index_t DIM, class T>
458 inline T length2(const vecng<DIM, T>& v) {
459 return v.length2();
460 }
461
470 template <index_t DIM, class T>
471 inline T distance2(
472 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
473 ) {
474 return v2.distance2(v1);
475 }
476
485 template <index_t DIM, class T>
486 inline T distance(
487 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
488 ) {
489 return v2.distance(v1);
490 }
491
501 template <index_t DIM, class T> GEO_NODISCARD
503 const vecng<DIM, T>& v
504 ) {
505 T s = length(v);
506 if(s > 1e-30) {
507 s = T(1) / s;
508 }
509 return s * v;
510 }
511
522 template <index_t DIM, class T>
524 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2, T s
525 ) {
526 return (T(1) - s) * v1 + s * v2;
527 }
528
529 /************************************************************************/
530
535 template <class T>
536 class vecng<2, T> {
537 public:
539 static constexpr index_t dim = 2;
540
543
545 typedef T value_type;
546
549 x(0),
550 y(0) {
551 }
552
557 vecng(const T& x_in, const T& y_in) :
558 x(x_in),
559 y(y_in) {
560 }
561
566 vecng(T&& x_in, T&& y_in) :
567 x(x_in),
568 y(y_in) {
569 }
570
571 vecng(const vecng<2,T>& rhs) = default;
572 vecng(vecng<2,T>&& rhs) = default;
573
575 template <class T2>
576 explicit vecng(const vecng<dim, T2>& v) :
577 x(v.x),
578 y(v.y) {
579 }
580
582 template <class T2>
583 explicit vecng(const T2* v) :
584 x(v[0]),
585 y(v[1]) {
586 }
587
589 vecng(const std::initializer_list<T>& Vi) {
590 index_t i = 0;
591 for(auto& it: Vi) {
593 data()[i] = it;
594 ++i;
595 }
596 }
597
598 vecng<2,T>& operator=(const vecng<2,T>& rhs) = default;
599 vecng<2,T>& operator=(vecng<2,T>&& rhs) = default;
600
602 inline T length2() const {
603 return x * x + y * y;
604 }
605
607 inline T length() const {
608 return sqrt(x * x + y * y);
609 }
610
612 inline T distance2(const vector_type& v) const {
613 T dx = v.x - x;
614 T dy = v.y - y;
615 return dx * dx + dy * dy;
616 }
617
619 inline T distance(const vector_type& v) const {
620 return sqrt(distance2(v));
621 }
622
625 x += v.x;
626 y += v.y;
627 return *this;
628 }
629
632 x -= v.x;
633 y -= v.y;
634 return *this;
635 }
636
638 template <class T2>
639 inline vector_type& operator*= (T2 s) {
640 x *= T(s);
641 y *= T(s);
642 return *this;
643 }
644
646 template <class T2>
647 inline vector_type& operator/= (T2 s) {
648 x /= T(s);
649 y /= T(s);
650 return *this;
651 }
652
654 inline vector_type operator+ (const vector_type& v) const {
655 return vector_type(x + v.x, y + v.y);
656 }
657
659 inline vector_type operator- (const vector_type& v) const {
660 return vector_type(x - v.x, y - v.y);
661 }
662
664 template <class T2>
665 inline vector_type operator/ (T2 s) const {
666 return vector_type(x / T(s), y / T(s));
667 }
668
670 inline vector_type operator- () const {
671 return vector_type(-x, -y);
672 }
673
676 return dim;
677 }
678
680 T* data() {
681 return &x;
682 }
683
685 const T* data() const {
686 return &x;
687 }
688
690 inline T& operator[] (index_t i) {
692 return data()[i];
693 }
694
696 inline const T& operator[] (index_t i) const {
698 return data()[i];
699 }
700
706
708 T x;
710 T y;
711 };
712
717 template <class T>
718 inline T dot(
719 const vecng<2, T>& v1, const vecng<2, T>& v2
720 ) {
721 return v1.x * v2.x + v1.y * v2.y;
722 }
723
731 template <class T>
732 inline T det(
733 const vecng<2, T>& v1, const vecng<2, T>& v2
734 ) {
735 return v1.x * v2.y - v1.y * v2.x;
736 }
737
738#ifndef GOMGEN
743 template <
744 class T2, class T,
745 typename = std::enable_if_t<is_scalar<T2>::value>
747 T2 s, const vecng<2, T>& v
748 ) {
749 return vecng<2, T>(T(s) * v.x, T(s) * v.y);
750 }
751
756 template <
757 class T2, class T,
758 typename = std::enable_if_t<is_scalar<T2>::value>
760 const vecng<2, T>& v, T2 s
761 ) {
762 return vecng<2, T>(T(s) * v.x, T(s) * v.y);
763 }
764#endif
765
766 /************************************************************************/
767
772 template <class T>
773 class vecng<3, T> {
774 public:
776 static constexpr index_t dim = 3;
777
780
782 typedef T value_type;
783
786 x(T(0.0)),
787 y(T(0.0)),
788 z(T(0.0)) {
789 }
790
795 vecng(const T& x_in, const T& y_in, const T& z_in) :
796 x(x_in),
797 y(y_in),
798 z(z_in) {
799 }
800
805 vecng(T&& x_in, T&& y_in, T&& z_in) :
806 x(x_in),
807 y(y_in),
808 z(z_in) {
809 }
810
811 vecng(const vecng<3,T>& rhs) = default;
812 vecng(vecng<3,T>&& rhs) = default;
813
815 template <class T2>
816 explicit vecng(const vecng<dim, T2>& v) :
817 x(v.x),
818 y(v.y),
819 z(v.z) {
820 }
821
823 template <class T2>
824 explicit vecng(const T2* v) :
825 x(v[0]),
826 y(v[1]),
827 z(v[2]) {
828 }
829
831 vecng(const std::initializer_list<T>& Vi) {
832 index_t i = 0;
833 for(auto& it: Vi) {
835 data()[i] = it;
836 ++i;
837 }
838 }
839
840 vecng<3,T>& operator=(const vecng<3,T>& rhs) = default;
841 vecng<3,T>& operator=(vecng<3,T>&& rhs) = default;
842
846 template<typename A, typename B>
847 vecng(const vecng<2, A>& _xy, B _z);
851 template<typename A, typename B>
852 vecng(const vecng<2, A>& _xy, const vecng<1, B>& _z);
856 template<typename A, typename B>
857 vecng(A _x, const vecng<2, B>& _yz);
861 template<typename A, typename B>
862 vecng(const vecng<1, A>& _x, const vecng<2, B>& _yz);
866 template<typename U>
867 explicit vecng(vecng<4, U> const& v);
868
869
871 inline T length2() const {
872 return x * x + y * y + z * z;
873 }
874
876 inline T length() const {
877 return sqrt(x * x + y * y + z * z);
878 }
879
881 inline T distance2(const vector_type& v) const {
882 T dx = v.x - x;
883 T dy = v.y - y;
884 T dz = v.z - z;
885 return dx * dx + dy * dy + dz * dz;
886 }
887
889 inline T distance(const vector_type& v) const {
890 return sqrt(distance2(v));
891 }
892
895 x += v.x;
896 y += v.y;
897 z += v.z;
898 return *this;
899 }
900
903 x -= v.x;
904 y -= v.y;
905 z -= v.z;
906 return *this;
907 }
908
910 template <class T2>
911 inline vector_type& operator*= (T2 s) {
912 x *= T(s);
913 y *= T(s);
914 z *= T(s);
915 return *this;
916 }
917
919 template <class T2>
920 inline vector_type& operator/= (T2 s) {
921 x /= T(s);
922 y /= T(s);
923 z /= T(s);
924 return *this;
925 }
926
928 inline vector_type operator+ (const vector_type& v) const {
929 return vector_type(x + v.x, y + v.y, z + v.z);
930 }
931
933 inline vector_type operator- (const vector_type& v) const {
934 return vector_type(x - v.x, y - v.y, z - v.z);
935 }
936
938 template <class T2>
939 inline vector_type operator/ (T2 s) const {
940 return vector_type(x / T(s), y / T(s), z / T(s));
941 }
942
944 inline vector_type operator- () const {
945 return vector_type(-x, -y, -z);
946 }
947
950 return dim;
951 }
952
954 T* data() {
955 return &x;
956 }
957
959 const T* data() const {
960 return &x;
961 }
962
964 inline T& operator[] (index_t i) {
966 return data()[i];
967 }
968
970 inline const T& operator[] (index_t i) const {
972 return data()[i];
973 }
974
981
983 T x;
985 T y;
987 T z;
988 };
989
994 template <class T>
995 inline T dot(
996 const vecng<3, T>& v1, const vecng<3, T>& v2
997 ) {
998 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
999 }
1000
1008 template <class T>
1010 const vecng<3, T>& v1, const vecng<3, T>& v2
1011 ) {
1012 return vecng<3, T>(
1013 det2x2(v1.y, v2.y, v1.z, v2.z),
1014 det2x2(v1.z, v2.z, v1.x, v2.x),
1015 det2x2(v1.x, v2.x, v1.y, v2.y)
1016 );
1017 }
1018
1019#ifndef GOMGEN
1024 template <
1025 class T2, class T,
1026 typename = std::enable_if_t<is_scalar<T2>::value>
1028 T2 s, const vecng<3, T>& v
1029 ) {
1030 return vecng<3, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z);
1031 }
1032
1037 template <
1038 class T2, class T,
1039 typename = std::enable_if_t<is_scalar<T2>::value>
1041 const vecng<3, T>& v, T2 s
1042 ) {
1043 return vecng<3, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z);
1044 }
1045
1046#endif
1047
1048 /************************************************************************/
1049
1054 template <class T>
1055 class vecng<4, T> {
1056 public:
1058 static constexpr index_t dim = 4;
1059
1062
1064 typedef T value_type;
1065
1068 x(0),
1069 y(0),
1070 z(0),
1071 w(0) {
1072 }
1073
1078 vecng(const T& x_in, const T& y_in, const T& z_in, const T& w_in) :
1079 x(x_in),
1080 y(y_in),
1081 z(z_in),
1082 w(w_in) {
1083 }
1084
1089 vecng(T&& x_in, T&& y_in, T&& z_in, T&& w_in) :
1090 x(x_in),
1091 y(y_in),
1092 z(z_in),
1093 w(w_in) {
1094 }
1095
1096 vecng(const vecng<4,T>& rhs) = default;
1097 vecng(vecng<4,T>&& rhs) = default;
1098
1100 template <class T2>
1101 explicit vecng(const vecng<dim, T2>& v) :
1102 x(v.x),
1103 y(v.y),
1104 z(v.z),
1105 w(v.w) {
1106 }
1107
1109 template <class T2>
1110 explicit vecng(const T2* v) :
1111 x(v[0]),
1112 y(v[1]),
1113 z(v[2]),
1114 w(v[3]) {
1115 }
1116
1118 vecng(const std::initializer_list<T>& Vi) {
1119 index_t i = 0;
1120 for(auto& it: Vi) {
1121 geo_debug_assert(i < dim);
1122 data()[i] = it;
1123 ++i;
1124 }
1125 }
1126
1127 vecng<4,T>& operator=(const vecng<4,T>& rhs) = default;
1128 vecng<4,T>& operator=(vecng<4,T>&& rhs) = default;
1129
1130 // -- Conversion scalar constructors --
1131
1132 template<typename U>
1133 explicit vecng(vecng<1, U> const& v);
1134
1135 template<typename X, typename Y, typename Z, typename W>
1136 vecng(X _x, Y _y, Z _z, W _w);
1137 template<typename X, typename Y, typename Z, typename W>
1138 vecng(const vecng<1, X>& _x, Y _y, Z _z, W _w);
1139 template<typename X, typename Y, typename Z, typename W>
1140 vecng(X _x, const vecng<1, Y>& _y, Z _z, W _w);
1141 template<typename X, typename Y, typename Z, typename W>
1142 vecng(const vecng<1, X>& _x, const vecng<1, Y>& _y, Z _z, W _w);
1143 template<typename X, typename Y, typename Z, typename W>
1144 vecng(X _x, Y _y, const vecng<1, Z>& _z, W _w);
1145 template<typename X, typename Y, typename Z, typename W>
1146 vecng(const vecng<1, X>& _x, Y _y, const vecng<1, Z>& _z, W _w);
1147 template<typename X, typename Y, typename Z, typename W>
1148 vecng(X _x, const vecng<1, Y>& _y, const vecng<1, Z>& _z, W _w);
1149 template<typename X, typename Y, typename Z, typename W>
1150 vecng(
1151 const vecng<1, X>& _x, const vecng<1, Y>& _y,
1152 const vecng<1, Z>& _z, W _w
1153 );
1154 template<typename X, typename Y, typename Z, typename W>
1155 vecng(const vecng<1, X>& _x, Y _y, Z _z, const vecng<1, W>& _w);
1156 template<typename X, typename Y, typename Z, typename W>
1157 vecng(X _x, const vecng<1, Y>& _y, Z _z, const vecng<1, W>& _w);
1158 template<typename X, typename Y, typename Z, typename W>
1159 vecng(
1160 const vecng<1, X>& _x, const vecng<1, Y>& _y, Z _z,
1161 const vecng<1, W>& _w
1162 );
1163 template<typename X, typename Y, typename Z, typename W>
1164 vecng(X _x, Y _y, const vecng<1, Z>& _z, const vecng<1, W>& _w);
1165 template<typename X, typename Y, typename Z, typename W>
1166 vecng(
1167 const vecng<1, X>& _x, Y _y, const vecng<1, Z>& _z,
1168 const vecng<1, W>& _w
1169 );
1170 template<typename X, typename Y, typename Z, typename W>
1171 vecng(
1172 X _x, const vecng<1, Y>& _y, const vecng<1, Z>& _z,
1173 const vecng<1, W>& _w
1174 );
1175 template<typename X, typename Y, typename Z, typename W>
1176 vecng(
1177 const vecng<1, X>& _x, const vecng<1, Y>& _y,
1178 const vecng<1, Z>& _z, const vecng<1, W>& _w
1179 );
1180
1181 // -- Conversion vector constructors --
1182
1183 template<typename A, typename B, typename C>
1184 vecng(const vecng<2, A>& _xy, B _z, C _w);
1185 template<typename A, typename B, typename C>
1186 vecng(const vecng<2, A>& _xy, const vecng<1, B> & _z, C _w);
1187 template<typename A, typename B, typename C>
1188 vecng(const vecng<2, A>& _xy, B _z, const vecng<1, C>& _w);
1189 template<typename A, typename B, typename C>
1190 vecng(
1191 const vecng<2, A>& _xy, const vecng<1, B>& _z,
1192 const vecng<1, C>& _w
1193 );
1194 template<typename A, typename B, typename C>
1195 vecng(A _x, const vecng<2, B>& _yz, C _w);
1196 template<typename A, typename B, typename C>
1197 vecng(const vecng<1, A>& _x, const vecng<2, B>& _yz, C _w);
1198 template<typename A, typename B, typename C>
1199 vecng(A _x, const vecng<2, B>& _yz, const vecng<1, C>& _w);
1200 template<typename A, typename B, typename C>
1201 vecng(
1202 const vecng<1, A>& _x, const vecng<2, B>& _yz,
1203 const vecng<1, C>& _w
1204 );
1205 template<typename A, typename B, typename C>
1206 vecng(A _x, B _y, const vecng<2, C>& _zw);
1207 template<typename A, typename B, typename C>
1208 vecng(const vecng<1, A>& _x, B _y, const vecng<2, C>& _zw);
1209 template<typename A, typename B, typename C>
1210 vecng(A _x, const vecng<1, B>& _y, const vecng<2, C>& _zw);
1211 template<typename A, typename B, typename C>
1212 vecng(
1213 const vecng<1, A>& _x, const vecng<1, B>& _y, const vecng<2, C>& _zw
1214 );
1215 template<typename A, typename B>
1216 vecng(const vecng<3, A>& _xyz, B _w);
1217 template<typename A, typename B>
1218 vecng(const vecng<3, A>& _xyz, const vecng<1, B>& _w);
1219 template<typename A, typename B>
1220 vecng(A _x, const vecng<3, B>& _yzw);
1221 template<typename A, typename B>
1222 vecng(const vecng<1, A>& _x, const vecng<3, B>& _yzw);
1223 template<typename A, typename B>
1224 vecng(const vecng<2, A>& _xy, const vecng<2, B>& _zw);
1225
1227 inline T length2() const {
1228 return x * x + y * y + z * z + w * w;
1229 }
1230
1232 inline T length() const {
1233 return sqrt(x * x + y * y + z * z + w * w);
1234 }
1235
1237 inline T distance2(const vector_type& v) const {
1238 T dx = v.x - x;
1239 T dy = v.y - y;
1240 T dz = v.z - z;
1241 T dw = v.w - w;
1242 return dx * dx + dy * dy + dz * dz + dw * dw;
1243 }
1244
1246 inline T distance(const vector_type& v) const {
1247 return sqrt(distance2(v));
1248 }
1249
1252 return dim;
1253 }
1254
1257 x += v.x;
1258 y += v.y;
1259 z += v.z;
1260 w += v.w;
1261 return *this;
1262 }
1263
1266 x -= v.x;
1267 y -= v.y;
1268 z -= v.z;
1269 w -= v.w;
1270 return *this;
1271 }
1272
1274 template <class T2>
1275 inline vector_type& operator*= (T2 s) {
1276 x *= T(s);
1277 y *= T(s);
1278 z *= T(s);
1279 w *= T(s);
1280 return *this;
1281 }
1282
1284 template <class T2>
1285 inline vector_type& operator/= (T2 s) {
1286 x /= T(s);
1287 y /= T(s);
1288 z /= T(s);
1289 w /= T(s);
1290 return *this;
1291 }
1292
1294 inline vector_type operator+ (const vector_type& v) const {
1295 return vector_type(x + v.x, y + v.y, z + v.z, w + v.w);
1296 }
1297
1299 inline vector_type operator- (const vector_type& v) const {
1300 return vector_type(x - v.x, y - v.y, z - v.z, w - v.w);
1301 }
1302
1304 template <class T2>
1305 inline vector_type operator/ (T2 s) const {
1306 return vector_type(x / T(s), y / T(s), z / T(s), w / T(s));
1307 }
1308
1310 inline vector_type operator- () const {
1311 return vector_type(-x, -y, -z, -w);
1312 }
1313
1315 T* data() {
1316 return &x;
1317 }
1318
1320 const T* data() const {
1321 return &x;
1322 }
1323
1325 inline T& operator[] (index_t i) {
1326 geo_debug_assert(i < dim);
1327 return data()[i];
1328 }
1329
1331 inline const T& operator[] (index_t i) const {
1332 geo_debug_assert(i < dim);
1333 return data()[i];
1334 }
1335
1337 T x;
1339 T y;
1341 T z;
1343 T w;
1344 };
1345
1350 template <class T>
1351 inline T dot(
1352 const vecng<4, T>& v1, const vecng<4, T>& v2
1353 ) {
1354 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
1355 }
1356
1357#ifndef GOMGEN
1362 template <
1363 class T2, class T,
1364 typename = std::enable_if_t<is_scalar<T2>::value>
1366 T2 s, const vecng<4, T>& v
1367 ) {
1368 return vecng<4, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z, T(s) * v.w);
1369 }
1370
1375 template <
1376 class T2, class T,
1377 typename = std::enable_if_t<is_scalar<T2>::value>
1379 const vecng<4, T>& v, T2 s
1380 ) {
1381 return vecng<4, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z, T(s) * v.w);
1382 }
1383
1384#endif
1385
1395 template <index_t DIM, class T>
1396 inline std::ostream& operator<< (
1397 std::ostream& out, const GEO::vecng<DIM, T>& v
1398 ) {
1399 const char* sep = "";
1400 for(index_t i = 0; i < DIM; i++) {
1401 out << sep << v[i];
1402 sep = " ";
1403 }
1404 return out;
1405 }
1406
1417 template <index_t DIM, class T>
1418 inline std::istream& operator>> (
1419 std::istream& in, GEO::vecng<DIM, T>& v
1420 ) {
1421 char c;
1422 while(isspace(in.peek())) {
1423 in.get(c);
1424 }
1425 if(in.peek() == '[' || in.peek() == '{') {
1426 in.get(c);
1427 }
1428 while(isspace(in.peek())) {
1429 in.get(c);
1430 }
1431 for(index_t i = 0; i < DIM; i++) {
1432 in >> v[i];
1433 while(isspace(in.peek())) {
1434 in.get(c);
1435 }
1436 if(in.peek() == ',') {
1437 in.get(c);
1438 }
1439 while(isspace(in.peek())) {
1440 in.get(c);
1441 }
1442 }
1443 if(in.peek() == ']' || in.peek() == '}') {
1444 in.get(c);
1445 }
1446 return in;
1447 }
1448
1449 /************************************************************************/
1450 // -- Conversion vector constructors --
1451
1452 template<typename T>
1453 template<typename A, typename B>
1455 : x{static_cast<T>(_xy.x)}
1456 , y{static_cast<T>(_xy.y)}
1457 , z{static_cast<T>(_z)}
1458 {}
1459
1460 template<typename T>
1461 template<typename A, typename B>
1463 : x(static_cast<T>(_xy.x))
1464 , y(static_cast<T>(_xy.y))
1465 , z(static_cast<T>(_z.x))
1466 {}
1467
1468 template<typename T>
1469 template<typename A, typename B>
1471 : x(static_cast<T>(_x))
1472 , y(static_cast<T>(_yz.x))
1473 , z(static_cast<T>(_yz.y))
1474 {}
1475
1476 template<typename T>
1477 template<typename A, typename B>
1479 : x(static_cast<T>(_x.x))
1480 , y(static_cast<T>(_yz.x))
1481 , z(static_cast<T>(_yz.y))
1482 {}
1483
1484 template<typename T>
1485 template<typename U>
1487 : x(static_cast<T>(v.x))
1488 , y(static_cast<T>(v.y))
1489 , z(static_cast<T>(v.z))
1490 {}
1491
1492
1493
1494 template<typename T>
1495 template<typename U>
1497 : x(static_cast<T>(v.x))
1498 , y(static_cast<T>(v.x))
1499 , z(static_cast<T>(v.x))
1500 , w(static_cast<T>(v.x))
1501 {}
1502
1503 template<typename T>
1504 template<typename X, typename Y, typename Z, typename W>
1505 vecng<4, T>::vecng(X _x, Y _y, Z _z, W _w)
1506 : x(static_cast<T>(_x))
1507 , y(static_cast<T>(_y))
1508 , z(static_cast<T>(_z))
1509 , w(static_cast<T>(_w))
1510 {}
1511
1512 template<typename T>
1513 template<typename X, typename Y, typename Z, typename W>
1514 vecng<4, T>::vecng(const vecng<1, X>& _x, Y _y, Z _z, W _w)
1515 : x(static_cast<T>(_x.x))
1516 , y(static_cast<T>(_y))
1517 , z(static_cast<T>(_z))
1518 , w(static_cast<T>(_w))
1519 {}
1520
1521 template<typename T>
1522 template<typename X, typename Y, typename Z, typename W>
1523 vecng<4, T>::vecng(X _x, const vecng<1, Y>& _y, Z _z, W _w)
1524 : x(static_cast<T>(_x))
1525 , y(static_cast<T>(_y.x))
1526 , z(static_cast<T>(_z))
1527 , w(static_cast<T>(_w))
1528 {}
1529
1530 template<typename T>
1531 template<typename X, typename Y, typename Z, typename W>
1532 vecng<4, T>::vecng(const vecng<1, X>& _x, const vecng<1, Y>& _y, Z _z, W _w)
1533 : x(static_cast<T>(_x.x))
1534 , y(static_cast<T>(_y.x))
1535 , z(static_cast<T>(_z))
1536 , w(static_cast<T>(_w))
1537 {}
1538
1539 template<typename T>
1540 template<typename X, typename Y, typename Z, typename W>
1541 vecng<4, T>::vecng(X _x, Y _y, const vecng<1, Z>& _z, W _w)
1542 : x(static_cast<T>(_x))
1543 , y(static_cast<T>(_y))
1544 , z(static_cast<T>(_z.x))
1545 , w(static_cast<T>(_w))
1546 {}
1547
1548 template<typename T>
1549 template<typename X, typename Y, typename Z, typename W>
1550 vecng<4, T>::vecng(const vecng<1, X>& _x, Y _y, const vecng<1, Z>& _z, W _w)
1551 : x(static_cast<T>(_x.x))
1552 , y(static_cast<T>(_y))
1553 , z(static_cast<T>(_z.x))
1554 , w(static_cast<T>(_w))
1555 {}
1556
1557 template<typename T>
1558 template<typename X, typename Y, typename Z, typename W>
1559 vecng<4, T>::vecng(X _x, const vecng<1, Y>& _y, const vecng<1, Z>& _z, W _w)
1560 : x(static_cast<T>(_x))
1561 , y(static_cast<T>(_y.x))
1562 , z(static_cast<T>(_z.x))
1563 , w(static_cast<T>(_w))
1564 {}
1565
1566 template<typename T>
1567 template<typename X, typename Y, typename Z, typename W>
1569 const vecng<1, X>& _x, const vecng<1, Y>& _y,
1570 const vecng<1, Z>& _z, W _w
1571 ) : x(static_cast<T>(_x.x))
1572 , y(static_cast<T>(_y.x))
1573 , z(static_cast<T>(_z.x))
1574 , w(static_cast<T>(_w))
1575 {}
1576
1577 template<typename T>
1578 template<typename X, typename Y, typename Z, typename W>
1580 const vecng<1, X>& _x, Y _y, Z _z, const vecng<1, W>& _w
1581 ) : x(static_cast<T>(_x.x))
1582 , y(static_cast<T>(_y))
1583 , z(static_cast<T>(_z))
1584 , w(static_cast<T>(_w.x))
1585 {}
1586
1587 template<typename T>
1588 template<typename X, typename Y, typename Z, typename W>
1590 X _x, const vecng<1, Y>& _y, Z _z, const vecng<1, W>& _w
1591 ) : x(static_cast<T>(_x))
1592 , y(static_cast<T>(_y.x))
1593 , z(static_cast<T>(_z))
1594 , w(static_cast<T>(_w.x))
1595 {}
1596
1597 template<typename T>
1598 template<typename X, typename Y, typename Z, typename W>
1600 const vecng<1, X>& _x, const vecng<1, Y>& _y, Z _z,
1601 const vecng<1, W>& _w
1602 ) : x(static_cast<T>(_x.x))
1603 , y(static_cast<T>(_y.x))
1604 , z(static_cast<T>(_z))
1605 , w(static_cast<T>(_w.x))
1606 {}
1607
1608 template<typename T>
1609 template<typename X, typename Y, typename Z, typename W>
1610 vecng<4, T>::vecng(X _x, Y _y, const vecng<1, Z>& _z, const vecng<1, W>& _w)
1611 : x(static_cast<T>(_x))
1612 , y(static_cast<T>(_y))
1613 , z(static_cast<T>(_z.x))
1614 , w(static_cast<T>(_w.x))
1615 {}
1616
1617 template<typename T>
1618 template<typename X, typename Y, typename Z, typename W>
1620 const vecng<1, X>& _x, Y _y, const vecng<1, Z>& _z,
1621 const vecng<1, W>& _w
1622 ) : x(static_cast<T>(_x.x))
1623 , y(static_cast<T>(_y))
1624 , z(static_cast<T>(_z.x))
1625 , w(static_cast<T>(_w.x))
1626 {}
1627
1628 template<typename T>
1629 template<typename X, typename Y, typename Z, typename W>
1631 X _x, const vecng<1, Y>& _y, const vecng<1, Z>& _z,
1632 const vecng<1, W>& _w
1633 ) : x(static_cast<T>(_x))
1634 , y(static_cast<T>(_y.x))
1635 , z(static_cast<T>(_z.x))
1636 , w(static_cast<T>(_w.x))
1637 {}
1638
1639 template<typename T>
1640 template<typename X, typename Y, typename Z, typename W>
1642 const vecng<1, X>& _x, const vecng<1, Y>& _y,
1643 const vecng<1, Z>& _z, const vecng<1, W>& _w
1644 ) : x(static_cast<T>(_x.x))
1645 , y(static_cast<T>(_y.x))
1646 , z(static_cast<T>(_z.x))
1647 , w(static_cast<T>(_w.x))
1648 {}
1649
1650 // -- Conversion vector constructors --
1651
1652 template<typename T>
1653 template<typename A, typename B, typename C>
1654 vecng<4, T>::vecng(const vecng<2, A>& _xy, B _z, C _w)
1655 : x(static_cast<T>(_xy.x))
1656 , y(static_cast<T>(_xy.y))
1657 , z(static_cast<T>(_z))
1658 , w(static_cast<T>(_w))
1659 {}
1660
1661 template<typename T>
1662 template<typename A, typename B, typename C>
1663 vecng<4, T>::vecng(const vecng<2, A>& _xy, const vecng<1, B>& _z, C _w)
1664 : x(static_cast<T>(_xy.x))
1665 , y(static_cast<T>(_xy.y))
1666 , z(static_cast<T>(_z.x))
1667 , w(static_cast<T>(_w))
1668 {}
1669
1670 template<typename T>
1671 template<typename A, typename B, typename C>
1672 vecng<4, T>::vecng(const vecng<2, A>& _xy, B _z, const vecng<1, C>& _w)
1673 : x(static_cast<T>(_xy.x))
1674 , y(static_cast<T>(_xy.y))
1675 , z(static_cast<T>(_z))
1676 , w(static_cast<T>(_w.x))
1677 {}
1678
1679 template<typename T>
1680 template<typename A, typename B, typename C>
1682 const vecng<2, A>& _xy, const vecng<1, B>& _z, const vecng<1, C>& _w
1683 ) : x(static_cast<T>(_xy.x))
1684 , y(static_cast<T>(_xy.y))
1685 , z(static_cast<T>(_z.x))
1686 , w(static_cast<T>(_w.x))
1687 {}
1688
1689 template<typename T>
1690 template<typename A, typename B, typename C>
1691 vecng<4, T>::vecng(A _x, const vecng<2, B>& _yz, C _w)
1692 : x(static_cast<T>(_x))
1693 , y(static_cast<T>(_yz.x))
1694 , z(static_cast<T>(_yz.y))
1695 , w(static_cast<T>(_w))
1696 {}
1697
1698 template<typename T>
1699 template<typename A, typename B, typename C>
1700 vecng<4, T>::vecng(const vecng<1, A>& _x, const vecng<2, B>& _yz, C _w)
1701 : x(static_cast<T>(_x.x))
1702 , y(static_cast<T>(_yz.x))
1703 , z(static_cast<T>(_yz.y))
1704 , w(static_cast<T>(_w))
1705 {}
1706
1707 template<typename T>
1708 template<typename A, typename B, typename C>
1709 vecng<4, T>::vecng(A _x, const vecng<2, B>& _yz, const vecng<1, C>& _w)
1710 : x(static_cast<T>(_x))
1711 , y(static_cast<T>(_yz.x))
1712 , z(static_cast<T>(_yz.y))
1713 , w(static_cast<T>(_w.x))
1714 {}
1715
1716 template<typename T>
1717 template<typename A, typename B, typename C>
1719 const vecng<1, A>& _x, const vecng<2, B>& _yz, const vecng<1, C>& _w
1720 ) : x(static_cast<T>(_x.x))
1721 , y(static_cast<T>(_yz.x))
1722 , z(static_cast<T>(_yz.y))
1723 , w(static_cast<T>(_w.x))
1724 {}
1725
1726 template<typename T>
1727 template<typename A, typename B, typename C>
1728 vecng<4, T>::vecng(A _x, B _y, const vecng<2, C>& _zw)
1729 : x(static_cast<T>(_x))
1730 , y(static_cast<T>(_y))
1731 , z(static_cast<T>(_zw.x))
1732 , w(static_cast<T>(_zw.y))
1733 {}
1734
1735 template<typename T>
1736 template<typename A, typename B, typename C>
1737 vecng<4, T>::vecng(const vecng<1, A>& _x, B _y, const vecng<2, C>& _zw)
1738 : x(static_cast<T>(_x.x))
1739 , y(static_cast<T>(_y))
1740 , z(static_cast<T>(_zw.x))
1741 , w(static_cast<T>(_zw.y))
1742 {}
1743
1744 template<typename T>
1745 template<typename A, typename B, typename C>
1746 vecng<4, T>::vecng(A _x, const vecng<1, B>& _y, const vecng<2, C>& _zw)
1747 : x(static_cast<T>(_x))
1748 , y(static_cast<T>(_y.x))
1749 , z(static_cast<T>(_zw.x))
1750 , w(static_cast<T>(_zw.y))
1751 {}
1752
1753 template<typename T>
1754 template<typename A, typename B, typename C>
1756 const vecng<1, A>& _x, const vecng<1, B>& _y, const vecng<2, C>& _zw
1757 ) : x(static_cast<T>(_x.x))
1758 , y(static_cast<T>(_y.x))
1759 , z(static_cast<T>(_zw.x))
1760 , w(static_cast<T>(_zw.y))
1761 {}
1762
1763 template<typename T>
1764 template<typename A, typename B>
1765 vecng<4, T>::vecng(const vecng<3, A>& _xyz, B _w)
1766 : x(static_cast<T>(_xyz.x))
1767 , y(static_cast<T>(_xyz.y))
1768 , z(static_cast<T>(_xyz.z))
1769 , w(static_cast<T>(_w))
1770 {}
1771
1772 template<typename T>
1773 template<typename A, typename B>
1774 vecng<4, T>::vecng(const vecng<3, A>& _xyz, const vecng<1, B>& _w)
1775 : x(static_cast<T>(_xyz.x))
1776 , y(static_cast<T>(_xyz.y))
1777 , z(static_cast<T>(_xyz.z))
1778 , w(static_cast<T>(_w.x))
1779 {}
1780
1781 template<typename T>
1782 template<typename A, typename B>
1783 vecng<4, T>::vecng(A _x, const vecng<3, B>& _yzw)
1784 : x(static_cast<T>(_x))
1785 , y(static_cast<T>(_yzw.x))
1786 , z(static_cast<T>(_yzw.y))
1787 , w(static_cast<T>(_yzw.z))
1788 {}
1789
1790 template<typename T>
1791 template<typename A, typename B>
1792 vecng<4, T>::vecng(const vecng<1, A>& _x, const vecng<3, B>& _yzw)
1793 : x(static_cast<T>(_x.x))
1794 , y(static_cast<T>(_yzw.x))
1795 , z(static_cast<T>(_yzw.y))
1796 , w(static_cast<T>(_yzw.z))
1797 {}
1798
1799 template<typename T>
1800 template<typename A, typename B>
1801 vecng<4, T>::vecng(const vecng<2, A>& _xy, const vecng<2, B>& _zw)
1802 : x(static_cast<T>(_xy.x))
1803 , y(static_cast<T>(_xy.y))
1804 , z(static_cast<T>(_zw.x))
1805 , w(static_cast<T>(_zw.y))
1806 {}
1807
1808 /************************************************************************/
1809
1810 namespace Numeric {
1811
1812 template<class T>
1814 vecng<2,T>& v
1815 ) {
1816 v.optimize();
1817 }
1818
1819 template<class T>
1821 vecng<3,T>& v
1822 ) {
1823 v.optimize();
1824 }
1825
1826 }
1827
1828 /************************************************************************/
1829}
1830
1831#endif
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:196
T distance2(const vector_type &v) const
Definition vecg.h:612
vecng(const T &x_in, const T &y_in)
Constructs a vector from coordinates.
Definition vecg.h:557
T distance(const vector_type &v) const
Definition vecg.h:619
T y
Vector y coordinate.
Definition vecg.h:710
T * data()
Gets modifiable vector data.
Definition vecg.h:680
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:675
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:685
void optimize()
Optimizes coordinate representation.
Definition vecg.h:702
T x
Vector x coordinate.
Definition vecg.h:708
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:576
T length() const
Gets the length of the vector.
Definition vecg.h:607
vecng(const std::initializer_list< T > &Vi)
Definition vecg.h:589
T value_type
The type of the vector coordinates.
Definition vecg.h:545
vecng(T &&x_in, T &&y_in)
Constructs a vector from coordinates.
Definition vecg.h:566
vecng()
Default vector constructor.
Definition vecg.h:548
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:583
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:542
T length2() const
Gets the squared length of the vector.
Definition vecg.h:602
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:816
T x
Vector x coordinate.
Definition vecg.h:983
void optimize()
Optimizes coordinate representation.
Definition vecg.h:976
vecng()
Default vector constructor.
Definition vecg.h:785
vecng(T &&x_in, T &&y_in, T &&z_in)
Constructs a vector from coordinates.
Definition vecg.h:805
T * data()
Gets modifiable vector data.
Definition vecg.h:954
T y
Vector y coordinate.
Definition vecg.h:985
T value_type
The type of the vector coordinates.
Definition vecg.h:782
T distance2(const vector_type &v) const
Definition vecg.h:881
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:959
T length2() const
Gets the squared length of the vector.
Definition vecg.h:871
T z
Vector z coordinate.
Definition vecg.h:987
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:824
vecng(const std::initializer_list< T > &Vi)
Definition vecg.h:831
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:779
T distance(const vector_type &v) const
Definition vecg.h:889
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:949
T length() const
Gets the length of the vector.
Definition vecg.h:876
vecng(const T &x_in, const T &y_in, const T &z_in)
Constructs a vector from coordinates.
Definition vecg.h:795
T distance2(const vector_type &v) const
Definition vecg.h:1237
vecng(const std::initializer_list< T > &Vi)
Definition vecg.h:1118
vecng(const T &x_in, const T &y_in, const T &z_in, const T &w_in)
Constructs a vector from coordinates.
Definition vecg.h:1078
T length2() const
Gets the squared length of the vector.
Definition vecg.h:1227
T w
Vector w coordinate.
Definition vecg.h:1343
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:1061
T value_type
The type of the vector coordinates.
Definition vecg.h:1064
vecng()
Default vector constructor.
Definition vecg.h:1067
T x
Vector x coordinate.
Definition vecg.h:1337
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:1320
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:1251
T y
Vector y coordinate.
Definition vecg.h:1339
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:1110
T z
Vector z coordinate.
Definition vecg.h:1341
T * data()
Gets modifiable vector data.
Definition vecg.h:1315
T length() const
Gets the length of the vector.
Definition vecg.h:1232
vecng(T &&x_in, T &&y_in, T &&z_in, T &&w_in)
Constructs a vector from coordinates.
Definition vecg.h:1089
T distance(const vector_type &v) const
Definition vecg.h:1246
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:1101
Generic maths vector.
Definition vecg.h:74
T & operator[](index_t i)
Gets a modifiable vector coordinate.
Definition vecg.h:182
vector_type & operator-=(const vector_type &v)
Subtracts a vector in place.
Definition vecg.h:260
vecng< 3, T > cross(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the cross product of 2 vectors.
Definition vecg.h:1009
T value_type
The type of the vector coordinates.
Definition vecg.h:83
T length2(const vecng< DIM, T > &v)
Gets the square norm of a vector.
Definition vecg.h:458
T det(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the determinant of 2 vectors.
Definition vecg.h:732
T distance2(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the square distance between 2 vectors.
Definition vecg.h:471
T length2() const
Gets the squared length of the vector.
Definition vecg.h:200
T * data()
Gets modifiable vector data.
Definition vecg.h:165
vector_type & operator/=(T2 s)
Divides by a scalar in place.
Definition vecg.h:294
GEO_NODISCARD vecng< DIM, T > normalize(const vecng< DIM, T > &v)
Normalizes a vector.
Definition vecg.h:502
T dot(const vecng< 4, T > &v1, const vecng< 4, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:1351
T length() const
Gets the length of the vector.
Definition vecg.h:211
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:173
T length(const vecng< DIM, T > &v)
Gets the norm of a vector.
Definition vecg.h:446
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:157
vector_type operator-() const
Negates a vector.
Definition vecg.h:355
vector_type & operator*=(T2 s)
Multiplies by a scalar in place.
Definition vecg.h:277
vector_type operator+(const vector_type &v) const
Adds 2 vectors.
Definition vecg.h:308
vector_type operator/(T2 s) const
Divides a vector by a scalar.
Definition vecg.h:342
vector_type & operator+=(const vector_type &v)
Adds a vector in place.
Definition vecg.h:246
vecng()
Default vector constructor.
Definition vecg.h:89
vecng< DIM, T > vector_type
This vector type.
Definition vecg.h:80
T dot(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:718
vecng< DIM, T > mix(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2, T s)
Computes a weighted barycenter.
Definition vecg.h:523
T distance(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the distance between 2 vectors.
Definition vecg.h:486
T distance(const vector_type &v) const
Gets the distance to a vector.
Definition vecg.h:233
vecng(const vecng< DIM, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:108
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
Definition vecg.h:220
vecng(const std::initializer_list< T > &Vi)
Constructs a vector from an initializer list.
Definition vecg.h:144
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:134
static constexpr index_t dim
The dimension of the vector.
Definition vecg.h:77
T dot(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:375
Determinants for small sizes.
Common include file, providing basic definitions. Should be included before anything else by all head...
Types and functions for memory manipulation.
void optimize_number_representation(T &x)
place holder for optimizing internal number representation
Definition numeric.h:268
Global Vorpaline namespace.
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
Definition vecg.h:995
std::istream & operator>>(std::istream &in, Quaternion &q)
Reads a Quaternion from a stream.
Definition quaternion.h:225
T geo_sqr(T x)
Gets the square value of a value.
Definition numeric.h:302
std::ostream & operator<<(std::ostream &out, const Quaternion &q)
Writes a Quaternion to a stream.
Definition quaternion.h:213
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:330
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Definition determinant.h:58
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
Definition matrix.h:536
Types and functions for numbers manipulation.