10 #ifndef __UT_Matrix2_h__
11 #define __UT_Matrix2_h__
30 template <
typename T>
UT_API
32 template <
typename T,
typename S>
UT_API
34 template <
typename T,
typename S>
static inline
36 template <
typename T>
UT_API
38 template <
typename T>
static inline
41 template <
typename T>
UT_API
43 template <
typename T,
typename S>
UT_API
45 template <
typename T,
typename S>
UT_API
47 template <
typename T>
static inline
49 template <
typename T>
UT_API
52 template <
typename T>
UT_API
54 template <
typename T,
typename S>
UT_API
56 template <
typename T,
typename S>
static inline
59 template <
typename T>
static inline
61 template <
typename T>
UT_API
68 template <
typename T,
typename S>
72 template <
typename T,
typename S>
79 template <
typename T,
typename S>
82 {
return v0 * (1 - u -
v) + v1 * u + v2 *v; }
95 static constexpr
int tuple_size = 4;
115 : matx{{
T(
m[0][0]),
T(
m[0][1])},{
T(
m[1][0]),
T(
m[1][1])}}
118 : matx{{
T(
m[0][0]),
T(
m[0][1])},{
T(
m[1][0]),
T(
m[1][1])}}
123 template <
typename S>
125 : matx{{
T(
v[0]),
T(
v[1])},{
T(
v[2]),
T(
v[3])}}
130 : matx{{val00,val01},{val10,val11}}
134 template <
typename S>
136 : matx{{
T(
m(0,0)),
T(
m(0,1))},{
T(
m(1,0)),
T(
m(1,1))}}
141 template <
typename S>
143 : matx{{
T(
m(0,0)),
T(
m(0,1))},{
T(
m(1,0)),
T(
m(1,1))}}
154 template <
typename S>
160 -matx[0][0], -matx[0][1],
161 -matx[1][0], -matx[1][1]);
166 matx[0][0]+=m.
matx[0][0]; matx[0][1]+=m.
matx[0][1];
167 matx[1][0]+=m.
matx[1][0]; matx[1][1]+=m.
matx[1][1];
172 matx[0][0]-=m.
matx[0][0]; matx[0][1]-=m.
matx[0][1];
173 matx[1][0]-=m.
matx[1][0]; matx[1][1]-=m.
matx[1][1];
180 return (&
m ==
this) || (
181 matx[0][0]==
m(0,0) && matx[0][1]==
m(0,1) &&
182 matx[1][0]==
m(1,0) && matx[1][1]==
m(1,1) );
186 return !(*
this ==
m);
191 matx[0][0] =
val; matx[0][1] = 0;
192 matx[1][0] = 0; matx[1][1] =
val;
197 matx[0][0]+=scalar; matx[0][1]+=scalar;
198 matx[1][0]+=scalar; matx[1][1]+=scalar;
207 matx[0][0]*=scalar; matx[0][1]*=scalar;
208 matx[1][0]*=scalar; matx[1][1]*=scalar;
217 template <
typename S>
220 template <
typename S>
223 template <
typename S>
229 return matx[0][0]*matx[1][1] - matx[0][1]*matx[1][0];
232 {
return matx[0][0] + matx[1][1]; }
235 template <
typename S>
253 T scale2 =
SYSmax(matx[0][0]*matx[0][0],
254 matx[0][1]*matx[0][1],
255 matx[1][0]*matx[1][0],
256 matx[1][1]*matx[1][1]);
257 T det = determinant();
263 -matx[1][0], matx[0][0]);
277 template <
typename S>
283 T scale2 =
SYSmax(matx[0][0]*matx[0][0],
284 matx[0][1]*matx[0][1],
285 matx[1][0]*matx[1][0],
286 matx[1][1]*matx[1][1]);
287 T det = determinant();
290 T recipdet =
T(1)/det;
292 recipdet * (matx[1][1]*b.
x() - matx[0][1]*b.
y()),
293 recipdet * (matx[0][0]*b.
y() - matx[1][0]*b.
x()));
302 template <
typename S>
308 T scale2 =
SYSmax(matx[0][0]*matx[0][0],
309 matx[0][1]*matx[0][1],
310 matx[1][0]*matx[1][0],
311 matx[1][1]*matx[1][1]);
312 T det = determinant();
315 T recipdet =
T(1)/det;
317 recipdet * (matx[1][1]*b.
x() - matx[1][0]*b.
y()),
318 recipdet * (matx[0][0]*b.
y() - matx[0][1]*b.
x()));
328 tmp=matx[0][1]; matx[0][1]=matx[1][0]; matx[1][0]=tmp;
336 return (&m ==
this) || (
337 SYSisEqual( matx[0][0], m.
matx[0][0], tolerance ) &&
338 SYSisEqual( matx[0][1], m.
matx[0][1], tolerance ) &&
340 SYSisEqual( matx[1][0], m.
matx[1][0], tolerance ) &&
341 SYSisEqual( matx[1][1], m.
matx[1][1], tolerance ) );
345 template <
typename S>
351 matx[0][0]+=bv1*v2.
x();
352 matx[0][1]+=bv1*v2.
y();
354 matx[1][0]+=bv1*v2.
x();
355 matx[1][1]+=bv1*v2.
y();
361 matx[0][0]=(
T)1;matx[0][1]=(
T)0;
362 matx[1][0]=(
T)0;matx[1][1]=(
T)1;
371 matx[0][0]==1 && matx[0][1]==0 &&
372 matx[1][0]==0 && matx[1][1]==1);
378 matx[0][0]==0 && matx[0][1]==0 &&
379 matx[1][0]==0 && matx[1][1]==0);
387 { (*this) *= rotationMat(theta); }
393 matx[0][0] *= sx; matx[0][1] *= sy;
394 matx[1][0] *= sx; matx[1][1] *= sy;
403 matx[0][0]=matx[0][1]= (
T)0;
404 matx[1][0]=matx[1][1]= (
T)0;
412 return matx[
row][col];
417 return matx[
row][col];
423 const T *
data()
const {
return myFloats; }
428 unsigned hash()
const {
return SYSvector_hash(
data(), tuple_size); }
455 {
return SYSsqrt(getEuclideanNorm2()); }
457 T getEuclideanNorm2()
const;
465 T getNormInf()
const;
469 T getNormMax()
const;
472 int save(std::ostream &os,
int binary)
const;
475 void outAsciiNoName(std::ostream &os)
const;
486 friend std::ostream &operator<<(std::ostream &os, const UT_Matrix2T<T> &
v)
489 v.outAsciiNoName(os);
497 void writeClassName(std::ostream &os)
const;
498 static const char *className();
502 T myFloats[tuple_size];
537 template <
typename T>
538 template <
typename S>
542 matx[0][0] = matx[0][1] = vec.
x();
543 matx[1][0] = matx[1][1] = vec.
y();
547 template <
typename T>
548 template <
typename S>
552 matx[0][0]+=vec.
x(); matx[0][1]+=vec.
x();
553 matx[1][0]+=vec.
y(); matx[1][1]+=vec.
y();
557 template <
typename T>
558 template <
typename S>
562 matx[0][0]-=vec.
x(); matx[0][1]-=vec.
x();
563 matx[1][0]-=vec.
y(); matx[1][1]-=vec.
y();
567 template <
typename T>
575 template <
typename T>
585 template <
typename T,
typename S>
592 template <
typename T>
599 template <
typename T>
606 template <
typename T,
typename S>
613 template <
typename T>
617 return m1 * (
T(1)/scalar);
620 template <
typename T>
626 template <
typename T>
638 template <
typename T>
650 template <
typename T,
typename S>
662 #ifndef UT_DISABLE_VECTORIZE_MATRIX
671 vm_store(result_mat.data(),
SYSlerp(
l,
r, t).vector);
676 template<
typename T, ex
int D >
void identity()
Set the matrix to identity.
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
GLboolean GLboolean GLboolean b
void rotate(T theta)
Rotate by theta radians.
#define SYS_STATIC_ASSERT(expr)
void initialize()
Initialize this matrix to zero.
constexpr UT_Matrix2T(const fpreal32 m[2][2]) noexcept
constexpr T determinant() const noexcept
GLenum GLenum GLenum GLenum GLenum scale
T tolerance() const
Returns the tolerance of our class.
const T * operator()(unsigned row) const
Return a matrix row. No bounds checking on subscript.
constexpr bool operator!=(const UT_Matrix2T< T > &m) const noexcept
int solve(const UT_Vector2T< S > &b, UT_Vector2T< S > &x) const
SYS_FORCE_INLINE T & operator()(unsigned row, unsigned col) noexcept
Return a matrix entry. No bounds checking on subscripts.
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
const GLuint GLenum const void * binary
UT_API size_t format(char *buffer, size_t buffer_size, const UT_Matrix2T< T > &v)
SYS_FORCE_INLINE T operator()(unsigned row, unsigned col) const noexcept
Return a matrix entry. No bounds checking on subscripts.
UT_Matrix2T< T > & operator=(T val)
JSON reader class which handles parsing of JSON or bJSON files.
UT_Matrix2T< T > SYSbilerp(const UT_Matrix2T< T > &u0v0, const UT_Matrix2T< T > &u1v0, const UT_Matrix2T< T > &u0v1, const UT_Matrix2T< T > &u1v1, S u, S v)
Bilinear interpolation.
Class which writes ASCII or binary JSON streams.
static const exint TupleSize
UT_Matrix2T< T > & operator/=(T scalar)
UT_Matrix2T< T > SYSlerp(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2, S t)
UT_Matrix2T< T > SYSbarycentric(const UT_Matrix2T< T > &v0, const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2, S u, S v)
Barycentric interpolation.
static int entries()
Returns the vector size.
void scale(const UT_Vector2T< T > &s)
unsigned hash() const
Compute a hash.
constexpr UT_Matrix2T(T val) noexcept
Construct identity matrix, multipled by scalar.
T * operator()(unsigned row)
Return a matrix row. No bounds checking on subscript.
GLubyte GLubyte GLubyte GLubyte w
GLsizei GLboolean transpose
T getEuclideanNorm() const
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
GLfloat GLfloat GLfloat v2
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
static const bool isVectorType
UT_Matrix2T< T > & operator=(UT_Matrix2T< T > &&m)=default
Default move assignment operator.
T dot(const UT_Matrix2T< T > &m) const
UT_Matrix2T< T > & operator+=(const UT_Matrix2T< T > &m)
IMATH_HOSTDEVICE const Vec2< S > & operator*=(Vec2< S > &v, const Matrix22< T > &m) IMATH_NOEXCEPT
Vector-matrix multiplication: v *= m.
int invert(UT_Matrix2T< T > &m) const
bool SYSequalZero(const UT_Vector3T< T > &v)
UT_Matrix2T< T > & operator-=(const UT_Matrix2T< T > &m)
const UT_Vector2T< T > & operator[](unsigned row) const
Return a matrix row. No bounds checking on subscript.
void zero()
Set the matrix to zero.
T * data()
Return the raw matrix data.
UT_Matrix2T< T > operator-() const
void outerproductUpdate(T b, const UT_Vector2T< S > &v1, const UT_Vector2T< S > &v2)
Class to store JSON objects as C++ objects.
bool isEqual(const UT_Matrix2T< T > &m, T tolerance=T(SYS_FTOLERANCE)) const
UT_Matrix2T< T > SYSmin(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2)
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
UT_Matrix2T< T > & operator-=(T scalar)
int invert()
Invert this matrix and return 0 if OK, 1 if singular.
int solveTranspose(const UT_Vector2T< S > &b, UT_Vector2T< S > &x) const
const T * data() const
Return the raw matrix data.
UT_API UT_Matrix2T< T > operator/(T sc, const UT_Matrix2T< T > &mat)
UT_Matrix2T< T > & operator+=(T scalar)
UT_Matrix2T< T > & operator*=(T scalar)
UT_Matrix2T< T > SYSmax(const UT_Matrix2T< T > &v1, const UT_Matrix2T< T > &v2)
constexpr bool operator==(const UT_Matrix2T< T > &m) const noexcept
constexpr T trace() const noexcept
UT_FixedVector< T, 4 > FixedVectorType