Geogram Version 1.8.5
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
49#include <iostream>
50#include <cfloat>
51#include <cmath>
52
58namespace GEO {
59
68 template <index_t DIM, class T>
69 class vecng {
70 public:
72 static const index_t dim = DIM;
73
76
78 typedef T value_type;
79
85 for(index_t i = 0; i < DIM; i++) {
86 data_[i] = T(0);
87 }
88 }
89
90 // This one should never be called :
91 // a template constructor cannot be a copy constructor
92
102 template <class T2>
103 explicit vecng(const vecng<DIM, T2>& v) {
104 for(index_t i = 0; i < DIM; i++) {
105 data_[i] = T(v[i]);
106 }
107 }
108
109 // to avoid compilation problems
110 template <class T2, index_t DIM2>
111 explicit vecng(
112 const vecng<DIM2, T2>& v
113 ) {
114 geo_debug_assert(DIM2 == DIM);
115 for(index_t i = 0; i < DIM; i++) {
116 data_[i] = T(v[i]);
117 }
118 }
119
128 template <class T2>
129 explicit vecng(const T2* v) {
130 for(index_t i = 0; i < DIM; i++) {
131 data_[i] = T(v[i]);
132 }
133 }
134
140 return DIM;
141 }
142
147 T* data() {
148 return data_;
149 }
150
155 const T* data() const {
156 return data_;
157 }
158
164 inline T& operator[] (index_t i) {
165 geo_debug_assert(i < DIM);
166 return data()[i];
167 }
168
174 inline const T& operator[] (index_t i) const {
175 geo_debug_assert(i < DIM);
176 return data()[i];
177 }
178
182 inline T length2() const {
183 T result = T(0);
184 for(index_t i = 0; i < DIM; i++) {
185 result += data_[i] * data_[i];
186 }
187 return result;
188 }
189
193 inline T length() const {
194 return sqrt(length2());
195 }
196
202 inline T distance2(const vector_type& v) const {
203 T result(0);
204 for(index_t i = 0; i < DIM; i++) {
205 result += geo_sqr(v.data_[i] - data_[i]);
206 }
207 return result;
208 }
209
215 inline T distance(const vector_type& v) const {
216 return sqrt(distance2(v));
217 }
218
219 // operators
220
229 for(index_t i = 0; i < DIM; i++) {
230 data_[i] += v.data_[i];
231 }
232 return *this;
233 }
234
243 for(index_t i = 0; i < DIM; i++) {
244 data_[i] -= v.data_[i];
245 }
246 return *this;
247 }
248
258 template <class T2>
259 inline vector_type& operator*= (T2 s) {
260 for(index_t i = 0; i < DIM; i++) {
261 data_[i] *= T(s);
262 }
263 return *this;
264 }
265
275 template <class T2>
276 inline vector_type& operator/= (T2 s) {
277 for(index_t i = 0; i < DIM; i++) {
278 data_[i] /= T(s);
279 }
280 return *this;
281 }
282
290 inline vector_type operator+ (const vector_type& v) const {
291 vector_type result(*this);
292 for(index_t i = 0; i < DIM; i++) {
293 result.data_[i] += v.data_[i];
294 }
295 return result;
296 }
297
305 inline vector_type operator- (const vector_type& v) const {
306 vector_type result(*this);
307 for(index_t i = 0; i < DIM; i++) {
308 result.data_[i] -= v.data_[i];
309 }
310 return result;
311 }
312
322 template <class T2>
323 inline vector_type operator* (T2 s) const {
324 vector_type result(*this);
325 for(index_t i = 0; i < DIM; i++) {
326 result.data_[i] *= T(s);
327 }
328 return result;
329 }
330
340 template <class T2>
341 inline vector_type operator/ (T2 s) const {
342 vector_type result(*this);
343 for(index_t i = 0; i < DIM; i++) {
344 result.data_[i] /= T(s);
345 }
346 return result;
347 }
348
354 inline vector_type operator- () const {
355 vector_type result;
356 for(index_t i = 0; i < DIM; i++) {
357 result.data_[i] = -data_[i];
358 }
359 return result;
360 }
361
362 private:
363 T data_[DIM];
364 };
365
373 template <index_t DIM, class T>
374 inline T dot(
375 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
376 ) {
377 T result = 0;
378 for(index_t i = 0; i < DIM; i++) {
379 result += v1[i] * v2[i];
380 }
381 return result;
382 }
383
395 template <class T2, index_t DIM, class T>
397 T2 s, const vecng<DIM, T>& v
398 ) {
399 vecng<DIM, T> result;
400 for(index_t i = 0; i < DIM; i++) {
401 result[i] = T(s) * v[i];
402 }
403 return result;
404 }
405
406 // Compatibility with GLSL
407
415 template <index_t DIM, class T>
416 inline T length(const vecng<DIM, T>& v) {
417 return v.length();
418 }
419
427 template <index_t DIM, class T>
428 inline T length2(const vecng<DIM, T>& v) {
429 return v.length2();
430 }
431
440 template <index_t DIM, class T>
441 inline T distance2(
442 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
443 ) {
444 return v2.distance2(v1);
445 }
446
455 template <index_t DIM, class T>
456 inline T distance(
457 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2
458 ) {
459 return v2.distance(v1);
460 }
461
471 template <index_t DIM, class T>
473 const vecng<DIM, T>& v
474 ) {
475 T s = length(v);
476 if(s > 1e-30) {
477 s = T(1) / s;
478 }
479 return s * v;
480 }
481
492 template <index_t DIM, class T>
494 const vecng<DIM, T>& v1, const vecng<DIM, T>& v2, T s
495 ) {
496 return (T(1) - s) * v1 + s * v2;
497 }
498
499 /************************************************************************/
500
505 template <class T>
506 class vecng<2, T> {
507 public:
509 static const index_t dim = 2;
510
513
515 typedef T value_type;
516
519 x(0),
520 y(0) {
521 }
522
527 vecng(T x_in, T y_in) :
528 x(x_in),
529 y(y_in) {
530 }
531
533 template <class T2>
534 explicit vecng(const vecng<dim, T2>& v) :
535 x(v.x),
536 y(v.y) {
537 }
538
540 template <class T2>
541 explicit vecng(const T2* v) :
542 x(v[0]),
543 y(v[1]) {
544 }
545
547 inline T length2() const {
548 return x * x + y * y;
549 }
550
552 inline T length() const {
553 return sqrt(x * x + y * y);
554 }
555
557 inline T distance2(const vector_type& v) const {
558 T dx = v.x - x;
559 T dy = v.y - y;
560 return dx * dx + dy * dy;
561 }
562
564 inline T distance(const vector_type& v) const {
565 return sqrt(distance2(v));
566 }
567
570 x += v.x;
571 y += v.y;
572 return *this;
573 }
574
577 x -= v.x;
578 y -= v.y;
579 return *this;
580 }
581
583 template <class T2>
584 inline vector_type& operator*= (T2 s) {
585 x *= T(s);
586 y *= T(s);
587 return *this;
588 }
589
591 template <class T2>
592 inline vector_type& operator/= (T2 s) {
593 x /= T(s);
594 y /= T(s);
595 return *this;
596 }
597
599 inline vector_type operator+ (const vector_type& v) const {
600 return vector_type(x + v.x, y + v.y);
601 }
602
604 inline vector_type operator- (const vector_type& v) const {
605 return vector_type(x - v.x, y - v.y);
606 }
607
609 template <class T2>
610 inline vector_type operator* (T2 s) const {
611 return vector_type(x * T(s), y * T(s));
612 }
613
615 template <class T2>
616 inline vector_type operator/ (T2 s) const {
617 return vector_type(x / T(s), y / T(s));
618 }
619
621 inline vector_type operator- () const {
622 return vector_type(-x, -y);
623 }
624
627 return dim;
628 }
629
631 T* data() {
632 return &x;
633 }
634
636 const T* data() const {
637 return &x;
638 }
639
641 inline T& operator[] (index_t i) {
643 return data()[i];
644 }
645
647 inline const T& operator[] (index_t i) const {
649 return data()[i];
650 }
651
653 T x;
655 T y;
656 };
657
662 template <class T>
663 inline T dot(
664 const vecng<2, T>& v1, const vecng<2, T>& v2
665 ) {
666 return v1.x * v2.x + v1.y * v2.y;
667 }
668
676 template <class T>
677 inline T det(
678 const vecng<2, T>& v1, const vecng<2, T>& v2
679 ) {
680 return v1.x * v2.y - v1.y * v2.x;
681 }
682
687 template <class T2, class T>
689 T2 s, const vecng<2, T>& v
690 ) {
691 return vecng<2, T>(T(s) * v.x, T(s) * v.y);
692 }
693
694 /************************************************************************/
695
700 template <class T>
701 class vecng<3, T> {
702 public:
704 static const index_t dim = 3;
705
708
710 typedef T value_type;
711
714 x(T(0.0)),
715 y(T(0.0)),
716 z(T(0.0)) {
717 }
718
723 vecng(T x_in, T y_in, T z_in) :
724 x(x_in),
725 y(y_in),
726 z(z_in) {
727 }
728
730 template <class T2>
731 explicit vecng(const vecng<dim, T2>& v) :
732 x(v.x),
733 y(v.y),
734 z(v.z) {
735 }
736
738 template <class T2>
739 explicit vecng(const T2* v) :
740 x(v[0]),
741 y(v[1]),
742 z(v[2]) {
743 }
744
746 inline T length2() const {
747 return x * x + y * y + z * z;
748 }
749
751 inline T length() const {
752 return sqrt(x * x + y * y + z * z);
753 }
754
756 inline T distance2(const vector_type& v) const {
757 T dx = v.x - x;
758 T dy = v.y - y;
759 T dz = v.z - z;
760 return dx * dx + dy * dy + dz * dz;
761 }
762
764 inline T distance(const vector_type& v) const {
765 return sqrt(distance2(v));
766 }
767
770 x += v.x;
771 y += v.y;
772 z += v.z;
773 return *this;
774 }
775
778 x -= v.x;
779 y -= v.y;
780 z -= v.z;
781 return *this;
782 }
783
785 template <class T2>
786 inline vector_type& operator*= (T2 s) {
787 x *= T(s);
788 y *= T(s);
789 z *= T(s);
790 return *this;
791 }
792
794 template <class T2>
795 inline vector_type& operator/= (T2 s) {
796 x /= T(s);
797 y /= T(s);
798 z /= T(s);
799 return *this;
800 }
801
803 inline vector_type operator+ (const vector_type& v) const {
804 return vector_type(x + v.x, y + v.y, z + v.z);
805 }
806
808 inline vector_type operator- (const vector_type& v) const {
809 return vector_type(x - v.x, y - v.y, z - v.z);
810 }
811
813 template <class T2>
814 inline vector_type operator* (T2 s) const {
815 return vector_type(x * T(s), y * T(s), z * T(s));
816 }
817
819 template <class T2>
820 inline vector_type operator/ (T2 s) const {
821 return vector_type(x / T(s), y / T(s), z / T(s));
822 }
823
825 inline vector_type operator- () const {
826 return vector_type(-x, -y, -z);
827 }
828
831 return dim;
832 }
833
835 T* data() {
836 return &x;
837 }
838
840 const T* data() const {
841 return &x;
842 }
843
845 inline T& operator[] (index_t i) {
847 return data()[i];
848 }
849
851 inline const T& operator[] (index_t i) const {
853 return data()[i];
854 }
855
857 T x;
859 T y;
861 T z;
862 };
863
868 template <class T>
869 inline T dot(
870 const vecng<3, T>& v1, const vecng<3, T>& v2
871 ) {
872 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
873 }
874
882 template <class T>
884 const vecng<3, T>& v1, const vecng<3, T>& v2
885 ) {
886 return vecng<3, T>(
887 det2x2(v1.y, v2.y, v1.z, v2.z),
888 det2x2(v1.z, v2.z, v1.x, v2.x),
889 det2x2(v1.x, v2.x, v1.y, v2.y)
890 );
891 }
892
897 template <class T2, class T>
899 T2 s, const vecng<3, T>& v
900 ) {
901 return vecng<3, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z);
902 }
903
904 /************************************************************************/
905
910 template <class T>
911 class vecng<4, T> {
912 public:
914 static const index_t dim = 4;
915
918
920 typedef T value_type;
921
924 x(0),
925 y(0),
926 z(0),
927 w(0) {
928 }
929
934 vecng(T x_in, T y_in, T z_in, T w_in) :
935 x(x_in),
936 y(y_in),
937 z(z_in),
938 w(w_in) {
939 }
940
942 template <class T2>
943 explicit vecng(const vecng<dim, T2>& v) :
944 x(v.x),
945 y(v.y),
946 z(v.z),
947 w(v.w) {
948 }
949
951 template <class T2>
952 explicit vecng(const T2* v) :
953 x(v[0]),
954 y(v[1]),
955 z(v[2]),
956 w(v[3]) {
957 }
958
960 inline T length2() const {
961 return x * x + y * y + z * z + w * w;
962 }
963
965 inline T length() const {
966 return sqrt(x * x + y * y + z * z + w * w);
967 }
968
970 inline T distance2(const vector_type& v) const {
971 T dx = v.x - x;
972 T dy = v.y - y;
973 T dz = v.z - z;
974 T dw = v.w - w;
975 return dx * dx + dy * dy + dz * dz + dw * dw;
976 }
977
979 inline T distance(const vector_type& v) const {
980 return sqrt(distance2(v));
981 }
982
985 return dim;
986 }
987
990 x += v.x;
991 y += v.y;
992 z += v.z;
993 w += v.w;
994 return *this;
995 }
996
999 x -= v.x;
1000 y -= v.y;
1001 z -= v.z;
1002 w -= v.w;
1003 return *this;
1004 }
1005
1007 template <class T2>
1008 inline vector_type& operator*= (T2 s) {
1009 x *= T(s);
1010 y *= T(s);
1011 z *= T(s);
1012 w *= T(s);
1013 return *this;
1014 }
1015
1017 template <class T2>
1018 inline vector_type& operator/= (T2 s) {
1019 x /= T(s);
1020 y /= T(s);
1021 z /= T(s);
1022 w /= T(s);
1023 return *this;
1024 }
1025
1027 inline vector_type operator+ (const vector_type& v) const {
1028 return vector_type(x + v.x, y + v.y, z + v.z, w + v.w);
1029 }
1030
1032 inline vector_type operator- (const vector_type& v) const {
1033 return vector_type(x - v.x, y - v.y, z - v.z, w - v.w);
1034 }
1035
1037 template <class T2>
1038 inline vector_type operator* (T2 s) const {
1039 return vector_type(x * T(s), y * T(s), z * T(s), w * T(s));
1040 }
1041
1043 template <class T2>
1044 inline vector_type operator/ (T2 s) const {
1045 return vector_type(x / T(s), y / T(s), z / T(s), w / T(s));
1046 }
1047
1049 inline vector_type operator- () const {
1050 return vector_type(-x, -y, -z, -w);
1051 }
1052
1054 T* data() {
1055 return &x;
1056 }
1057
1059 const T* data() const {
1060 return &x;
1061 }
1062
1064 inline T& operator[] (index_t i) {
1065 geo_debug_assert(i < dim);
1066 return data()[i];
1067 }
1068
1070 inline const T& operator[] (index_t i) const {
1071 geo_debug_assert(i < dim);
1072 return data()[i];
1073 }
1074
1076 T x;
1078 T y;
1080 T z;
1082 T w;
1083 };
1084
1089 template <class T>
1090 inline T dot(
1091 const vecng<4, T>& v1, const vecng<4, T>& v2
1092 ) {
1093 return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
1094 }
1095
1100 template <class T2, class T>
1102 T2 s, const vecng<4, T>& v
1103 ) {
1104 return vecng<4, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z, T(s) * v.w);
1105 }
1106
1116 template <index_t DIM, class T>
1117 inline std::ostream& operator<< (
1118 std::ostream& out, const GEO::vecng<DIM, T>& v
1119 ) {
1120 const char* sep = "";
1121 for(index_t i = 0; i < DIM; i++) {
1122 out << sep << v[i];
1123 sep = " ";
1124 }
1125 return out;
1126 }
1127
1137 template <index_t DIM, class T>
1138 inline std::istream& operator>> (
1139 std::istream& in, GEO::vecng<DIM, T>& v
1140 ) {
1141 for(index_t i = 0; i < DIM; i++) {
1142 in >> v[i];
1143 }
1144 return in;
1145 }
1146}
1147
1148#endif
1149
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition assert.h:195
Common include file, providing basic definitions. Should be included before anything else by all head...
T distance2(const vector_type &v) const
Definition vecg.h:557
vecng(T x_in, T y_in)
Constructs a vector from coordinates.
Definition vecg.h:527
T distance(const vector_type &v) const
Definition vecg.h:564
T y
Vector y coordinate.
Definition vecg.h:655
T * data()
Gets modifiable vector data.
Definition vecg.h:631
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:626
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:636
T x
Vector x coordinate.
Definition vecg.h:653
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:534
T length() const
Gets the length of the vector.
Definition vecg.h:552
T value_type
The type of the vector coordinates.
Definition vecg.h:515
vecng()
Default vector constructor.
Definition vecg.h:518
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:541
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:512
T length2() const
Gets the squared length of the vector.
Definition vecg.h:547
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:731
T x
Vector x coordinate.
Definition vecg.h:857
vecng()
Default vector constructor.
Definition vecg.h:713
T * data()
Gets modifiable vector data.
Definition vecg.h:835
T y
Vector y coordinate.
Definition vecg.h:859
T value_type
The type of the vector coordinates.
Definition vecg.h:710
T distance2(const vector_type &v) const
Definition vecg.h:756
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:840
T length2() const
Gets the squared length of the vector.
Definition vecg.h:746
T z
Vector z coordinate.
Definition vecg.h:861
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:739
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:707
vecng(T x_in, T y_in, T z_in)
Constructs a vector from coordinates.
Definition vecg.h:723
T distance(const vector_type &v) const
Definition vecg.h:764
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:830
T length() const
Gets the length of the vector.
Definition vecg.h:751
T distance2(const vector_type &v) const
Definition vecg.h:970
T length2() const
Gets the squared length of the vector.
Definition vecg.h:960
T w
Vector w coordinate.
Definition vecg.h:1082
vecng(T x_in, T y_in, T z_in, T w_in)
Constructs a vector from coordinates.
Definition vecg.h:934
vecng< dim, T > vector_type
This vector type.
Definition vecg.h:917
T value_type
The type of the vector coordinates.
Definition vecg.h:920
vecng()
Default vector constructor.
Definition vecg.h:923
T x
Vector x coordinate.
Definition vecg.h:1076
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:1059
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:984
T y
Vector y coordinate.
Definition vecg.h:1078
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:952
T z
Vector z coordinate.
Definition vecg.h:1080
T * data()
Gets modifiable vector data.
Definition vecg.h:1054
T length() const
Gets the length of the vector.
Definition vecg.h:965
T distance(const vector_type &v) const
Definition vecg.h:979
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:943
Generic maths vector.
Definition vecg.h:69
vector_type operator*(T2 s) const
Multiplies a vector by a scalar.
Definition vecg.h:323
T & operator[](index_t i)
Gets a modifiable vector coordinate.
Definition vecg.h:164
vector_type & operator-=(const vector_type &v)
Subtracts a vector in place.
Definition vecg.h:242
vecng< DIM, T > normalize(const vecng< DIM, T > &v)
Normalizes a vector.
Definition vecg.h:472
vecng< 3, T > cross(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the cross product of 2 vectors.
Definition vecg.h:883
T value_type
The type of the vector coordinates.
Definition vecg.h:78
T length2(const vecng< DIM, T > &v)
Gets the square norm of a vector.
Definition vecg.h:428
T det(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the determinant of 2 vectors.
Definition vecg.h:677
T distance2(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the square distance between 2 vectors.
Definition vecg.h:441
T length2() const
Gets the squared length of the vector.
Definition vecg.h:182
T * data()
Gets modifiable vector data.
Definition vecg.h:147
vector_type & operator/=(T2 s)
Divides by a scalar in place.
Definition vecg.h:276
T dot(const vecng< 4, T > &v1, const vecng< 4, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:1090
T length() const
Gets the length of the vector.
Definition vecg.h:193
const T * data() const
Gets non-modifiable vector data.
Definition vecg.h:155
T length(const vecng< DIM, T > &v)
Gets the norm of a vector.
Definition vecg.h:416
index_t dimension() const
Gets the vector dimension.
Definition vecg.h:139
vector_type operator-() const
Negates a vector.
Definition vecg.h:354
vector_type & operator*=(T2 s)
Multiplies by a scalar in place.
Definition vecg.h:259
vector_type operator+(const vector_type &v) const
Adds 2 vectors.
Definition vecg.h:290
vector_type operator/(T2 s) const
Divides a vector by a scalar.
Definition vecg.h:341
vector_type & operator+=(const vector_type &v)
Adds a vector in place.
Definition vecg.h:228
vecng()
Default vector constructor.
Definition vecg.h:84
vecng< DIM, T > vector_type
This vector type.
Definition vecg.h:75
T dot(const vecng< 2, T > &v1, const vecng< 2, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:663
vecng< DIM, T > mix(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2, T s)
Computes a weighted barycenter.
Definition vecg.h:493
T distance(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Gets the distance between 2 vectors.
Definition vecg.h:456
T distance(const vector_type &v) const
Gets the distance to a vector.
Definition vecg.h:215
vecng(const vecng< DIM, T2 > &v)
Constructs a vector by copy.
Definition vecg.h:103
static const index_t dim
The dimension of the vector.
Definition vecg.h:72
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
Definition vecg.h:202
vecng(const T2 *v)
Constructs a vector from an array.
Definition vecg.h:129
T dot(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Computes the dot product of 2 vectors.
Definition vecg.h:374
Determinants for small sizes.
Types and functions for memory manipulation.
Global Vorpaline namespace.
Definition algorithm.h:64
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors. vecng
Definition vecg.h:869
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:259
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:287
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:516
Types and functions for numbers manipulation.