Graphite  Version 3
An experimental 3D geometry processing program
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 
43 #include <geogram/basic/common.h>
44 #include <geogram/basic/numeric.h>
46 #include <geogram/basic/memory.h>
47 #include <geogram/basic/assert.h>
48 #include <initializer_list>
49 
50 #include <iostream>
51 #include <cfloat>
52 #include <cmath>
53 
59 namespace GEO {
60 
69  template <index_t DIM, class T>
70  class vecng {
71  public:
73  static const index_t dim = DIM;
74 
77 
79  typedef T value_type;
80 
85  vecng() {
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 
153  index_t dimension() const {
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 
242  inline vector_type& operator+= (const vector_type& v) {
243  for(index_t i = 0; i < DIM; i++) {
244  data_[i] += v.data_[i];
245  }
246  return *this;
247  }
248 
256  inline vector_type& operator-= (const vector_type& v) {
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>
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 const index_t dim = 2;
524 
527 
529  typedef T value_type;
530 
532  vecng() :
533  x(0),
534  y(0) {
535  }
536 
541  vecng(T x_in, T y_in) :
542  x(x_in),
543  y(y_in) {
544  }
545 
547  template <class T2>
548  explicit vecng(const vecng<dim, T2>& v) :
549  x(v.x),
550  y(v.y) {
551  }
552 
554  template <class T2>
555  explicit vecng(const T2* v) :
556  x(v[0]),
557  y(v[1]) {
558  }
559 
561  vecng(const std::initializer_list<T>& Vi) {
562  index_t i = 0;
563  for(auto& it: Vi) {
564  geo_debug_assert(i < dim);
565  data()[i] = it;
566  ++i;
567  }
568  }
569 
571  inline T length2() const {
572  return x * x + y * y;
573  }
574 
576  inline T length() const {
577  return sqrt(x * x + y * y);
578  }
579 
581  inline T distance2(const vector_type& v) const {
582  T dx = v.x - x;
583  T dy = v.y - y;
584  return dx * dx + dy * dy;
585  }
586 
588  inline T distance(const vector_type& v) const {
589  return sqrt(distance2(v));
590  }
591 
593  inline vector_type& operator+= (const vector_type& v) {
594  x += v.x;
595  y += v.y;
596  return *this;
597  }
598 
600  inline vector_type& operator-= (const vector_type& v) {
601  x -= v.x;
602  y -= v.y;
603  return *this;
604  }
605 
607  template <class T2>
608  inline vector_type& operator*= (T2 s) {
609  x *= T(s);
610  y *= T(s);
611  return *this;
612  }
613 
615  template <class T2>
616  inline vector_type& operator/= (T2 s) {
617  x /= T(s);
618  y /= T(s);
619  return *this;
620  }
621 
623  inline vector_type operator+ (const vector_type& v) const {
624  return vector_type(x + v.x, y + v.y);
625  }
626 
628  inline vector_type operator- (const vector_type& v) const {
629  return vector_type(x - v.x, y - v.y);
630  }
631 
633  template <class T2>
634  inline vector_type operator* (T2 s) const {
635  return vector_type(x * T(s), y * T(s));
636  }
637 
639  template <class T2>
640  inline vector_type operator/ (T2 s) const {
641  return vector_type(x / T(s), y / T(s));
642  }
643 
645  inline vector_type operator- () const {
646  return vector_type(-x, -y);
647  }
648 
650  index_t dimension() const {
651  return dim;
652  }
653 
655  T* data() {
656  return &x;
657  }
658 
660  const T* data() const {
661  return &x;
662  }
663 
665  inline T& operator[] (index_t i) {
666  geo_debug_assert(i < dim);
667  return data()[i];
668  }
669 
671  inline const T& operator[] (index_t i) const {
672  geo_debug_assert(i < dim);
673  return data()[i];
674  }
675 
677  void optimize() {
680  }
681 
683  T x;
685  T y;
686  };
687 
692  template <class T>
693  inline T dot(
694  const vecng<2, T>& v1, const vecng<2, T>& v2
695  ) {
696  return v1.x * v2.x + v1.y * v2.y;
697  }
698 
706  template <class T>
707  inline T det(
708  const vecng<2, T>& v1, const vecng<2, T>& v2
709  ) {
710  return v1.x * v2.y - v1.y * v2.x;
711  }
712 
717  template <class T2, class T>
719  T2 s, const vecng<2, T>& v
720  ) {
721  return vecng<2, T>(T(s) * v.x, T(s) * v.y);
722  }
723 
724  /************************************************************************/
725 
730  template <class T>
731  class vecng<3, T> {
732  public:
734  static const index_t dim = 3;
735 
738 
740  typedef T value_type;
741 
743  vecng() :
744  x(T(0.0)),
745  y(T(0.0)),
746  z(T(0.0)) {
747  }
748 
753  vecng(T x_in, T y_in, T z_in) :
754  x(x_in),
755  y(y_in),
756  z(z_in) {
757  }
758 
760  template <class T2>
761  explicit vecng(const vecng<dim, T2>& v) :
762  x(v.x),
763  y(v.y),
764  z(v.z) {
765  }
766 
768  template <class T2>
769  explicit vecng(const T2* v) :
770  x(v[0]),
771  y(v[1]),
772  z(v[2]) {
773  }
774 
776  vecng(const std::initializer_list<T>& Vi) {
777  index_t i = 0;
778  for(auto& it: Vi) {
779  geo_debug_assert(i < dim);
780  data()[i] = it;
781  ++i;
782  }
783  }
784 
786  inline T length2() const {
787  return x * x + y * y + z * z;
788  }
789 
791  inline T length() const {
792  return sqrt(x * x + y * y + z * z);
793  }
794 
796  inline T distance2(const vector_type& v) const {
797  T dx = v.x - x;
798  T dy = v.y - y;
799  T dz = v.z - z;
800  return dx * dx + dy * dy + dz * dz;
801  }
802 
804  inline T distance(const vector_type& v) const {
805  return sqrt(distance2(v));
806  }
807 
809  inline vector_type& operator+= (const vector_type& v) {
810  x += v.x;
811  y += v.y;
812  z += v.z;
813  return *this;
814  }
815 
817  inline vector_type& operator-= (const vector_type& v) {
818  x -= v.x;
819  y -= v.y;
820  z -= v.z;
821  return *this;
822  }
823 
825  template <class T2>
826  inline vector_type& operator*= (T2 s) {
827  x *= T(s);
828  y *= T(s);
829  z *= T(s);
830  return *this;
831  }
832 
834  template <class T2>
835  inline vector_type& operator/= (T2 s) {
836  x /= T(s);
837  y /= T(s);
838  z /= T(s);
839  return *this;
840  }
841 
843  inline vector_type operator+ (const vector_type& v) const {
844  return vector_type(x + v.x, y + v.y, z + v.z);
845  }
846 
848  inline vector_type operator- (const vector_type& v) const {
849  return vector_type(x - v.x, y - v.y, z - v.z);
850  }
851 
853  template <class T2>
854  inline vector_type operator* (T2 s) const {
855  return vector_type(x * T(s), y * T(s), z * T(s));
856  }
857 
859  template <class T2>
860  inline vector_type operator/ (T2 s) const {
861  return vector_type(x / T(s), y / T(s), z / T(s));
862  }
863 
865  inline vector_type operator- () const {
866  return vector_type(-x, -y, -z);
867  }
868 
870  index_t dimension() const {
871  return dim;
872  }
873 
875  T* data() {
876  return &x;
877  }
878 
880  const T* data() const {
881  return &x;
882  }
883 
885  inline T& operator[] (index_t i) {
886  geo_debug_assert(i < dim);
887  return data()[i];
888  }
889 
891  inline const T& operator[] (index_t i) const {
892  geo_debug_assert(i < dim);
893  return data()[i];
894  }
895 
897  void optimize() {
901  }
902 
904  T x;
906  T y;
908  T z;
909  };
910 
915  template <class T>
916  inline T dot(
917  const vecng<3, T>& v1, const vecng<3, T>& v2
918  ) {
919  return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
920  }
921 
929  template <class T>
931  const vecng<3, T>& v1, const vecng<3, T>& v2
932  ) {
933  return vecng<3, T>(
934  det2x2(v1.y, v2.y, v1.z, v2.z),
935  det2x2(v1.z, v2.z, v1.x, v2.x),
936  det2x2(v1.x, v2.x, v1.y, v2.y)
937  );
938  }
939 
944  template <class T2, class T>
946  T2 s, const vecng<3, T>& v
947  ) {
948  return vecng<3, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z);
949  }
950 
951  /************************************************************************/
952 
957  template <class T>
958  class vecng<4, T> {
959  public:
961  static const index_t dim = 4;
962 
965 
967  typedef T value_type;
968 
970  vecng() :
971  x(0),
972  y(0),
973  z(0),
974  w(0) {
975  }
976 
981  vecng(T x_in, T y_in, T z_in, T w_in) :
982  x(x_in),
983  y(y_in),
984  z(z_in),
985  w(w_in) {
986  }
987 
989  template <class T2>
990  explicit vecng(const vecng<dim, T2>& v) :
991  x(v.x),
992  y(v.y),
993  z(v.z),
994  w(v.w) {
995  }
996 
998  template <class T2>
999  explicit vecng(const T2* v) :
1000  x(v[0]),
1001  y(v[1]),
1002  z(v[2]),
1003  w(v[3]) {
1004  }
1005 
1007  vecng(const std::initializer_list<T>& Vi) {
1008  index_t i = 0;
1009  for(auto& it: Vi) {
1010  geo_debug_assert(i < dim);
1011  data()[i] = it;
1012  ++i;
1013  }
1014  }
1015 
1017  inline T length2() const {
1018  return x * x + y * y + z * z + w * w;
1019  }
1020 
1022  inline T length() const {
1023  return sqrt(x * x + y * y + z * z + w * w);
1024  }
1025 
1027  inline T distance2(const vector_type& v) const {
1028  T dx = v.x - x;
1029  T dy = v.y - y;
1030  T dz = v.z - z;
1031  T dw = v.w - w;
1032  return dx * dx + dy * dy + dz * dz + dw * dw;
1033  }
1034 
1036  inline T distance(const vector_type& v) const {
1037  return sqrt(distance2(v));
1038  }
1039 
1041  index_t dimension() const {
1042  return dim;
1043  }
1044 
1047  x += v.x;
1048  y += v.y;
1049  z += v.z;
1050  w += v.w;
1051  return *this;
1052  }
1053 
1056  x -= v.x;
1057  y -= v.y;
1058  z -= v.z;
1059  w -= v.w;
1060  return *this;
1061  }
1062 
1064  template <class T2>
1065  inline vector_type& operator*= (T2 s) {
1066  x *= T(s);
1067  y *= T(s);
1068  z *= T(s);
1069  w *= T(s);
1070  return *this;
1071  }
1072 
1074  template <class T2>
1075  inline vector_type& operator/= (T2 s) {
1076  x /= T(s);
1077  y /= T(s);
1078  z /= T(s);
1079  w /= T(s);
1080  return *this;
1081  }
1082 
1084  inline vector_type operator+ (const vector_type& v) const {
1085  return vector_type(x + v.x, y + v.y, z + v.z, w + v.w);
1086  }
1087 
1089  inline vector_type operator- (const vector_type& v) const {
1090  return vector_type(x - v.x, y - v.y, z - v.z, w - v.w);
1091  }
1092 
1094  template <class T2>
1095  inline vector_type operator* (T2 s) const {
1096  return vector_type(x * T(s), y * T(s), z * T(s), w * T(s));
1097  }
1098 
1100  template <class T2>
1101  inline vector_type operator/ (T2 s) const {
1102  return vector_type(x / T(s), y / T(s), z / T(s), w / T(s));
1103  }
1104 
1106  inline vector_type operator- () const {
1107  return vector_type(-x, -y, -z, -w);
1108  }
1109 
1111  T* data() {
1112  return &x;
1113  }
1114 
1116  const T* data() const {
1117  return &x;
1118  }
1119 
1121  inline T& operator[] (index_t i) {
1122  geo_debug_assert(i < dim);
1123  return data()[i];
1124  }
1125 
1127  inline const T& operator[] (index_t i) const {
1128  geo_debug_assert(i < dim);
1129  return data()[i];
1130  }
1131 
1133  T x;
1135  T y;
1137  T z;
1139  T w;
1140  };
1141 
1146  template <class T>
1147  inline T dot(
1148  const vecng<4, T>& v1, const vecng<4, T>& v2
1149  ) {
1150  return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z + v1.w * v2.w;
1151  }
1152 
1157  template <class T2, class T>
1159  T2 s, const vecng<4, T>& v
1160  ) {
1161  return vecng<4, T>(T(s) * v.x, T(s) * v.y, T(s) * v.z, T(s) * v.w);
1162  }
1163 
1173  template <index_t DIM, class T>
1174  inline std::ostream& operator<< (
1175  std::ostream& out, const GEO::vecng<DIM, T>& v
1176  ) {
1177  const char* sep = "";
1178  for(index_t i = 0; i < DIM; i++) {
1179  out << sep << v[i];
1180  sep = " ";
1181  }
1182  return out;
1183  }
1184 
1195  template <index_t DIM, class T>
1196  inline std::istream& operator>> (
1197  std::istream& in, GEO::vecng<DIM, T>& v
1198  ) {
1199  char c;
1200  while(isspace(in.peek())) {
1201  in.get(c);
1202  }
1203  if(in.peek() == '[') {
1204  in.get(c);
1205  }
1206  while(isspace(in.peek())) {
1207  in.get(c);
1208  }
1209  for(index_t i = 0; i < DIM; i++) {
1210  in >> v[i];
1211  while(isspace(in.peek())) {
1212  in.get(c);
1213  }
1214  if(in.peek() == ',') {
1215  in.get(c);
1216  }
1217  while(isspace(in.peek())) {
1218  in.get(c);
1219  }
1220  }
1221  if(in.peek() == ']') {
1222  in.get(c);
1223  }
1224  return in;
1225  }
1226 
1227  /************************************************************************/
1228 
1229  namespace Numeric {
1230 
1231  template<class T>
1232  inline void optimize_number_representation(
1233  vecng<2,T>& v
1234  ) {
1235  v.optimize();
1236  }
1237 
1238  template<class T>
1239  inline void optimize_number_representation(
1240  vecng<3,T>& v
1241  ) {
1242  v.optimize();
1243  }
1244 
1245  }
1246 
1247  /************************************************************************/
1248 
1249 }
1250 
1251 #endif
Assertion checking mechanism.
#define geo_debug_assert(x)
Verifies that a condition is met.
Definition: assert.h:196
Specialization of class vecng for DIM == 2.
Definition: vecg.h:520
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
Definition: vecg.h:581
vecng(T x_in, T y_in)
Constructs a vector from coordinates.
Definition: vecg.h:541
T distance(const vector_type &v) const
Gets the distance to a vector.
Definition: vecg.h:588
T y
Vector y coordinate.
Definition: vecg.h:685
index_t dimension() const
Gets the vector dimension.
Definition: vecg.h:650
const T * data() const
Gets non-modifiable vector data.
Definition: vecg.h:660
void optimize()
Optimizes coordinate representation.
Definition: vecg.h:677
T x
Vector x coordinate.
Definition: vecg.h:683
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition: vecg.h:548
T length() const
Gets the length of the vector.
Definition: vecg.h:576
vecng(const std::initializer_list< T > &Vi)
Definition: vecg.h:561
T value_type
The type of the vector coordinates.
Definition: vecg.h:529
vecng()
Default vector constructor.
Definition: vecg.h:532
vecng(const T2 *v)
Constructs a vector from an array.
Definition: vecg.h:555
T * data()
Gets modifiable vector data.
Definition: vecg.h:655
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:571
Specialization of class vecng for DIM == 3.
Definition: vecg.h:731
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition: vecg.h:761
T x
Vector x coordinate.
Definition: vecg.h:904
void optimize()
Optimizes coordinate representation.
Definition: vecg.h:897
vecng()
Default vector constructor.
Definition: vecg.h:743
T y
Vector y coordinate.
Definition: vecg.h:906
T value_type
The type of the vector coordinates.
Definition: vecg.h:740
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
Definition: vecg.h:796
T length2() const
Gets the squared length of the vector.
Definition: vecg.h:786
T z
Vector z coordinate.
Definition: vecg.h:908
const T * data() const
Gets non-modifiable vector data.
Definition: vecg.h:880
vecng(const T2 *v)
Constructs a vector from an array.
Definition: vecg.h:769
vecng(const std::initializer_list< T > &Vi)
Definition: vecg.h:776
vecng< dim, T > vector_type
This vector type.
Definition: vecg.h:737
vecng(T x_in, T y_in, T z_in)
Constructs a vector from coordinates.
Definition: vecg.h:753
T distance(const vector_type &v) const
Gets the distance to a vector.
Definition: vecg.h:804
index_t dimension() const
Gets the vector dimension.
Definition: vecg.h:870
T length() const
Gets the length of the vector.
Definition: vecg.h:791
T * data()
Gets modifiable vector data.
Definition: vecg.h:875
Specialization of class vecn3 for DIM == 4.
Definition: vecg.h:958
const T * data() const
Gets non-modifiable vector data.
Definition: vecg.h:1116
T distance2(const vector_type &v) const
Gets the squared distance to a vector.
Definition: vecg.h:1027
vecng(const std::initializer_list< T > &Vi)
Definition: vecg.h:1007
T length2() const
Gets the squared length of the vector.
Definition: vecg.h:1017
T w
Vector w coordinate.
Definition: vecg.h:1139
vecng(T x_in, T y_in, T z_in, T w_in)
Constructs a vector from coordinates.
Definition: vecg.h:981
vecng< dim, T > vector_type
This vector type.
Definition: vecg.h:964
T value_type
The type of the vector coordinates.
Definition: vecg.h:967
vecng()
Default vector constructor.
Definition: vecg.h:970
T x
Vector x coordinate.
Definition: vecg.h:1133
index_t dimension() const
Gets the vector dimension.
Definition: vecg.h:1041
T y
Vector y coordinate.
Definition: vecg.h:1135
vecng(const T2 *v)
Constructs a vector from an array.
Definition: vecg.h:999
T * data()
Gets modifiable vector data.
Definition: vecg.h:1111
T z
Vector z coordinate.
Definition: vecg.h:1137
T length() const
Gets the length of the vector.
Definition: vecg.h:1022
T distance(const vector_type &v) const
Gets the distance to a vector.
Definition: vecg.h:1036
vecng(const vecng< dim, T2 > &v)
Constructs a vector by copy.
Definition: vecg.h:990
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
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:930
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:707
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 dot(const vecng< 4, T > &v1, const vecng< 4, T > &v2)
Computes the dot product of 2 vectors.
Definition: vecg.h:1147
T length() const
Gets the length of the vector.
Definition: vecg.h:207
T dot(const vecng< 3, T > &v1, const vecng< 3, T > &v2)
Computes the dot product of 2 vectors.
Definition: vecg.h:916
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+(const vector_type &v) const
Adds 2 vectors.
Definition: vecg.h:304
vector_type & operator+=(const vector_type &v)
Adds a vector in place.
Definition: vecg.h:242
T * data()
Gets modifiable vector data.
Definition: vecg.h:161
const T * data() const
Gets non-modifiable vector data.
Definition: vecg.h:169
vector_type operator/(T2 s) const
Divides a vector by a scalar.
Definition: vecg.h:355
vector_type & operator*=(T2 s)
Multiplies by a scalar in place.
Definition: vecg.h:273
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:693
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
static const index_t dim
The dimension of the vector.
Definition: vecg.h:73
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
T dot(const vecng< DIM, T > &v1, const vecng< DIM, T > &v2)
Computes the dot product of 2 vectors.
Definition: vecg.h:388
vector_type & operator-=(const vector_type &v)
Subtracts a vector in place.
Definition: vecg.h:256
vector_type & operator/=(T2 s)
Divides by a scalar in place.
Definition: vecg.h:290
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.
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
std::ostream & operator<<(std::ostream &out, const Quaternion &q)
Writes a Quaternion to a stream.
Definition: quaternion.h:213
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
Definition: matrix.h:536
T det2x2(const T &a11, const T &a12, const T &a21, const T &a22)
Computes a two-by-two determinant.
Definition: determinant.h:58
std::istream & operator>>(std::istream &in, Quaternion &q)
Reads a Quaternion from a stream.
Definition: quaternion.h:225
Types and functions for numbers manipulation.