Blender V5.0
VecMat.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11
12#include <iostream>
13#include <math.h>
14#include <vector>
15
16#include "MEM_guardedalloc.h"
17
18namespace Freestyle {
19
20namespace VecMat {
21
22namespace Internal {
23template<bool B> struct is_false {};
24
25template<> struct is_false<false> {
26 static inline void ensure() {}
27};
28} // end of namespace Internal
29
30//
31// Vector class
32// - T: value type
33// - N: dimension
34//
36
37template<class T, uint N> class Vec {
38 public:
39 typedef T value_type;
40
41 // constructors
42 inline Vec()
43 {
44 for (uint i = 0; i < N; i++) {
45 this->_coord[i] = 0;
46 }
47 }
48
50 {
51 Internal::is_false<(N == 0)>::ensure();
52 }
53
54 template<class U> explicit inline Vec(const U tab[N])
55 {
56 for (uint i = 0; i < N; i++) {
57 this->_coord[i] = (T)tab[i];
58 }
59 }
60
61 template<class U> explicit inline Vec(const std::vector<U> &tab)
62 {
63 for (uint i = 0; i < N; i++) {
64 this->_coord[i] = (T)tab[i];
65 }
66 }
67
68 template<class U> explicit inline Vec(const Vec<U, N> &v)
69 {
70 for (uint i = 0; i < N; i++) {
71 this->_coord[i] = (T)v[i];
72 }
73 }
74
75 // accessors
76 inline value_type operator[](const uint i) const
77 {
78 return this->_coord[i];
79 }
80
81 inline value_type &operator[](const uint i)
82 {
83 return this->_coord[i];
84 }
85
86 static inline uint dim()
87 {
88 return N;
89 }
90
91 // various useful methods
92 inline value_type norm() const
93 {
94 return (T)sqrt((float)squareNorm());
95 }
96
97 inline value_type squareNorm() const
98 {
99 return (*this) * (*this);
100 }
101
103 {
104 value_type n = norm();
105 for (uint i = 0; i < N; i++) {
106 this->_coord[i] /= n;
107 }
108 return *this;
109 }
110
112 {
113 value_type n = norm();
114 if (n) {
115 for (uint i = 0; i < N; i++) {
116 this->_coord[i] /= n;
117 }
118 }
119 return *this;
120 }
121
122 // classical operators
123 inline Vec<T, N> operator+(const Vec<T, N> &v) const
124 {
125 Vec<T, N> res(v);
126 res += *this;
127 return res;
128 }
129
130 inline Vec<T, N> operator-(const Vec<T, N> &v) const
131 {
132 Vec<T, N> res(*this);
133 res -= v;
134 return res;
135 }
136
137 inline Vec<T, N> operator*(const typename Vec<T, N>::value_type r) const
138 {
139 Vec<T, N> res(*this);
140 res *= r;
141 return res;
142 }
143
144 inline Vec<T, N> operator/(const typename Vec<T, N>::value_type r) const
145 {
146 Vec<T, N> res(*this);
147 if (r) {
148 res /= r;
149 }
150 return res;
151 }
152
153 // dot product
154 inline value_type operator*(const Vec<T, N> &v) const
155 {
156 value_type sum = 0;
157 for (uint i = 0; i < N; i++) {
158 sum += (*this)[i] * v[i];
159 }
160 return sum;
161 }
162
163 template<class U> inline Vec<T, N> &operator=(const Vec<U, N> &v)
164 {
165 if (this != &v) {
166 for (uint i = 0; i < N; i++) {
167 this->_coord[i] = (T)v[i];
168 }
169 }
170 return *this;
171 }
172
173 template<class U> inline Vec<T, N> &operator+=(const Vec<U, N> &v) &
174 {
175 for (uint i = 0; i < N; i++) {
176 this->_coord[i] += (T)v[i];
177 }
178 return *this;
179 }
180
181 template<class U> inline Vec<T, N> &operator-=(const Vec<U, N> &v) &
182 {
183 for (uint i = 0; i < N; i++) {
184 this->_coord[i] -= (T)v[i];
185 }
186 return *this;
187 }
188
189 template<class U> inline Vec<T, N> &operator*=(const U r) &
190 {
191 for (uint i = 0; i < N; i++) {
192 this->_coord[i] *= r;
193 }
194 return *this;
195 }
196
197 template<class U> inline Vec<T, N> &operator/=(const U r) &
198 {
199 if (r) {
200 for (uint i = 0; i < N; i++) {
201 this->_coord[i] /= r;
202 }
203 }
204 return *this;
205 }
206
207 inline bool operator==(const Vec<T, N> &v) const
208 {
209 for (uint i = 0; i < N; i++) {
210 if (this->_coord[i] != v[i]) {
211 return false;
212 }
213 }
214 return true;
215 }
216
217 inline bool operator!=(const Vec<T, N> &v) const
218 {
219 for (uint i = 0; i < N; i++) {
220 if (this->_coord[i] != v[i]) {
221 return true;
222 }
223 }
224 return false;
225 }
226
227 inline bool operator<(const Vec<T, N> &v) const
228 {
229 for (uint i = 0; i < N; i++) {
230 if (this->_coord[i] < v[i]) {
231 return true;
232 }
233 if (this->_coord[i] > v[i]) {
234 return false;
235 }
236 if (this->_coord[i] == v[i]) {
237 continue;
238 }
239 }
240 return false;
241 }
242
243 inline bool operator>(const Vec<T, N> &v) const
244 {
245 for (uint i = 0; i < N; i++) {
246 if (this->_coord[i] > v[i]) {
247 return true;
248 }
249 if (this->_coord[i] < v[i]) {
250 return false;
251 }
252 if (this->_coord[i] == v[i]) {
253 continue;
254 }
255 }
256 return false;
257 }
258
259 protected:
261 enum {
263 };
264
265 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VecMat:Vec")
266};
267
268//
269// Vec2 class (2D Vector)
270// - T: value type
271//
273
274template<class T> class Vec2 : public Vec<T, 2> {
275 public:
277
278 inline Vec2() : Vec<T, 2>() {}
279
280 template<class U> explicit inline Vec2(const U tab[2]) : Vec<T, 2>(tab) {}
281
282 template<class U> explicit inline Vec2(const std::vector<U> &tab) : Vec<T, 2>(tab) {}
283
284 template<class U> inline Vec2(const Vec<U, 2> &v) : Vec<T, 2>(v) {}
285
286 inline Vec2(const value_type x, const value_type y = 0) : Vec<T, 2>()
287 {
288 this->_coord[0] = (T)x;
289 this->_coord[1] = (T)y;
290 }
291
292 inline value_type x() const
293 {
294 return this->_coord[0];
295 }
296
297 inline value_type &x()
298 {
299 return this->_coord[0];
300 }
301
302 inline value_type y() const
303 {
304 return this->_coord[1];
305 }
306
307 inline value_type &y()
308 {
309 return this->_coord[1];
310 }
311
312 inline void setX(const value_type v)
313 {
314 this->_coord[0] = v;
315 }
316
317 inline void setY(const value_type v)
318 {
319 this->_coord[1] = v;
320 }
321
322 // FIXME: hack swig -- no choice
323 inline Vec2<T> operator+(const Vec2<T> &v) const
324 {
325 Vec2<T> res(v);
326 res += *this;
327 return res;
328 }
329
330 inline Vec2<T> operator-(const Vec2<T> &v) const
331 {
332 Vec2<T> res(*this);
333 res -= v;
334 return res;
335 }
336
337 inline Vec2<T> operator*(const value_type r) const
338 {
339 Vec2<T> res(*this);
340 res *= r;
341 return res;
342 }
343
344 inline Vec2<T> operator/(const value_type r) const
345 {
346 Vec2<T> res(*this);
347 if (r) {
348 res /= r;
349 }
350 return res;
351 }
352
353 // dot product
354 inline value_type operator*(const Vec2<T> &v) const
355 {
356 value_type sum = 0;
357 for (uint i = 0; i < 2; i++) {
358 sum += (*this)[i] * v[i];
359 }
360 return sum;
361 }
362};
363
364//
365// HVec3 class (3D Vector in homogeneous coordinates)
366// - T: value type
367//
369
370template<class T> class HVec3 : public Vec<T, 4> {
371 public:
373
374 inline HVec3() : Vec<T, 4>() {}
375
376 template<class U> explicit inline HVec3(const U tab[4]) : Vec<T, 4>(tab) {}
377
378 template<class U> explicit inline HVec3(const std::vector<U> &tab) : Vec<T, 4>(tab) {}
379
380 template<class U> inline HVec3(const Vec<U, 4> &v) : Vec<T, 4>(v) {}
381
382 inline HVec3(const value_type sx,
383 const value_type sy = 0,
384 const value_type sz = 0,
385 const value_type s = 1)
386 {
387 this->_coord[0] = sx;
388 this->_coord[1] = sy;
389 this->_coord[2] = sz;
390 this->_coord[3] = s;
391 }
392
393 template<class U> inline HVec3(const Vec<U, 3> &sv, const U s = 1)
394 {
395 this->_coord[0] = (T)sv[0];
396 this->_coord[1] = (T)sv[1];
397 this->_coord[2] = (T)sv[2];
398 this->_coord[3] = (T)s;
399 }
400
401 inline value_type sx() const
402 {
403 return this->_coord[0];
404 }
405
406 inline value_type &sx()
407 {
408 return this->_coord[0];
409 }
410
411 inline value_type sy() const
412 {
413 return this->_coord[1];
414 }
415
416 inline value_type &sy()
417 {
418 return this->_coord[1];
419 }
420
421 inline value_type sz() const
422 {
423 return this->_coord[2];
424 }
425
426 inline value_type &sz()
427 {
428 return this->_coord[2];
429 }
430
431 inline value_type s() const
432 {
433 return this->_coord[3];
434 }
435
436 inline value_type &s()
437 {
438 return this->_coord[3];
439 }
440
441 // Access to non-homogeneous coordinates in 3D
442 inline value_type x() const
443 {
444 return this->_coord[0] / this->_coord[3];
445 }
446
447 inline value_type y() const
448 {
449 return this->_coord[1] / this->_coord[3];
450 }
451
452 inline value_type z() const
453 {
454 return this->_coord[2] / this->_coord[3];
455 }
456};
457
458//
459// Vec3 class (3D Vec)
460// - T: value type
461//
463template<class T> class Vec3 : public Vec<T, 3> {
464 public:
466
467 inline Vec3() : Vec<T, 3>() {}
468
469 template<class U> explicit inline Vec3(const U tab[3]) : Vec<T, 3>(tab) {}
470
471 template<class U> explicit inline Vec3(const std::vector<U> &tab) : Vec<T, 3>(tab) {}
472
473 template<class U> inline Vec3(const Vec<U, 3> &v) : Vec<T, 3>(v) {}
474
475 template<class U> inline Vec3(const HVec3<U> &v)
476 {
477 this->_coord[0] = (T)v.x();
478 this->_coord[1] = (T)v.y();
479 this->_coord[2] = (T)v.z();
480 }
481
482 inline Vec3(const value_type x, const value_type y = 0, const value_type z = 0) : Vec<T, 3>()
483 {
484 this->_coord[0] = x;
485 this->_coord[1] = y;
486 this->_coord[2] = z;
487 }
488
489 inline value_type x() const
490 {
491 return this->_coord[0];
492 }
493
494 inline value_type &x()
495 {
496 return this->_coord[0];
497 }
498
499 inline value_type y() const
500 {
501 return this->_coord[1];
502 }
503
504 inline value_type &y()
505 {
506 return this->_coord[1];
507 }
508
509 inline value_type z() const
510 {
511 return this->_coord[2];
512 }
513
514 inline value_type &z()
515 {
516 return this->_coord[2];
517 }
518
519 inline void setX(const value_type v)
520 {
521 this->_coord[0] = v;
522 }
523
524 inline void setY(const value_type v)
525 {
526 this->_coord[1] = v;
527 }
528
529 inline void setZ(const value_type v)
530 {
531 this->_coord[2] = v;
532 }
533
534 // classical operators
535 // FIXME: hack swig -- no choice
536 inline Vec3<T> operator+(const Vec3<T> &v) const
537 {
538 Vec3<T> res(v);
539 res += *this;
540 return res;
541 }
542
543 inline Vec3<T> operator-(const Vec3<T> &v) const
544 {
545 Vec3<T> res(*this);
546 res -= v;
547 return res;
548 }
549
550 inline Vec3<T> operator*(const value_type r) const
551 {
552 Vec3<T> res(*this);
553 res *= r;
554 return res;
555 }
556
557 inline Vec3<T> operator/(const value_type r) const
558 {
559 Vec3<T> res(*this);
560 if (r) {
561 res /= r;
562 }
563 return res;
564 }
565
566 // dot product
567 inline value_type operator*(const Vec3<T> &v) const
568 {
569 value_type sum = 0;
570 for (uint i = 0; i < 3; i++) {
571 sum += (*this)[i] * v[i];
572 }
573 return sum;
574 }
575
576 // cross product for 3D Vectors
577 // FIXME: hack swig -- no choice
578 inline Vec3<T> operator^(const Vec3<T> &v) const
579 {
580 Vec3<T> res((*this)[1] * v[2] - (*this)[2] * v[1],
581 (*this)[2] * v[0] - (*this)[0] * v[2],
582 (*this)[0] * v[1] - (*this)[1] * v[0]);
583 return res;
584 }
585
586 // cross product for 3D Vectors
587 template<typename U> inline Vec3<T> operator^(const Vec<U, 3> &v) const
588 {
589 Vec3<T> res((*this)[1] * v[2] - (*this)[2] * v[1],
590 (*this)[2] * v[0] - (*this)[0] * v[2],
591 (*this)[0] * v[1] - (*this)[1] * v[0]);
592 return res;
593 }
594};
595
596//
597// Matrix class
598// - T: value type
599// - M: rows
600// - N: cols
601//
603
604// Dirty, but icc under Windows needs this
605#define _SIZE (M * N)
606
607template<class T, uint M, uint N> class Matrix {
608 public:
609 typedef T value_type;
610
611 inline Matrix()
612 {
613 for (uint i = 0; i < _SIZE; i++) {
614 this->_coord[i] = 0;
615 }
616 }
617
619 {
620 Internal::is_false<(M == 0)>::ensure();
621 Internal::is_false<(N == 0)>::ensure();
622 }
623
624 template<class U> explicit inline Matrix(const U tab[_SIZE])
625 {
626 for (uint i = 0; i < _SIZE; i++) {
627 this->_coord[i] = tab[i];
628 }
629 }
630
631 template<class U> explicit inline Matrix(const std::vector<U> &tab)
632 {
633 for (uint i = 0; i < _SIZE; i++) {
634 this->_coord[i] = tab[i];
635 }
636 }
637
638 template<class U> inline Matrix(const Matrix<U, M, N> &m)
639 {
640 for (uint i = 0; i < M; i++) {
641 for (uint j = 0; j < N; j++) {
642 this->_coord[i * N + j] = (T)m(i, j);
643 }
644 }
645 }
646
647 inline value_type operator()(const uint i, const uint j) const
648 {
649 return this->_coord[i * N + j];
650 }
651
652 inline value_type &operator()(const uint i, const uint j)
653 {
654 return this->_coord[i * N + j];
655 }
656
657 static inline uint rows()
658 {
659 return M;
660 }
661
662 static inline uint cols()
663 {
664 return N;
665 }
666
668 {
669 Matrix<T, N, M> res;
670 for (uint i = 0; i < M; i++) {
671 for (uint j = 0; j < N; j++) {
672 res(j, i) = this->_coord[i * N + j];
673 }
674 }
675 *this = res;
676 return *this;
677 }
678
679 template<class U> inline Matrix<T, M, N> &operator=(const Matrix<U, M, N> &m)
680 {
681 if (this != &m) {
682 for (uint i = 0; i < M; i++) {
683 for (uint j = 0; j < N; j++) {
684 this->_coord[i * N + j] = (T)m(i, j);
685 }
686 }
687 }
688 return *this;
689 }
690
691 template<class U> inline Matrix<T, M, N> &operator+=(const Matrix<U, M, N> &m) &
692 {
693 for (uint i = 0; i < M; i++) {
694 for (uint j = 0; j < N; j++) {
695 this->_coord[i * N + j] += (T)m(i, j);
696 }
697 }
698 return *this;
699 }
700
701 template<class U> inline Matrix<T, M, N> &operator-=(const Matrix<U, M, N> &m) &
702 {
703 for (uint i = 0; i < M; i++) {
704 for (uint j = 0; j < N; j++) {
705 this->_coord[i * N + j] -= (T)m(i, j);
706 }
707 }
708 return *this;
709 }
710
711 template<class U> inline Matrix<T, M, N> &operator*=(const U lambda) &
712 {
713 for (uint i = 0; i < M; i++) {
714 for (uint j = 0; j < N; j++) {
715 this->_coord[i * N + j] *= lambda;
716 }
717 }
718 return *this;
719 }
720
721 template<class U> inline Matrix<T, M, N> &operator/=(const U lambda) &
722 {
723 if (lambda) {
724 for (uint i = 0; i < M; i++) {
725 for (uint j = 0; j < N; j++) {
726 this->_coord[i * N + j] /= lambda;
727 }
728 }
729 }
730 return *this;
731 }
732
733 protected:
735
736 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:VecMat:Matrix")
737};
738
739#undef _SIZE
740
741//
742// SquareMatrix class
743// - T: value type
744// - N: rows & cols
745//
747
748// Dirty, but icc under Windows needs this
749#define _SIZE (N * N)
750
751template<class T, uint N> class SquareMatrix : public Matrix<T, N, N> {
752 public:
753 typedef T value_type;
754
755 inline SquareMatrix() : Matrix<T, N, N>() {}
756
757 template<class U> explicit inline SquareMatrix(const U tab[_SIZE]) : Matrix<T, N, N>(tab) {}
758
759 template<class U> explicit inline SquareMatrix(const std::vector<U> &tab) : Matrix<T, N, N>(tab)
760 {
761 }
762
763 template<class U> inline SquareMatrix(const Matrix<U, N, N> &m) : Matrix<T, N, N>(m) {}
764
766 {
768 for (uint i = 0; i < N; i++) {
769 res(i, i) = 1;
770 }
771 return res;
772 }
773};
774
775#undef _SIZE
776
777//
778// Vector external functions
779//
781
782#if 0
783template<class T, uint N> inline Vec<T, N> operator+(const Vec<T, N> &v1, const Vec<T, N> &v2)
784{
785 Vec<T, N> res(v1);
786 res += v2;
787 return res;
788}
789
790template<class T, uint N> inline Vec<T, N> operator-(const Vec<T, N> &v1, const Vec<T, N> &v2)
791{
792 Vec<T, N> res(v1);
793 res -= v2;
794 return res;
795}
796
797template<class T, uint N>
798inline Vec<T, N> operator*(const Vec<T, N> &v, const typename Vec<T, N>::value_type r)
799{
800 Vec<T, N> res(v);
801 res *= r;
802 return res;
803}
804#endif
805
806template<class T, uint N>
807inline Vec<T, N> operator*(const typename Vec<T, N>::value_type r, const Vec<T, N> &v)
808{
809 Vec<T, N> res(v);
810 res *= r;
811 return res;
812}
813
814#if 0
815template<class T, uint N>
816inline Vec<T, N> operator/(const Vec<T, N> &v, const typename Vec<T, N>::value_type r)
817{
818 Vec<T, N> res(v);
819 if (r) {
820 res /= r;
821 }
822 return res;
823}
824
825// dot product
826template<class T, uint N>
827inline typename Vec<T, N>::value_type operator*(const Vec<T, N> &v1, const Vec<T, N> &v2)
828{
829 typename Vec<T, N>::value_type sum = 0;
830 for (uint i = 0; i < N; i++) {
831 sum += v1[i] * v2[i];
832 }
833 return sum;
834}
835
836// cross product for 3D Vectors
837template<typename T> inline Vec3<T> operator^(const Vec<T, 3> &v1, const Vec<T, 3> &v2)
838{
839 Vec3<T> res(
840 v1[1] * v2[2] - v1[2] * v2[1], v1[2] * v2[0] - v1[0] * v2[2], v1[0] * v2[1] - v1[1] * v2[0]);
841 return res;
842}
843#endif
844
845// stream operator
846template<class T, uint N> inline std::ostream &operator<<(std::ostream &s, const Vec<T, N> &v)
847{
848 uint i;
849 s << "[";
850 for (i = 0; i < N - 1; i++) {
851 s << v[i] << ", ";
852 }
853 s << v[i] << "]";
854 return s;
855}
856
857//
858// Matrix external functions
859//
861
862template<class T, uint M, uint N>
864{
865 Matrix<T, M, N> res(m1);
866 res += m2;
867 return res;
868}
869
870template<class T, uint M, uint N>
872{
873 Matrix<T, M, N> res(m1);
874 res -= m2;
875 return res;
876}
877
878template<class T, uint M, uint N>
880 const typename Matrix<T, M, N>::value_type lambda)
881{
882 Matrix<T, M, N> res(m1);
883 res *= lambda;
884 return res;
885}
886
887template<class T, uint M, uint N>
889 const Matrix<T, M, N> &m1)
890{
891 Matrix<T, M, N> res(m1);
892 res *= lambda;
893 return res;
894}
895
896template<class T, uint M, uint N>
898 const typename Matrix<T, M, N>::value_type lambda)
899{
900 Matrix<T, M, N> res(m1);
901 res /= lambda;
902 return res;
903}
904
905template<class T, uint M, uint N, uint P>
907{
908 uint i, j, k;
909 Matrix<T, M, P> res;
910 typename Matrix<T, N, P>::value_type scale;
911
912 for (j = 0; j < P; j++) {
913 for (k = 0; k < N; k++) {
914 scale = m2(k, j);
915 for (i = 0; i < N; i++) {
916 res(i, j) += m1(i, k) * scale;
917 }
918 }
919 }
920 return res;
921}
922
923template<class T, uint M, uint N>
925{
926 Vec<T, M> res;
927 typename Matrix<T, M, N>::value_type scale;
928
929 for (uint j = 0; j < M; j++) {
930 scale = v[j];
931 for (uint i = 0; i < N; i++) {
932 res[i] += m(i, j) * scale;
933 }
934 }
935 return res;
936}
937
938// stream operator
939template<class T, uint M, uint N>
940inline std::ostream &operator<<(std::ostream &s, const Matrix<T, M, N> &m)
941{
942 uint i, j;
943 for (i = 0; i < M; i++) {
944 s << "[";
945 for (j = 0; j < N - 1; j++) {
946 s << m(i, j) << ", ";
947 }
948 s << m(i, j) << "]" << std::endl;
949 }
950 return s;
951}
952
953} // end of namespace VecMat
954
955} /* namespace Freestyle */
unsigned int uint
Read Guarded memory(de)allocation.
#define _SIZE
Definition VecMat.h:605
#define U
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
static T sum(const btAlignedObjectArray< T > &items)
value_type z() const
Definition VecMat.h:452
HVec3(const Vec< U, 4 > &v)
Definition VecMat.h:380
HVec3(const std::vector< U > &tab)
Definition VecMat.h:378
value_type & s()
Definition VecMat.h:436
HVec3(const Vec< U, 3 > &sv, const U s=1)
Definition VecMat.h:393
value_type x() const
Definition VecMat.h:442
value_type sy() const
Definition VecMat.h:411
value_type & sy()
Definition VecMat.h:416
value_type & sx()
Definition VecMat.h:406
value_type sx() const
Definition VecMat.h:401
HVec3(const U tab[4])
Definition VecMat.h:376
HVec3(const value_type sx, const value_type sy=0, const value_type sz=0, const value_type s=1)
Definition VecMat.h:382
value_type & sz()
Definition VecMat.h:426
value_type sz() const
Definition VecMat.h:421
Vec< uint, 4 >::value_type value_type
Definition VecMat.h:372
value_type y() const
Definition VecMat.h:447
Matrix< T, M, N > & operator+=(const Matrix< U, M, N > &m) &
Definition VecMat.h:691
Matrix(const std::vector< U > &tab)
Definition VecMat.h:631
Matrix(const Matrix< U, M, N > &m)
Definition VecMat.h:638
Matrix< T, M, N > & operator*=(const U lambda) &
Definition VecMat.h:711
static uint cols()
Definition VecMat.h:662
static uint rows()
Definition VecMat.h:657
Matrix(const U tab[_SIZE])
Definition VecMat.h:624
value_type operator()(const uint i, const uint j) const
Definition VecMat.h:647
value_type _coord[_SIZE]
Definition VecMat.h:734
value_type & operator()(const uint i, const uint j)
Definition VecMat.h:652
Matrix< T, M, N > & operator/=(const U lambda) &
Definition VecMat.h:721
Matrix< T, M, N > & operator-=(const Matrix< U, M, N > &m) &
Definition VecMat.h:701
Matrix< T, M, N > & transpose() const
Definition VecMat.h:667
Matrix< T, M, N > & operator=(const Matrix< U, M, N > &m)
Definition VecMat.h:679
static SquareMatrix< T, N > identity()
Definition VecMat.h:765
SquareMatrix(const std::vector< U > &tab)
Definition VecMat.h:759
SquareMatrix(const Matrix< U, N, N > &m)
Definition VecMat.h:763
SquareMatrix(const U tab[_SIZE])
Definition VecMat.h:757
Vec2< T > operator*(const value_type r) const
Definition VecMat.h:337
value_type operator*(const Vec2< T > &v) const
Definition VecMat.h:354
Vec< uint, 2 >::value_type value_type
Definition VecMat.h:276
void setX(const value_type v)
Definition VecMat.h:312
value_type x() const
Definition VecMat.h:292
Vec2(const U tab[2])
Definition VecMat.h:280
value_type & y()
Definition VecMat.h:307
Vec2(const Vec< U, 2 > &v)
Definition VecMat.h:284
value_type & x()
Definition VecMat.h:297
Vec2< T > operator/(const value_type r) const
Definition VecMat.h:344
value_type y() const
Definition VecMat.h:302
Vec2< T > operator+(const Vec2< T > &v) const
Definition VecMat.h:323
void setY(const value_type v)
Definition VecMat.h:317
Vec2< T > operator-(const Vec2< T > &v) const
Definition VecMat.h:330
Vec2(const value_type x, const value_type y=0)
Definition VecMat.h:286
Vec2(const std::vector< U > &tab)
Definition VecMat.h:282
value_type & x()
Definition VecMat.h:494
Vec3(const std::vector< U > &tab)
Definition VecMat.h:471
Vec3< T > operator^(const Vec3< T > &v) const
Definition VecMat.h:578
Vec< uint, 3 >::value_type value_type
Definition VecMat.h:465
void setX(const value_type v)
Definition VecMat.h:519
value_type x() const
Definition VecMat.h:489
value_type operator*(const Vec3< T > &v) const
Definition VecMat.h:567
Vec3< T > operator-(const Vec3< T > &v) const
Definition VecMat.h:543
void setY(const value_type v)
Definition VecMat.h:524
value_type & y()
Definition VecMat.h:504
value_type z() const
Definition VecMat.h:509
Vec3< T > operator/(const value_type r) const
Definition VecMat.h:557
Vec3< T > operator*(const value_type r) const
Definition VecMat.h:550
Vec3(const U tab[3])
Definition VecMat.h:469
Vec3(const value_type x, const value_type y=0, const value_type z=0)
Definition VecMat.h:482
value_type y() const
Definition VecMat.h:499
Vec3(const HVec3< U > &v)
Definition VecMat.h:475
Vec3< T > operator^(const Vec< U, 3 > &v) const
Definition VecMat.h:587
void setZ(const value_type v)
Definition VecMat.h:529
Vec3(const Vec< U, 3 > &v)
Definition VecMat.h:473
value_type & z()
Definition VecMat.h:514
Vec3< T > operator+(const Vec3< T > &v) const
Definition VecMat.h:536
Vec< T, N > operator+(const Vec< T, N > &v) const
Definition VecMat.h:123
Vec< T, N > & normalizeSafe()
Definition VecMat.h:111
value_type squareNorm() const
Definition VecMat.h:97
Vec(const U tab[N])
Definition VecMat.h:54
Vec< T, N > & operator=(const Vec< U, N > &v)
Definition VecMat.h:163
value_type operator[](const uint i) const
Definition VecMat.h:76
Vec< T, N > operator/(const typename Vec< T, N >::value_type r) const
Definition VecMat.h:144
value_type & operator[](const uint i)
Definition VecMat.h:81
Vec< T, N > & operator/=(const U r) &
Definition VecMat.h:197
Vec< T, N > & operator-=(const Vec< U, N > &v) &
Definition VecMat.h:181
Vec< T, N > operator*(const typename Vec< T, N >::value_type r) const
Definition VecMat.h:137
bool operator>(const Vec< T, N > &v) const
Definition VecMat.h:243
Vec< T, N > operator-(const Vec< T, N > &v) const
Definition VecMat.h:130
Vec(const Vec< U, N > &v)
Definition VecMat.h:68
bool operator!=(const Vec< T, N > &v) const
Definition VecMat.h:217
static uint dim()
Definition VecMat.h:86
Vec< T, N > & normalize()
Definition VecMat.h:102
Vec< T, N > & operator+=(const Vec< U, N > &v) &
Definition VecMat.h:173
bool operator==(const Vec< T, N > &v) const
Definition VecMat.h:207
value_type operator*(const Vec< T, N > &v) const
Definition VecMat.h:154
Vec(const std::vector< U > &tab)
Definition VecMat.h:61
value_type norm() const
Definition VecMat.h:92
Vec< T, N > & operator*=(const U r) &
Definition VecMat.h:189
bool operator<(const Vec< T, N > &v) const
Definition VecMat.h:227
#define sqrt
ccl_device_inline float4 operator^(const float4 a, const float4 b)
#define M
#define N
#define T
Matrix< T, M, N > operator/(const Matrix< T, M, N > &m1, const typename Matrix< T, M, N >::value_type lambda)
Definition VecMat.h:897
Matrix< T, M, N > operator+(const Matrix< T, M, N > &m1, const Matrix< T, M, N > &m2)
Definition VecMat.h:863
std::ostream & operator<<(std::ostream &s, const Vec< T, N > &v)
Definition VecMat.h:846
Vec< T, N > operator*(const typename Vec< T, N >::value_type r, const Vec< T, N > &v)
Definition VecMat.h:807
Matrix< T, M, N > operator-(const Matrix< T, M, N > &m1, const Matrix< T, M, N > &m2)
Definition VecMat.h:871
inherits from class Rep
Definition AppCanvas.cpp:20
i
Definition text_draw.cc:230