Geogram Version 1.9.7
A programming library of geometric algorithms
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
59namespace GEO {
60
69 template <index_t DIM, class T>
70 class vecng {
71 public:
73 static constexpr index_t dim = DIM;
74
77
79 typedef T value_type;
80
86 for(index_t i = 0; i < DIM; i++) {
87 data_[i] = T(0);
88 }
89 }
90
91 // This one should never be called :
92 // a template constructor cannot be a copy constructor
93
103 template <class T2>
104 explicit vecng(const vecng<DIM, T2>& v) {
105 for(index_t i = 0; i < DIM; i++) {
106 data_[i] = T(v[i]);
107 }
108 }
109
110 // to avoid compilation problems
111 template <class T2, index_t DIM2>
112 explicit vecng(
113 const vecng<DIM2, T2>& v
114 ) {
115 geo_debug_assert(DIM2 == DIM);
116 for(index_t i = 0; i < DIM; i++) {
117 data_[i] = T(v[i]);
118 }
119 }
120
129 template <class T2>
130 explicit vecng(const T2* v) {
131 for(index_t i = 0; i < DIM; i++) {
132 data_[i] = T(v[i]);
133 }
134 }
135
140 vecng(const std::initializer_list<T>& Vi) {
141 index_t i = 0;
142 for(auto& it: Vi) {
143 geo_debug_assert(i < DIM);
144 data()[i] = it;
145 ++i;
146 }
147 }
148
154 return DIM;
155 }
156
161 T* data() {
162 return data_;
163 }
164
169 const T* data() const {
170 return data_;
171 }
172
178 inline T& operator[] (index_t i) {
179 geo_debug_assert(i < DIM);
180 return data()[i];
181 }
182
188 inline const T& operator[] (index_t i) const {
189 geo_debug_assert(i < DIM);
190 return data()[i];
191 }
192
196 inline T length2() const {
197 T result = T(0);
198 for(index_t i = 0; i < DIM; i++) {
199 result += data_[i] * data_[i];
200 }
201 return result;
202 }
203
207 inline T length() const {
208 return sqrt(length2());
209 }
210
216 inline T distance2(const vector_type& v) const {
217 T result(0);
218 for(index_t i = 0; i < DIM; i++) {
219 result += geo_sqr(v.data_[i] - data_[i]);
220 }
221 return result;
222 }
223
229 inline T distance(const vector_type& v) const {
230 return sqrt(distance2(v));
231 }
232
233 // operators
234
243 for(index_t i = 0; i < DIM; i++) {
244 data_[i] += v.data_[i];
245 }
246 return *this;
247 }
248
257 for(index_t i = 0; i < DIM; i++) {
258 data_[i] -= v.data_[i];
259 }
260 return *this;
261 }
262
272 template <class T2>
273 inline vector_type& operator*= (T2 s) {
274 for(index_t i = 0; i < DIM; i++) {
275 data_[i] *= T(s);
276 }
277 return *this;
278 }
279
289 template <class T2>
290 inline vector_type& operator/= (T2 s) {
291 for(index_t i = 0; i < DIM; i++) {
292 data_[i] /= T(s);
293 }
294 return *this;
295 }
296
304 inline vector_type operator+ (const vector_type& v) const {
305 vector_type result(*this);
306 for(index_t i = 0; i < DIM; i++) {
307 result.data_[i] += v.data_[i];
308 }
309 return result;
310 }
311
319 inline vector_type operator- (const vector_type& v) const {
320 vector_type result(*this);
321 for(index_t i = 0; i < DIM; i++) {
322 result.data_[i] -= v.data_[i];
323 }
324 return result;
325 }
326
336 template <class T2>
337 inline vector_type operator* (T2 s) const {
338 vector_type result(*this);
339 for(index_t i = 0; i < DIM; i++) {
340 result.data_[i] *= T(s);
341 }
342 return result;
343 }
344
354 template <class T2>
355 inline vector_type operator/ (T2 s) const {
356 vector_type result(*this);
357 for(index_t i = 0; i < DIM; i++) {
358 result.data_[i] /= T(s);
359 }
360 return result;
361 }
362
368 inline vector_type operator- () const {
369 vector_type result;
370 for(index_t i = 0; i < DIM; i++) {
371 result.data_[i] = -data_[i];
372 }
373 return result;
374 }
375
376 private:
377 T data_[DIM];
378 };
379
387 template <index_t DIM, class T>
388 inline T dot(
389 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
390 ) {
391 T result = 0;
392 for(index_t i = 0; i < DIM; i++) {
393 result += v1[i] * v2[i];
394 }
395 return result;
396 }
397
409 template <class T2, index_t DIM, class T>
410 inline vecng<DIM, T> operator* (
411 T2 s, const vecng<DIM, T>& v
412 ) {
413 vecng<DIM, T> result;
414 for(index_t i = 0; i < DIM; i++) {
415 result[i] = T(s) * v[i];
416 }
417 return result;
418 }
419
420 // Compatibility with GLSL
421
429 template <index_t DIM, class T>
430 inline T length(const vecng<DIM, T>& v) {
431 return v.length();
432 }
433
441 template <index_t DIM, class T>
442 inline T length2(const vecng<DIM, T>& v) {
443 return v.length2();
444 }
445
454 template <index_t DIM, class T>
455 inline T distance2(
456 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
457 ) {
458 return v2.distance2(v1);
459 }
460
469 template <index_t DIM, class T>
470 inline T distance(
471 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
472 ) {
473 return v2.distance(v1);
474 }
475
485 template <index_t DIM, class T>
487 const vecng<DIM, T>& v
488 ) {
489 T s = length(v);
490 if(s > 1e-30) {
491 s = T(1) / s;
492 }
493 return s * v;
494 }
495
506 template <index_t DIM, class T>
508 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2, T s
509 ) {
510 return (T(1) - s) * v1 + s * v2;
511 }
512
513 /************************************************************************/
514
519 template <class T>
520 class vecng<2, T> {
521 public:
523 static constexpr index_t dim = 2;
524
527
529 typedef T value_type;
530
533 x(0),
534 y(0) {
535 }
536
541 vecng(const T& x_in, const T& y_in) :
542 x(x_in),
543 y(y_in) {
544 }
545
550 vecng(T&& x_in, T&& y_in) :
551 x(x_in),
552 y(y_in) {
553 }
554
555 vecng(const vecng<2,T>& rhs) = default;
556 vecng(vecng<2,T>&& rhs) = default;
557
559 template <class T2>
560 explicit vecng(const vecng<dim, T2>& v) :
561 x(v.x),
562 y(v.y) {
563 }
564
566 template <class T2>
567 explicit vecng(const T2* v) :
568 x(v[0]),
569 y(v[1]) {
570 }
571
573 vecng(const std::initializer_list<T>& Vi) {
574 index_t i = 0;
575 for(auto& it: Vi) {
577 data()[i] = it;
578 ++i;
579 }
580 }
581
582 vecng<2,T>& operator=(const vecng<2,T>& rhs) = default;
583 vecng<2,T>& operator=(vecng<2,T>&& rhs) = default;
584
586 inline T length2() const {
587 return x * x + y * y;
588 }
589
591 inline T length() const {
592 return sqrt(x * x + y * y);
593 }
594
596 inline T distance2(const vector_type& v) const {
597 T dx = v.x - x;
598 T dy = v.y - y;
599 return dx * dx + dy * dy;
600 }
601
603 inline T distance(const vector_type& v) const {
604 return sqrt(distance2(v));
605 }
606
609 x += v.x;
610 y += v.y;
611 return *this;
612 }
613
616 x -= v.x;
617 y -= v.y;
618 return *this;
619 }
620
622 template <class T2>
623 inline vector_type& operator*= (T2 s) {
624 x *= T(s);
625 y *= T(s);
626 return *this;
627 }
628
630 template <class T2>
631 inline vector_type& operator/= (T2 s) {
632 x /= T(s);
633 y /= T(s);
634 return *this;
635 }
636
638 inline vector_type operator+ (const vector_type& v) const {
639 return vector_type(x + v.x, y + v.y);
640 }
641
643 inline vector_type operator- (const vector_type& v) const {
644 return vector_type(x - v.x, y - v.y);
645 }
646
648 template <class T2>
649 inline vector_type operator* (T2 s) const {
650 return vector_type(x * T(s), y * T(s));
651 }
652
654 template <class T2>
655 inline vector_type operator/ (T2 s) const {
656 return vector_type(x / T(s), y / T(s));
657 }
658
660 inline vector_type operator- () const {
661 return vector_type(-x, -y);
662 }
663
666 return dim;
667 }
668
670 T* data() {
671 return &x;
672 }
673
675 const T* data() const {
676 return &x;
677 }
678
680 inline T& operator[] (index_t i) {
682 return data()[i];
683 }
684
686 inline const T& operator[] (index_t i) const {
688 return data()[i];
689 }
690
696
698 T x;
700 T y;
701 };
702
707 template <class T>
708 inline T dot(
709 const vecng<2, T>& v1, const vecng<2, T>& v2
710 ) {
711 return v1.x * v2.x + v1.y * v2.y;
712 }
713
721 template <class T>
722 inline T det(
723 const vecng<2, T>& v1, const vecng<2, T>& v2
724 ) {
725 return v1.x * v2.y - v1.y * v2.x;
726 }
727
732 template <class T2, class T>
733 inline vecng<2, T> operator* (
734 T2 s, const vecng<2, T>& v
735 ) {
736 return vecng<2, T>(T(s) * v.x, T(s) * v.y);
737 }
738
739 /************************************************************************/
740
745 template <class T>
746 class vecng<3, T> {
747 public:
749 static constexpr index_t dim = 3;
750
753
755 typedef T value_type;
756
759 x(T(0.0)),
760 y(T(0.0)),
761 z(T(0.0)) {
762 }
763
768 vecng(const T& x_in, const T& y_in, const T& z_in) :
769 x(x_in),
770 y(y_in),
771 z(z_in) {
772 }
773
778 vecng(T&& x_in, T&& y_in, T&& z_in) :
779 x(x_in),
780 y(y_in),
781 z(z_in) {
782 }
783
784 vecng(const vecng<3,T>& rhs) = default;
785 vecng(vecng<3,T>&& rhs) = default;
786
788 template <class T2>
789 explicit vecng(const vecng<dim, T2>& v) :
790 x(v.x),
791 y(v.y),
792 z(v.z) {
793 }
794
796 template <class T2>
797 explicit vecng(const T2* v) :
798 x(v[0]),
799 y(v[1]),
800 z(v[2]) {
801 }
802
804 vecng(const std::initializer_list<T>& Vi) {
805 index_t i = 0;
806 for(auto& it: Vi) {
808 data()[i] = it;
809 ++i;
810 }
811 }
812
813 vecng<3,T>& operator=(const vecng<3,T>& rhs) = default;
814 vecng<3,T>& operator=(vecng<3,T>&& rhs) = default;
815
817 inline T length2() const {
818 return x * x + y * y + z * z;
819 }
820
822 inline T length() const {
823 return sqrt(x * x + y * y + z * z);
824 }
825
827 inline T distance2(const vector_type& v) const {
828 T dx = v.x - x;
829 T dy = v.y - y;
830 T dz = v.z - z;
831 return dx * dx + dy * dy + dz * dz;
832 }
833
835 inline T distance(const vector_type& v) const {
836 return sqrt(distance2(v));
837 }
838
841 x += v.x;
842 y += v.y;
843 z += v.z;
844 return *this;
845 }
846
849 x -= v.x;
850 y -= v.y;
851 z -= v.z;
852 return *this;
853 }
854
856 template <class T2>
857 inline vector_type& operator*= (T2 s) {
858 x *= T(s);
859 y *= T(s);
860 z *= T(s);
861 return *this;
862 }
863
865 template <class T2>
866 inline vector_type& operator/= (T2 s) {
867 x /= T(s);
868 y /= T(s);
869 z /= T(s);
870 return *this;
871 }
872
874 inline vector_type operator+ (const vector_type& v) const {
875 return vector_type(x + v.x, y + v.y, z + v.z);
876 }
877
879 inline vector_type operator- (const vector_type& v) const {
880 return vector_type(x - v.x, y - v.y, z - v.z);
881 }
882
884 template <class T2>
885 inline vector_type operator* (T2 s) const {
886 return vector_type(x * T(s), y * T(s), z * T(s));
887 }
888
890 template <class T2>
891 inline vector_type operator/ (T2 s) const {
892 return vector_type(x / T(s), y / T(s), z / T(s));
893 }
894
896 inline vector_type operator- () const {
897 return vector_type(-x, -y, -z);
898 }
899
902 return dim;
903 }
904
906 T* data() {
907 return &x;
908 }
909
911 const T* data() const {
912 return &x;
913 }
914
916 inline T& operator[] (index_t i) {
918 return data()[i];
919 }
920
922 inline const T& operator[] (index_t i) const {
924 return data()[i];
925 }
926
933
935 T x;
937 T y;
939 T z;
940 };
941
946 template <class T>
947 inline T dot(
948 const vecng<3, T>& v1, const vecng<3, T>& v2
949 ) {
950 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
951 }
952
960 template <class T>
962 const vecng<3, T>& v1, const vecng<3, T>& v2
963 ) {
964 return vecng<3, T>(
965 det2x2(v1.y, v2.y, v1.z, v2.z),
966 det2x2(v1.z, v2.z, v1.x, v2.x),
967 det2x2(v1.x, v2.x, v1.y, v2.y)
968 );
969 }
970
975 template <class T2, class T>
976 inline vecng<3, T> operator* (
977 T2 s, const vecng<3, T>& v
978 ) {
979 return vecng<3, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z);
980 }
981
982 /************************************************************************/
983
988 template <class T>
989 class vecng<4, T> {
990 public:
992 static constexpr index_t dim = 4;
993
996
998 typedef T value_type;
999
1002 x(0),
1003 y(0),
1004 z(0),
1005 w(0) {
1006 }
1007
1012 vecng(const T& x_in, const T& y_in, const T& z_in, const T& w_in) :
1013 x(x_in),
1014 y(y_in),
1015 z(z_in),
1016 w(w_in) {
1017 }
1018
1023 vecng(T&& x_in, T&& y_in, T&& z_in, T&& w_in) :
1024 x(x_in),
1025 y(y_in),
1026 z(z_in),
1027 w(w_in) {
1028 }
1029
1030 vecng(const vecng<4,T>& rhs) = default;
1031 vecng(vecng<4,T>&& rhs) = default;
1032
1034 template <class T2>
1035 explicit vecng(const vecng<dim, T2>& v) :
1036 x(v.x),
1037 y(v.y),
1038 z(v.z),
1039 w(v.w) {
1040 }
1041
1043 template <class T2>
1044 explicit vecng(const T2* v) :
1045 x(v[0]),
1046 y(v[1]),
1047 z(v[2]),
1048 w(v[3]) {
1049 }
1050
1052 vecng(const std::initializer_list<T>& Vi) {
1053 index_t i = 0;
1054 for(auto& it: Vi) {
1055 geo_debug_assert(i < dim);
1056 data()[i] = it;
1057 ++i;
1058 }
1059 }
1060
1061 vecng<4,T>& operator=(const vecng<4,T>& rhs) = default;
1062 vecng<4,T>& operator=(vecng<4,T>&& rhs) = default;
1063
1065 inline T length2() const {
1066 return x * x + y * y + z * z + w * w;
1067 }
1068
1070 inline T length() const {
1071 return sqrt(x * x + y * y + z * z + w * w);
1072 }
1073
1075 inline T distance2(const vector_type& v) const {
1076 T dx = v.x - x;
1077 T dy = v.y - y;
1078 T dz = v.z - z;
1079 T dw = v.w - w;
1080 return dx * dx + dy * dy + dz * dz + dw * dw;
1081 }
1082
1084 inline T distance(const vector_type& v) const {
1085 return sqrt(distance2(v));
1086 }
1087
1090 return dim;
1091 }
1092
1095 x += v.x;
1096 y += v.y;
1097 z += v.z;
1098 w += v.w;
1099 return *this;
1100 }
1101
1104 x -= v.x;
1105 y -= v.y;
1106 z -= v.z;
1107 w -= v.w;
1108 return *this;
1109 }
1110
1112 template <class T2>
1113 inline vector_type& operator*= (T2 s) {
1114 x *= T(s);
1115 y *= T(s);
1116 z *= T(s);
1117 w *= T(s);
1118 return *this;
1119 }
1120
1122 template <class T2>
1123 inline vector_type& operator/= (T2 s) {
1124 x /= T(s);
1125 y /= T(s);
1126 z /= T(s);
1127 w /= T(s);
1128 return *this;
1129 }
1130
1132 inline vector_type operator+ (const vector_type& v) const {
1133 return vector_type(x + v.x, y + v.y, z + v.z, w + v.w);
1134 }
1135
1137 inline vector_type operator- (const vector_type& v) const {
1138 return vector_type(x - v.x, y - v.y, z - v.z, w - v.w);
1139 }
1140
1142 template <class T2>
1143 inline vector_type operator* (T2 s) const {
1144 return vector_type(x * T(s), y * T(s), z * T(s), w * T(s));
1145 }
1146
1148 template <class T2>
1149 inline vector_type operator/ (T2 s) const {
1150 return vector_type(x / T(s), y / T(s), z / T(s), w / T(s));
1151 }
1152
1154 inline vector_type operator- () const {
1155 return vector_type(-x, -y, -z, -w);
1156 }
1157
1159 T* data() {
1160 return &x;
1161 }
1162
1164 const T* data() const {
1165 return &x;
1166 }
1167
1169 inline T& operator[] (index_t i) {
1170 geo_debug_assert(i < dim);
1171 return data()[i];
1172 }
1173
1175 inline const T& operator[] (index_t i) const {
1176 geo_debug_assert(i < dim);
1177 return data()[i];
1178 }
1179
1181 T x;
1183 T y;
1185 T z;
1187 T w;
1188 };
1189
1194 template <class T>
1195 inline T dot(
1196 const vecng<4, T>& v1, const vecng<4, T>& v2
1197 ) {
1198 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
1199 }
1200
1205 template <class T2, class T>
1206 inline vecng<4, T> operator* (
1207 T2 s, const vecng<4, T>& v
1208 ) {
1209 return vecng<4, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z, T(s) * v.w);
1210 }
1211
1221 template <index_t DIM, class T>
1222 inline std::ostream& operator<< (
1223 std::ostream& out, const GEO::vecng<DIM, T>& v
1224 ) {
1225 const char* sep = "";
1226 for(index_t i = 0; i < DIM; i++) {
1227 out << sep << v[i];
1228 sep = " ";
1229 }
1230 return out;
1231 }
1232
1243 template <index_t DIM, class T>
1244 inline std::istream& operator>> (
1245 std::istream& in, GEO::vecng<DIM, T>& v
1246 ) {
1247 char c;
1248 while(isspace(in.peek())) {
1249 in.get(c);
1250 }
1251 if(in.peek() == '[' || in.peek() == '{') {
1252 in.get(c);
1253 }
1254 while(isspace(in.peek())) {
1255 in.get(c);
1256 }
1257 for(index_t i = 0; i < DIM; i++) {
1258 in >> v[i];
1259 while(isspace(in.peek())) {
1260 in.get(c);
1261 }
1262 if(in.peek() == ',') {
1263 in.get(c);
1264 }
1265 while(isspace(in.peek())) {
1266 in.get(c);
1267 }
1268 }
1269 if(in.peek() == ']' || in.peek() == '}') {
1270 in.get(c);
1271 }
1272 return in;
1273 }
1274
1275 /************************************************************************/
1276
1277 namespace Numeric {
1278
1279 template<class T>
1281 vecng<2,T>& v
1282 ) {
1283 v.optimize();
1284 }
1285
1286 template<class T>
1288 vecng<3,T>& v
1289 ) {
1290 v.optimize();
1291 }
1292
1293 }
1294
1295 /************************************************************************/
1296}
1297
1298#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:596
vecng(const T &x_in, const T &y_in)
Constructs a vector from coordinates.
Definition vecg.h:541
T distance(const vector_type &v) const
Definition vecg.h:603
T y
Vector y coordinate.
Definition vecg.h:700
T * data()
Gets modifiable vector data.
Definition vecg.h:670
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:665
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:675
void optimize()
Optimizes coordinate representation.
Definition vecg.h:692
T x
Vector x coordinate.
Definition vecg.h:698
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:560
T length() const
Gets the length of the vector.
Definition vecg.h:591
vecng(const std::initializer_list< T > &Vi)
Definition vecg.h:573
T value_type
The type of the vector coordinates.
Definition vecg.h:529
vecng(T &&x_in, T &&y_in)
Constructs a vector from coordinates.
Definition vecg.h:550
vecng()
Default vector constructor.
Definition vecg.h:532
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:567
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:526
T length2() const
Gets the squared length of the vector.
Definition vecg.h:586
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:789
T x
Vector x coordinate.
Definition vecg.h:935
void optimize()
Optimizes coordinate representation.
Definition vecg.h:928
vecng()
Default vector constructor.
Definition vecg.h:758
vecng(T &&x_in, T &&y_in, T &&z_in)
Constructs a vector from coordinates.
Definition vecg.h:778
T * data()
Gets modifiable vector data.
Definition vecg.h:906
T y
Vector y coordinate.
Definition vecg.h:937
T value_type
The type of the vector coordinates.
Definition vecg.h:755
T distance2(const vector_type &v) const
Definition vecg.h:827
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:911
T length2() const
Gets the squared length of the vector.
Definition vecg.h:817
T z
Vector z coordinate.
Definition vecg.h:939
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:797
vecng(const std::initializer_list< T > &Vi)
Definition vecg.h:804
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:752
T distance(const vector_type &v) const
Definition vecg.h:835
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:901
T length() const
Gets the length of the vector.
Definition vecg.h:822
vecng(const T &x_in, const T &y_in, const T &z_in)
Constructs a vector from coordinates.
Definition vecg.h:768
T distance2(const vector_type &v) const
Definition vecg.h:1075
vecng(const std::initializer_list< T > &Vi)
Definition vecg.h:1052
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:1012
T length2() const
Gets the squared length of the vector.
Definition vecg.h:1065
T w
Vector w coordinate.
Definition vecg.h:1187
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:995
T value_type
The type of the vector coordinates.
Definition vecg.h:998
vecng()
Default vector constructor.
Definition vecg.h:1001
T x
Vector x coordinate.
Definition vecg.h:1181
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:1164
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:1089
T y
Vector y coordinate.
Definition vecg.h:1183
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:1044
T z
Vector z coordinate.
Definition vecg.h:1185
T * data()
Gets modifiable vector data.
Definition vecg.h:1159
T length() const
Gets the length of the vector.
Definition vecg.h:1070
vecng(T &&x_in, T &&y_in, T &&z_in, T &&w_in)
Constructs a vector from coordinates.
Definition vecg.h:1023
T distance(const vector_type &v) const
Definition vecg.h:1084
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:1035
Generic maths vector.
Definition vecg.h:70
vector_type operator*(T2 s) const
Multiplies a vector by a scalar.
Definition vecg.h:337
T & operator[](index_t i)
Gets a modifiable vector coordinate.
Definition vecg.h:178
vector_type & operator-=(const vector_type &v)
Subtracts a vector in place.
Definition vecg.h:256
vecng< DIM, T > normalize(const vecng< DIM, T > &v)
Normalizes a vector.
Definition vecg.h:486
vecng< 3, T > cross(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the cross product of 2 vectors.
Definition vecg.h:961
T value_type
The type of the vector coordinates.
Definition vecg.h:79
T length2(const vecng< DIM, T > &v)
Gets the square norm of a vector.
Definition vecg.h:442
T det(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the determinant of 2 vectors.
Definition vecg.h:722
T distance2(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the square distance between 2 vectors.
Definition vecg.h:455
T length2() const
Gets the squared length of the vector.
Definition vecg.h:196
T * data()
Gets modifiable vector data.
Definition vecg.h:161
vector_type & operator/=(T2 s)
Divides by a scalar in place.
Definition vecg.h:290
T dot(const vecng< 4, T > &v1, const vecng< 4, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:1195
T length() const
Gets the length of the vector.
Definition vecg.h:207
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:169
T length(const vecng< DIM, T > &v)
Gets the norm of a vector.
Definition vecg.h:430
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:153
vector_type operator-() const
Negates a vector.
Definition vecg.h:368
vector_type & operator*=(T2 s)
Multiplies by a scalar in place.
Definition vecg.h:273
vector_type operator+(const vector_type &v) const
Adds 2 vectors.
Definition vecg.h:304
vector_type operator/(T2 s) const
Divides a vector by a scalar.
Definition vecg.h:355
vector_type & operator+=(const vector_type &v)
Adds a vector in place.
Definition vecg.h:242
vecng()
Default vector constructor.
Definition vecg.h:85
vecng< DIM, T > vector_type
This vector type.
Definition vecg.h:76
T dot(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:708
vecng< DIM, T > mix(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2, T s)
Computes a weighted barycenter.
Definition vecg.h:507
T distance(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the distance between 2 vectors.
Definition vecg.h:470
T distance(const vector_type &v) const
Gets the distance to a vector.
Definition vecg.h:229
vecng(const vecng< DIM, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:104
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
Definition vecg.h:216
vecng(const std::initializer_list< T > &Vi)
Constructs a vector from an initializer list.
Definition vecg.h:140
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:130
static constexpr index_t dim
The dimension of the vector.
Definition vecg.h:73
T dot(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:388
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:267
Global Vorpaline namespace.
Definition basic.h:55
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
Definition vecg.h:947
T geo_sqr(T x)
Gets the square value of a value.
Definition numeric.h:301
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:329
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Definition determinant.h:58
Types and functions for numbers manipulation.