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 template<typename T>
1493 template<typename U>
1495 : x(static_cast<T>(v.x))
1496 , y(static_cast<T>(v.x))
1497 , z(static_cast<T>(v.x))
1498 , w(static_cast<T>(v.x))
1499 {}
1500
1501 template<typename T>
1502 template<typename X, typename Y, typename Z, typename W>
1503 vecng<4, T>::vecng(X _x, Y _y, Z _z, W _w)
1504 : x(static_cast<T>(_x))
1505 , y(static_cast<T>(_y))
1506 , z(static_cast<T>(_z))
1507 , w(static_cast<T>(_w))
1508 {}
1509
1510 template<typename T>
1511 template<typename X, typename Y, typename Z, typename W>
1512 vecng<4, T>::vecng(const vecng<1, X>& _x, Y _y, Z _z, W _w)
1513 : x(static_cast<T>(_x.x))
1514 , y(static_cast<T>(_y))
1515 , z(static_cast<T>(_z))
1516 , w(static_cast<T>(_w))
1517 {}
1518
1519 template<typename T>
1520 template<typename X, typename Y, typename Z, typename W>
1521 vecng<4, T>::vecng(X _x, const vecng<1, Y>& _y, Z _z, W _w)
1522 : x(static_cast<T>(_x))
1523 , y(static_cast<T>(_y.x))
1524 , z(static_cast<T>(_z))
1525 , w(static_cast<T>(_w))
1526 {}
1527
1528 template<typename T>
1529 template<typename X, typename Y, typename Z, typename W>
1530 vecng<4, T>::vecng(const vecng<1, X>& _x, const vecng<1, Y>& _y, Z _z, W _w)
1531 : x(static_cast<T>(_x.x))
1532 , y(static_cast<T>(_y.x))
1533 , z(static_cast<T>(_z))
1534 , w(static_cast<T>(_w))
1535 {}
1536
1537 template<typename T>
1538 template<typename X, typename Y, typename Z, typename W>
1539 vecng<4, T>::vecng(X _x, Y _y, const vecng<1, Z>& _z, W _w)
1540 : x(static_cast<T>(_x))
1541 , y(static_cast<T>(_y))
1542 , z(static_cast<T>(_z.x))
1543 , w(static_cast<T>(_w))
1544 {}
1545
1546 template<typename T>
1547 template<typename X, typename Y, typename Z, typename W>
1548 vecng<4, T>::vecng(const vecng<1, X>& _x, Y _y, const vecng<1, Z>& _z, W _w)
1549 : x(static_cast<T>(_x.x))
1550 , y(static_cast<T>(_y))
1551 , z(static_cast<T>(_z.x))
1552 , w(static_cast<T>(_w))
1553 {}
1554
1555 template<typename T>
1556 template<typename X, typename Y, typename Z, typename W>
1557 vecng<4, T>::vecng(X _x, const vecng<1, Y>& _y, const vecng<1, Z>& _z, W _w)
1558 : x(static_cast<T>(_x))
1559 , y(static_cast<T>(_y.x))
1560 , z(static_cast<T>(_z.x))
1561 , w(static_cast<T>(_w))
1562 {}
1563
1564 template<typename T>
1565 template<typename X, typename Y, typename Z, typename W>
1567 const vecng<1, X>& _x, const vecng<1, Y>& _y,
1568 const vecng<1, Z>& _z, W _w
1569 ) : x(static_cast<T>(_x.x))
1570 , y(static_cast<T>(_y.x))
1571 , z(static_cast<T>(_z.x))
1572 , w(static_cast<T>(_w))
1573 {}
1574
1575 template<typename T>
1576 template<typename X, typename Y, typename Z, typename W>
1578 const vecng<1, X>& _x, Y _y, Z _z, const vecng<1, W>& _w
1579 ) : x(static_cast<T>(_x.x))
1580 , y(static_cast<T>(_y))
1581 , z(static_cast<T>(_z))
1582 , w(static_cast<T>(_w.x))
1583 {}
1584
1585 template<typename T>
1586 template<typename X, typename Y, typename Z, typename W>
1588 X _x, const vecng<1, Y>& _y, Z _z, const vecng<1, W>& _w
1589 ) : x(static_cast<T>(_x))
1590 , y(static_cast<T>(_y.x))
1591 , z(static_cast<T>(_z))
1592 , w(static_cast<T>(_w.x))
1593 {}
1594
1595 template<typename T>
1596 template<typename X, typename Y, typename Z, typename W>
1598 const vecng<1, X>& _x, const vecng<1, Y>& _y, Z _z,
1599 const vecng<1, W>& _w
1600 ) : x(static_cast<T>(_x.x))
1601 , y(static_cast<T>(_y.x))
1602 , z(static_cast<T>(_z))
1603 , w(static_cast<T>(_w.x))
1604 {}
1605
1606 template<typename T>
1607 template<typename X, typename Y, typename Z, typename W>
1608 vecng<4, T>::vecng(X _x, Y _y, const vecng<1, Z>& _z, const vecng<1, W>& _w)
1609 : x(static_cast<T>(_x))
1610 , y(static_cast<T>(_y))
1611 , z(static_cast<T>(_z.x))
1612 , w(static_cast<T>(_w.x))
1613 {}
1614
1615 template<typename T>
1616 template<typename X, typename Y, typename Z, typename W>
1618 const vecng<1, X>& _x, Y _y, const vecng<1, Z>& _z,
1619 const vecng<1, W>& _w
1620 ) : x(static_cast<T>(_x.x))
1621 , y(static_cast<T>(_y))
1622 , z(static_cast<T>(_z.x))
1623 , w(static_cast<T>(_w.x))
1624 {}
1625
1626 template<typename T>
1627 template<typename X, typename Y, typename Z, typename W>
1629 X _x, const vecng<1, Y>& _y, const vecng<1, Z>& _z,
1630 const vecng<1, W>& _w
1631 ) : x(static_cast<T>(_x))
1632 , y(static_cast<T>(_y.x))
1633 , z(static_cast<T>(_z.x))
1634 , w(static_cast<T>(_w.x))
1635 {}
1636
1637 template<typename T>
1638 template<typename X, typename Y, typename Z, typename W>
1640 const vecng<1, X>& _x, const vecng<1, Y>& _y,
1641 const vecng<1, Z>& _z, const vecng<1, W>& _w
1642 ) : x(static_cast<T>(_x.x))
1643 , y(static_cast<T>(_y.x))
1644 , z(static_cast<T>(_z.x))
1645 , w(static_cast<T>(_w.x))
1646 {}
1647
1648 // -- Conversion vector constructors --
1649
1650 template<typename T>
1651 template<typename A, typename B, typename C>
1652 vecng<4, T>::vecng(const vecng<2, A>& _xy, B _z, C _w)
1653 : x(static_cast<T>(_xy.x))
1654 , y(static_cast<T>(_xy.y))
1655 , z(static_cast<T>(_z))
1656 , w(static_cast<T>(_w))
1657 {}
1658
1659 template<typename T>
1660 template<typename A, typename B, typename C>
1661 vecng<4, T>::vecng(const vecng<2, A>& _xy, const vecng<1, B>& _z, C _w)
1662 : x(static_cast<T>(_xy.x))
1663 , y(static_cast<T>(_xy.y))
1664 , z(static_cast<T>(_z.x))
1665 , w(static_cast<T>(_w))
1666 {}
1667
1668 template<typename T>
1669 template<typename A, typename B, typename C>
1670 vecng<4, T>::vecng(const vecng<2, A>& _xy, B _z, const vecng<1, C>& _w)
1671 : x(static_cast<T>(_xy.x))
1672 , y(static_cast<T>(_xy.y))
1673 , z(static_cast<T>(_z))
1674 , w(static_cast<T>(_w.x))
1675 {}
1676
1677 template<typename T>
1678 template<typename A, typename B, typename C>
1680 const vecng<2, A>& _xy, const vecng<1, B>& _z, const vecng<1, C>& _w
1681 ) : x(static_cast<T>(_xy.x))
1682 , y(static_cast<T>(_xy.y))
1683 , z(static_cast<T>(_z.x))
1684 , w(static_cast<T>(_w.x))
1685 {}
1686
1687 template<typename T>
1688 template<typename A, typename B, typename C>
1689 vecng<4, T>::vecng(A _x, const vecng<2, B>& _yz, C _w)
1690 : x(static_cast<T>(_x))
1691 , y(static_cast<T>(_yz.x))
1692 , z(static_cast<T>(_yz.y))
1693 , w(static_cast<T>(_w))
1694 {}
1695
1696 template<typename T>
1697 template<typename A, typename B, typename C>
1698 vecng<4, T>::vecng(const vecng<1, A>& _x, const vecng<2, B>& _yz, C _w)
1699 : x(static_cast<T>(_x.x))
1700 , y(static_cast<T>(_yz.x))
1701 , z(static_cast<T>(_yz.y))
1702 , w(static_cast<T>(_w))
1703 {}
1704
1705 template<typename T>
1706 template<typename A, typename B, typename C>
1707 vecng<4, T>::vecng(A _x, const vecng<2, B>& _yz, const vecng<1, C>& _w)
1708 : x(static_cast<T>(_x))
1709 , y(static_cast<T>(_yz.x))
1710 , z(static_cast<T>(_yz.y))
1711 , w(static_cast<T>(_w.x))
1712 {}
1713
1714 template<typename T>
1715 template<typename A, typename B, typename C>
1717 const vecng<1, A>& _x, const vecng<2, B>& _yz, const vecng<1, C>& _w
1718 ) : x(static_cast<T>(_x.x))
1719 , y(static_cast<T>(_yz.x))
1720 , z(static_cast<T>(_yz.y))
1721 , w(static_cast<T>(_w.x))
1722 {}
1723
1724 template<typename T>
1725 template<typename A, typename B, typename C>
1726 vecng<4, T>::vecng(A _x, B _y, const vecng<2, C>& _zw)
1727 : x(static_cast<T>(_x))
1728 , y(static_cast<T>(_y))
1729 , z(static_cast<T>(_zw.x))
1730 , w(static_cast<T>(_zw.y))
1731 {}
1732
1733 template<typename T>
1734 template<typename A, typename B, typename C>
1735 vecng<4, T>::vecng(const vecng<1, A>& _x, B _y, const vecng<2, C>& _zw)
1736 : x(static_cast<T>(_x.x))
1737 , y(static_cast<T>(_y))
1738 , z(static_cast<T>(_zw.x))
1739 , w(static_cast<T>(_zw.y))
1740 {}
1741
1742 template<typename T>
1743 template<typename A, typename B, typename C>
1744 vecng<4, T>::vecng(A _x, const vecng<1, B>& _y, const vecng<2, C>& _zw)
1745 : x(static_cast<T>(_x))
1746 , y(static_cast<T>(_y.x))
1747 , z(static_cast<T>(_zw.x))
1748 , w(static_cast<T>(_zw.y))
1749 {}
1750
1751 template<typename T>
1752 template<typename A, typename B, typename C>
1754 const vecng<1, A>& _x, const vecng<1, B>& _y, const vecng<2, C>& _zw
1755 ) : x(static_cast<T>(_x.x))
1756 , y(static_cast<T>(_y.x))
1757 , z(static_cast<T>(_zw.x))
1758 , w(static_cast<T>(_zw.y))
1759 {}
1760
1761 template<typename T>
1762 template<typename A, typename B>
1763 vecng<4, T>::vecng(const vecng<3, A>& _xyz, B _w)
1764 : x(static_cast<T>(_xyz.x))
1765 , y(static_cast<T>(_xyz.y))
1766 , z(static_cast<T>(_xyz.z))
1767 , w(static_cast<T>(_w))
1768 {}
1769
1770 template<typename T>
1771 template<typename A, typename B>
1772 vecng<4, T>::vecng(const vecng<3, A>& _xyz, const vecng<1, B>& _w)
1773 : x(static_cast<T>(_xyz.x))
1774 , y(static_cast<T>(_xyz.y))
1775 , z(static_cast<T>(_xyz.z))
1776 , w(static_cast<T>(_w.x))
1777 {}
1778
1779 template<typename T>
1780 template<typename A, typename B>
1781 vecng<4, T>::vecng(A _x, const vecng<3, B>& _yzw)
1782 : x(static_cast<T>(_x))
1783 , y(static_cast<T>(_yzw.x))
1784 , z(static_cast<T>(_yzw.y))
1785 , w(static_cast<T>(_yzw.z))
1786 {}
1787
1788 template<typename T>
1789 template<typename A, typename B>
1790 vecng<4, T>::vecng(const vecng<1, A>& _x, const vecng<3, B>& _yzw)
1791 : x(static_cast<T>(_x.x))
1792 , y(static_cast<T>(_yzw.x))
1793 , z(static_cast<T>(_yzw.y))
1794 , w(static_cast<T>(_yzw.z))
1795 {}
1796
1797 template<typename T>
1798 template<typename A, typename B>
1799 vecng<4, T>::vecng(const vecng<2, A>& _xy, const vecng<2, B>& _zw)
1800 : x(static_cast<T>(_xy.x))
1801 , y(static_cast<T>(_xy.y))
1802 , z(static_cast<T>(_zw.x))
1803 , w(static_cast<T>(_zw.y))
1804 {}
1805
1806 /************************************************************************/
1807
1808 namespace Numeric {
1809
1810 template<class T>
1812 vecng<2,T>& v
1813 ) {
1814 v.optimize();
1815 }
1816
1817 template<class T>
1819 vecng<3,T>& v
1820 ) {
1821 v.optimize();
1822 }
1823
1824 }
1825
1826 /************************************************************************/
1827}
1828
1829#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:278
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:312
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:340
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:540
Types and functions for numbers manipulation.