37template<
class T, u
int N>
class Vec {
44 for (
uint i = 0; i <
N; i++) {
54 template<
class U>
explicit inline Vec(
const U tab[
N])
56 for (
uint i = 0; i <
N; i++) {
61 template<
class U>
explicit inline Vec(
const std::vector<U> &tab)
63 for (
uint i = 0; i <
N; i++) {
70 for (
uint i = 0; i <
N; i++) {
99 return (*
this) * (*this);
105 for (
uint i = 0; i <
N; i++) {
115 for (
uint i = 0; i <
N; i++) {
157 for (
uint i = 0; i <
N; i++) {
158 sum += (*this)[i] *
v[i];
166 for (
uint i = 0; i <
N; i++) {
175 for (
uint i = 0; i <
N; i++) {
183 for (
uint i = 0; i <
N; i++) {
191 for (
uint i = 0; i <
N; i++) {
200 for (
uint i = 0; i <
N; i++) {
209 for (
uint i = 0; i <
N; i++) {
219 for (
uint i = 0; i <
N; i++) {
229 for (
uint i = 0; i <
N; i++) {
245 for (
uint i = 0; i <
N; i++) {
265 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:VecMat:Vec")
274template<
class T>
class Vec2 :
public Vec<T, 2> {
280 template<
class U>
explicit inline Vec2(
const U tab[2]) :
Vec<T, 2>(tab) {}
282 template<
class U>
explicit inline Vec2(
const std::vector<U> &tab) :
Vec<T, 2>(tab) {}
292 inline value_type
x()
const
297 inline value_type &
x()
302 inline value_type
y()
const
307 inline value_type &
y()
312 inline void setX(
const value_type
v)
317 inline void setY(
const value_type
v)
357 for (
uint i = 0; i < 2; i++) {
358 sum += (*this)[i] *
v[i];
376 template<
class U>
explicit inline HVec3(
const U tab[4]) :
Vec<T, 4>(tab) {}
378 template<
class U>
explicit inline HVec3(
const std::vector<U> &tab) :
Vec<T, 4>(tab) {}
401 inline value_type
sx()
const
406 inline value_type &
sx()
411 inline value_type
sy()
const
416 inline value_type &
sy()
421 inline value_type
sz()
const
426 inline value_type &
sz()
431 inline value_type
s()
const
436 inline value_type &
s()
442 inline value_type
x()
const
447 inline value_type
y()
const
452 inline value_type
z()
const
463template<
class T>
class Vec3 :
public Vec<T, 3> {
469 template<
class U>
explicit inline Vec3(
const U tab[3]) :
Vec<T, 3>(tab) {}
471 template<
class U>
explicit inline Vec3(
const std::vector<U> &tab) :
Vec<T, 3>(tab) {}
489 inline value_type
x()
const
494 inline value_type &
x()
499 inline value_type
y()
const
504 inline value_type &
y()
509 inline value_type
z()
const
514 inline value_type &
z()
519 inline void setX(
const value_type
v)
524 inline void setY(
const value_type
v)
529 inline void setZ(
const value_type
v)
570 for (
uint i = 0; i < 3; i++) {
571 sum += (*this)[i] *
v[i];
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]);
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]);
607template<
class T, u
int M, u
int N>
class Matrix {
631 template<
class U>
explicit inline Matrix(
const std::vector<U> &tab)
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);
649 return this->
_coord[i *
N + j];
654 return this->
_coord[i *
N + j];
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];
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);
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);
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);
713 for (
uint i = 0; i <
M; i++) {
714 for (
uint j = 0; j <
N; j++) {
715 this->
_coord[i *
N + j] *= lambda;
724 for (
uint i = 0; i <
M; i++) {
725 for (
uint j = 0; j <
N; j++) {
726 this->
_coord[i *
N + j] /= lambda;
736 MEM_CXX_CLASS_ALLOC_FUNCS(
"Freestyle:VecMat:Matrix")
768 for (
uint i = 0; i <
N; i++) {
783template<
class T, u
int N>
inline Vec<T, N>
operator+(
const Vec<T, N> &v1,
const Vec<T, N> &
v2)
790template<
class T, u
int N>
inline Vec<T, N>
operator-(
const Vec<T, N> &v1,
const Vec<T, N> &
v2)
797template<
class T, u
int N>
806template<
class T, u
int N>
815template<
class T, u
int N>
826template<
class T, u
int N>
830 for (
uint i = 0; i <
N; i++) {
831 sum += v1[i] *
v2[i];
837template<
typename T>
inline Vec3<T>
operator^(
const Vec<T, 3> &v1,
const Vec<T, 3> &
v2)
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]);
850 for (i = 0; i <
N - 1; i++) {
862template<
class T, u
int M, u
int N>
870template<
class T, u
int M, u
int N>
878template<
class T, u
int M, u
int N>
887template<
class T, u
int M, u
int N>
896template<
class T, u
int M, u
int N>
905template<
class T, u
int M, u
int N, u
int P>
912 for (j = 0; j <
P; j++) {
913 for (k = 0; k <
N; k++) {
915 for (i = 0; i <
N; i++) {
916 res(i, j) += m1(i, k) * scale;
923template<
class T, u
int M, u
int N>
929 for (
uint j = 0; j <
M; j++) {
931 for (
uint i = 0; i <
N; i++) {
932 res[i] += m(i, j) * scale;
939template<
class T, u
int M, u
int N>
943 for (i = 0; i <
M; i++) {
945 for (j = 0; j <
N - 1; j++) {
946 s << m(i, j) <<
", ";
948 s << m(i, j) <<
"]" << std::endl;
Read Guarded memory(de)allocation.
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert * v
static T sum(const btAlignedObjectArray< T > &items)
HVec3(const Vec< U, 4 > &v)
HVec3(const std::vector< U > &tab)
HVec3(const Vec< U, 3 > &sv, const U s=1)
HVec3(const value_type sx, const value_type sy=0, const value_type sz=0, const value_type s=1)
Vec< T, 4 >::value_type value_type
Matrix< T, M, N > & operator+=(const Matrix< U, M, N > &m) &
Matrix(const std::vector< U > &tab)
Matrix(const Matrix< U, M, N > &m)
Matrix< T, M, N > & operator*=(const U lambda) &
Matrix(const U tab[_SIZE])
value_type operator()(const uint i, const uint j) const
value_type & operator()(const uint i, const uint j)
Matrix< T, M, N > & operator/=(const U lambda) &
Matrix< T, M, N > & operator-=(const Matrix< U, M, N > &m) &
Matrix< T, M, N > & transpose() const
Matrix< T, M, N > & operator=(const Matrix< U, M, N > &m)
static SquareMatrix< T, N > identity()
SquareMatrix(const std::vector< U > &tab)
SquareMatrix(const Matrix< U, N, N > &m)
SquareMatrix(const U tab[_SIZE])
Vec2< T > operator*(const value_type r) const
value_type operator*(const Vec2< T > &v) const
Vec< T, 2 >::value_type value_type
void setX(const value_type v)
Vec2(const Vec< U, 2 > &v)
Vec2< T > operator/(const value_type r) const
Vec2< T > operator+(const Vec2< T > &v) const
void setY(const value_type v)
Vec2< T > operator-(const Vec2< T > &v) const
Vec2(const value_type x, const value_type y=0)
Vec2(const std::vector< U > &tab)
Vec3(const std::vector< U > &tab)
Vec3< T > operator^(const Vec3< T > &v) const
Vec< T, 3 >::value_type value_type
void setX(const value_type v)
value_type operator*(const Vec3< T > &v) const
Vec3< T > operator-(const Vec3< T > &v) const
void setY(const value_type v)
Vec3< T > operator/(const value_type r) const
Vec3< T > operator*(const value_type r) const
Vec3(const value_type x, const value_type y=0, const value_type z=0)
Vec3(const HVec3< U > &v)
Vec3< T > operator^(const Vec< U, 3 > &v) const
void setZ(const value_type v)
Vec3(const Vec< U, 3 > &v)
Vec3< T > operator+(const Vec3< T > &v) const
Vec< T, N > operator+(const Vec< T, N > &v) const
Vec< T, N > & normalizeSafe()
value_type squareNorm() const
Vec< T, N > & operator=(const Vec< U, N > &v)
value_type operator[](const uint i) const
Vec< T, N > operator/(const typename Vec< T, N >::value_type r) const
value_type & operator[](const uint i)
Vec< T, N > & operator/=(const U r) &
Vec< T, N > & operator-=(const Vec< U, N > &v) &
Vec< T, N > operator*(const typename Vec< T, N >::value_type r) const
bool operator>(const Vec< T, N > &v) const
Vec< T, N > operator-(const Vec< T, N > &v) const
Vec(const Vec< U, N > &v)
bool operator!=(const Vec< T, N > &v) const
Vec< T, N > & normalize()
Vec< T, N > & operator+=(const Vec< U, N > &v) &
bool operator==(const Vec< T, N > &v) const
value_type operator*(const Vec< T, N > &v) const
Vec(const std::vector< U > &tab)
Vec< T, N > & operator*=(const U r) &
bool operator<(const Vec< T, N > &v) const
ccl_device_inline float4 operator^(const float4 a, const float4 b)
Matrix< T, M, N > operator/(const Matrix< T, M, N > &m1, const typename Matrix< T, M, N >::value_type lambda)
Matrix< T, M, N > operator+(const Matrix< T, M, N > &m1, const Matrix< T, M, N > &m2)
std::ostream & operator<<(std::ostream &s, const Vec< T, N > &v)
Vec< T, N > operator*(const typename Vec< T, N >::value_type r, const Vec< T, N > &v)
Matrix< T, M, N > operator-(const Matrix< T, M, N > &m1, const Matrix< T, M, N > &m2)