2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2011-06-13 14:02:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SkMatrix44_DEFINED
|
|
|
|
#define SkMatrix44_DEFINED
|
|
|
|
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkScalar.h"
|
|
|
|
|
|
|
|
#ifdef SK_MSCALAR_IS_DOUBLE
|
2012-12-03 21:19:52 +00:00
|
|
|
#ifdef SK_MSCALAR_IS_FLOAT
|
|
|
|
#error "can't define MSCALAR both as DOUBLE and FLOAT"
|
|
|
|
#endif
|
2011-06-13 14:02:52 +00:00
|
|
|
typedef double SkMScalar;
|
2012-12-03 21:19:52 +00:00
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
static inline double SkFloatToMScalar(float x) {
|
|
|
|
return static_cast<double>(x);
|
|
|
|
}
|
|
|
|
static inline float SkMScalarToFloat(double x) {
|
|
|
|
return static_cast<float>(x);
|
|
|
|
}
|
|
|
|
static inline double SkDoubleToMScalar(double x) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
static inline double SkMScalarToDouble(double x) {
|
|
|
|
return x;
|
|
|
|
}
|
2014-09-26 18:45:48 +00:00
|
|
|
static inline double SkMScalarAbs(double x) {
|
|
|
|
return fabs(x);
|
|
|
|
}
|
2011-06-13 14:02:52 +00:00
|
|
|
static const SkMScalar SK_MScalarPI = 3.141592653589793;
|
2014-10-21 19:33:21 +00:00
|
|
|
|
|
|
|
#define SkMScalarFloor(x) sk_double_floor(x)
|
|
|
|
#define SkMScalarCeil(x) sk_double_ceil(x)
|
|
|
|
#define SkMScalarRound(x) sk_double_round(x)
|
|
|
|
|
|
|
|
#define SkMScalarFloorToInt(x) sk_double_floor2int(x)
|
|
|
|
#define SkMScalarCeilToInt(x) sk_double_ceil2int(x)
|
|
|
|
#define SkMScalarRoundToInt(x) sk_double_round2int(x)
|
|
|
|
|
|
|
|
|
2012-11-13 20:12:00 +00:00
|
|
|
#elif defined SK_MSCALAR_IS_FLOAT
|
2012-12-03 21:19:52 +00:00
|
|
|
#ifdef SK_MSCALAR_IS_DOUBLE
|
|
|
|
#error "can't define MSCALAR both as DOUBLE and FLOAT"
|
|
|
|
#endif
|
2011-06-13 14:02:52 +00:00
|
|
|
typedef float SkMScalar;
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
static inline float SkFloatToMScalar(float x) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
static inline float SkMScalarToFloat(float x) {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
static inline float SkDoubleToMScalar(double x) {
|
|
|
|
return static_cast<float>(x);
|
|
|
|
}
|
|
|
|
static inline double SkMScalarToDouble(float x) {
|
|
|
|
return static_cast<double>(x);
|
|
|
|
}
|
2014-09-26 18:45:48 +00:00
|
|
|
static inline float SkMScalarAbs(float x) {
|
|
|
|
return sk_float_abs(x);
|
|
|
|
}
|
2011-06-13 14:02:52 +00:00
|
|
|
static const SkMScalar SK_MScalarPI = 3.14159265f;
|
2014-10-21 19:33:21 +00:00
|
|
|
|
|
|
|
#define SkMScalarFloor(x) sk_float_floor(x)
|
|
|
|
#define SkMScalarCeil(x) sk_float_ceil(x)
|
|
|
|
#define SkMScalarRound(x) sk_float_round(x)
|
|
|
|
|
|
|
|
#define SkMScalarFloorToInt(x) sk_float_floor2int(x)
|
|
|
|
#define SkMScalarCeilToInt(x) sk_float_ceil2int(x)
|
|
|
|
#define SkMScalarRoundToInt(x) sk_float_round2int(x)
|
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
#endif
|
|
|
|
|
2014-10-21 19:33:21 +00:00
|
|
|
#define SkIntToMScalar(n) static_cast<SkMScalar>(n)
|
|
|
|
|
|
|
|
#define SkMScalarToScalar(x) SkMScalarToFloat(x)
|
|
|
|
#define SkScalarToMScalar(x) SkFloatToMScalar(x)
|
2011-10-27 21:47:03 +00:00
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
static const SkMScalar SK_MScalar1 = 1;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct SkVector4 {
|
|
|
|
SkScalar fData[4];
|
|
|
|
|
|
|
|
SkVector4() {
|
|
|
|
this->set(0, 0, 0, 1);
|
|
|
|
}
|
|
|
|
SkVector4(const SkVector4& src) {
|
|
|
|
memcpy(fData, src.fData, sizeof(fData));
|
|
|
|
}
|
|
|
|
SkVector4(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) {
|
|
|
|
fData[0] = x;
|
|
|
|
fData[1] = y;
|
|
|
|
fData[2] = z;
|
|
|
|
fData[3] = w;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkVector4& operator=(const SkVector4& src) {
|
|
|
|
memcpy(fData, src.fData, sizeof(fData));
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const SkVector4& v) {
|
|
|
|
return fData[0] == v.fData[0] && fData[1] == v.fData[1] &&
|
|
|
|
fData[2] == v.fData[2] && fData[3] == v.fData[3];
|
|
|
|
}
|
|
|
|
bool operator!=(const SkVector4& v) {
|
|
|
|
return !(*this == v);
|
|
|
|
}
|
|
|
|
bool equals(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) {
|
|
|
|
return fData[0] == x && fData[1] == y &&
|
|
|
|
fData[2] == z && fData[3] == w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(SkScalar x, SkScalar y, SkScalar z, SkScalar w = SK_Scalar1) {
|
|
|
|
fData[0] = x;
|
|
|
|
fData[1] = y;
|
|
|
|
fData[2] = z;
|
|
|
|
fData[3] = w;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-17 13:29:35 +00:00
|
|
|
class SK_API SkMatrix44 {
|
2011-06-13 14:02:52 +00:00
|
|
|
public:
|
2012-12-10 20:16:10 +00:00
|
|
|
|
|
|
|
enum Uninitialized_Constructor {
|
|
|
|
kUninitialized_Constructor
|
|
|
|
};
|
|
|
|
enum Identity_Constructor {
|
|
|
|
kIdentity_Constructor
|
|
|
|
};
|
|
|
|
|
|
|
|
SkMatrix44(Uninitialized_Constructor) { }
|
|
|
|
SkMatrix44(Identity_Constructor) { this->setIdentity(); }
|
|
|
|
|
2013-10-31 17:28:30 +00:00
|
|
|
SK_ATTR_DEPRECATED("use the constructors that take an enum")
|
2012-12-03 21:19:52 +00:00
|
|
|
SkMatrix44() { this->setIdentity(); }
|
2013-01-15 14:54:00 +00:00
|
|
|
|
|
|
|
SkMatrix44(const SkMatrix44& src) {
|
|
|
|
memcpy(fMat, src.fMat, sizeof(fMat));
|
|
|
|
fTypeMask = src.fTypeMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkMatrix44(const SkMatrix44& a, const SkMatrix44& b) {
|
|
|
|
this->setConcat(a, b);
|
|
|
|
}
|
2011-06-13 14:02:52 +00:00
|
|
|
|
|
|
|
SkMatrix44& operator=(const SkMatrix44& src) {
|
2013-02-06 12:47:14 +00:00
|
|
|
if (&src != this) {
|
|
|
|
memcpy(fMat, src.fMat, sizeof(fMat));
|
|
|
|
fTypeMask = src.fTypeMask;
|
|
|
|
}
|
2011-06-13 14:02:52 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-11-27 13:13:22 +00:00
|
|
|
bool operator==(const SkMatrix44& other) const;
|
2011-06-13 14:02:52 +00:00
|
|
|
bool operator!=(const SkMatrix44& other) const {
|
2012-11-27 13:13:22 +00:00
|
|
|
return !(other == *this);
|
2011-06-13 14:02:52 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 01:16:30 +00:00
|
|
|
/* When converting from SkMatrix44 to SkMatrix, the third row and
|
|
|
|
* column is dropped. When converting from SkMatrix to SkMatrix44
|
|
|
|
* the third row and column remain as identity:
|
|
|
|
* [ a b c ] [ a b 0 c ]
|
|
|
|
* [ d e f ] -> [ d e 0 f ]
|
|
|
|
* [ g h i ] [ 0 0 1 0 ]
|
|
|
|
* [ g h 0 i ]
|
|
|
|
*/
|
2011-06-13 14:02:52 +00:00
|
|
|
SkMatrix44(const SkMatrix&);
|
|
|
|
SkMatrix44& operator=(const SkMatrix& src);
|
|
|
|
operator SkMatrix() const;
|
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
/**
|
|
|
|
* Return a reference to a const identity matrix
|
|
|
|
*/
|
|
|
|
static const SkMatrix44& I();
|
|
|
|
|
|
|
|
enum TypeMask {
|
|
|
|
kIdentity_Mask = 0,
|
|
|
|
kTranslate_Mask = 0x01, //!< set if the matrix has translation
|
|
|
|
kScale_Mask = 0x02, //!< set if the matrix has any scale != 1
|
|
|
|
kAffine_Mask = 0x04, //!< set if the matrix skews or rotates
|
|
|
|
kPerspective_Mask = 0x08 //!< set if the matrix is in perspective
|
|
|
|
};
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
/**
|
|
|
|
* Returns a bitfield describing the transformations the matrix may
|
|
|
|
* perform. The bitfield is computed conservatively, so it may include
|
|
|
|
* false positives. For example, when kPerspective_Mask is true, all
|
|
|
|
* other bits may be set to true even in the case of a pure perspective
|
|
|
|
* transform.
|
|
|
|
*/
|
|
|
|
inline TypeMask getType() const {
|
|
|
|
if (fTypeMask & kUnknown_Mask) {
|
|
|
|
fTypeMask = this->computeTypeMask();
|
|
|
|
}
|
|
|
|
SkASSERT(!(fTypeMask & kUnknown_Mask));
|
|
|
|
return (TypeMask)fTypeMask;
|
|
|
|
}
|
|
|
|
|
2012-12-10 03:27:47 +00:00
|
|
|
/**
|
|
|
|
* Return true if the matrix is identity.
|
|
|
|
*/
|
2012-12-03 21:19:52 +00:00
|
|
|
inline bool isIdentity() const {
|
2012-12-10 03:27:47 +00:00
|
|
|
return kIdentity_Mask == this->getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the matrix contains translate or is identity.
|
|
|
|
*/
|
|
|
|
inline bool isTranslate() const {
|
|
|
|
return !(this->getType() & ~kTranslate_Mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if the matrix only contains scale or translate or is identity.
|
|
|
|
*/
|
|
|
|
inline bool isScaleTranslate() const {
|
|
|
|
return !(this->getType() & ~(kScale_Mask | kTranslate_Mask));
|
2012-12-03 21:19:52 +00:00
|
|
|
}
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2014-10-24 15:07:05 +00:00
|
|
|
/**
|
|
|
|
* Returns true if the matrix only contains scale or is identity.
|
|
|
|
*/
|
|
|
|
inline bool isScale() const {
|
|
|
|
return !(this->getType() & ~kScale_Mask);
|
|
|
|
}
|
|
|
|
|
2014-09-16 15:29:29 +00:00
|
|
|
inline bool hasPerspective() const {
|
|
|
|
return SkToBool(this->getType() & kPerspective_Mask);
|
|
|
|
}
|
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
void setIdentity();
|
|
|
|
inline void reset() { this->setIdentity();}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get a value from the matrix. The row,col parameters work as follows:
|
|
|
|
* (0, 0) scale-x
|
|
|
|
* (0, 3) translate-x
|
|
|
|
* (3, 0) perspective-x
|
|
|
|
*/
|
|
|
|
inline SkMScalar get(int row, int col) const {
|
2012-11-27 13:13:22 +00:00
|
|
|
SkASSERT((unsigned)row <= 3);
|
|
|
|
SkASSERT((unsigned)col <= 3);
|
|
|
|
return fMat[col][row];
|
|
|
|
}
|
2011-06-13 14:02:52 +00:00
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
/**
|
|
|
|
* set a value in the matrix. The row,col parameters work as follows:
|
|
|
|
* (0, 0) scale-x
|
|
|
|
* (0, 3) translate-x
|
|
|
|
* (3, 0) perspective-x
|
|
|
|
*/
|
|
|
|
inline void set(int row, int col, SkMScalar value) {
|
2012-11-27 13:13:22 +00:00
|
|
|
SkASSERT((unsigned)row <= 3);
|
|
|
|
SkASSERT((unsigned)col <= 3);
|
|
|
|
fMat[col][row] = value;
|
2012-12-03 21:19:52 +00:00
|
|
|
this->dirtyTypeMask();
|
2012-11-27 13:13:22 +00:00
|
|
|
}
|
2012-11-28 02:02:11 +00:00
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
inline double getDouble(int row, int col) const {
|
2012-11-14 21:33:55 +00:00
|
|
|
return SkMScalarToDouble(this->get(row, col));
|
|
|
|
}
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void setDouble(int row, int col, double value) {
|
2012-11-14 21:33:55 +00:00
|
|
|
this->set(row, col, SkDoubleToMScalar(value));
|
|
|
|
}
|
2013-09-18 18:52:09 +00:00
|
|
|
inline float getFloat(int row, int col) const {
|
|
|
|
return SkMScalarToFloat(this->get(row, col));
|
|
|
|
}
|
|
|
|
inline void setFloat(int row, int col, float value) {
|
|
|
|
this->set(row, col, SkFloatToMScalar(value));
|
|
|
|
}
|
2012-11-14 21:33:55 +00:00
|
|
|
|
2012-11-19 21:02:06 +00:00
|
|
|
/** These methods allow one to efficiently read matrix entries into an
|
|
|
|
* array. The given array must have room for exactly 16 entries. Whenever
|
|
|
|
* possible, they will try to use memcpy rather than an entry-by-entry
|
|
|
|
* copy.
|
|
|
|
*/
|
2011-06-13 14:46:52 +00:00
|
|
|
void asColMajorf(float[]) const;
|
|
|
|
void asColMajord(double[]) const;
|
|
|
|
void asRowMajorf(float[]) const;
|
|
|
|
void asRowMajord(double[]) const;
|
|
|
|
|
2012-11-19 21:02:06 +00:00
|
|
|
/** These methods allow one to efficiently set all matrix entries from an
|
|
|
|
* array. The given array must have room for exactly 16 entries. Whenever
|
|
|
|
* possible, they will try to use memcpy rather than an entry-by-entry
|
|
|
|
* copy.
|
|
|
|
*/
|
|
|
|
void setColMajorf(const float[]);
|
|
|
|
void setColMajord(const double[]);
|
|
|
|
void setRowMajorf(const float[]);
|
|
|
|
void setRowMajord(const double[]);
|
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
#ifdef SK_MSCALAR_IS_FLOAT
|
|
|
|
void setColMajor(const SkMScalar data[]) { this->setColMajorf(data); }
|
|
|
|
void setRowMajor(const SkMScalar data[]) { this->setRowMajorf(data); }
|
|
|
|
#else
|
|
|
|
void setColMajor(const SkMScalar data[]) { this->setColMajord(data); }
|
|
|
|
void setRowMajor(const SkMScalar data[]) { this->setRowMajord(data); }
|
|
|
|
#endif
|
2011-06-13 14:02:52 +00:00
|
|
|
|
2013-10-05 01:16:30 +00:00
|
|
|
/* This sets the top-left of the matrix and clears the translation and
|
|
|
|
* perspective components (with [3][3] set to 1). */
|
2011-06-13 14:02:52 +00:00
|
|
|
void set3x3(SkMScalar m00, SkMScalar m01, SkMScalar m02,
|
|
|
|
SkMScalar m10, SkMScalar m11, SkMScalar m12,
|
|
|
|
SkMScalar m20, SkMScalar m21, SkMScalar m22);
|
|
|
|
|
|
|
|
void setTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz);
|
|
|
|
void preTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz);
|
|
|
|
void postTranslate(SkMScalar dx, SkMScalar dy, SkMScalar dz);
|
|
|
|
|
|
|
|
void setScale(SkMScalar sx, SkMScalar sy, SkMScalar sz);
|
|
|
|
void preScale(SkMScalar sx, SkMScalar sy, SkMScalar sz);
|
|
|
|
void postScale(SkMScalar sx, SkMScalar sy, SkMScalar sz);
|
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void setScale(SkMScalar scale) {
|
2011-06-13 14:02:52 +00:00
|
|
|
this->setScale(scale, scale, scale);
|
|
|
|
}
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void preScale(SkMScalar scale) {
|
2011-06-13 14:02:52 +00:00
|
|
|
this->preScale(scale, scale, scale);
|
|
|
|
}
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void postScale(SkMScalar scale) {
|
2011-06-13 14:02:52 +00:00
|
|
|
this->postScale(scale, scale, scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setRotateDegreesAbout(SkMScalar x, SkMScalar y, SkMScalar z,
|
|
|
|
SkMScalar degrees) {
|
|
|
|
this->setRotateAbout(x, y, z, degrees * SK_MScalarPI / 180);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Rotate about the vector [x,y,z]. If that vector is not unit-length,
|
|
|
|
it will be automatically resized.
|
|
|
|
*/
|
|
|
|
void setRotateAbout(SkMScalar x, SkMScalar y, SkMScalar z,
|
|
|
|
SkMScalar radians);
|
|
|
|
/** Rotate about the vector [x,y,z]. Does not check the length of the
|
|
|
|
vector, assuming it is unit-length.
|
|
|
|
*/
|
|
|
|
void setRotateAboutUnit(SkMScalar x, SkMScalar y, SkMScalar z,
|
|
|
|
SkMScalar radians);
|
|
|
|
|
|
|
|
void setConcat(const SkMatrix44& a, const SkMatrix44& b);
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void preConcat(const SkMatrix44& m) {
|
2011-06-13 14:02:52 +00:00
|
|
|
this->setConcat(*this, m);
|
|
|
|
}
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void postConcat(const SkMatrix44& m) {
|
2011-06-13 14:02:52 +00:00
|
|
|
this->setConcat(m, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend SkMatrix44 operator*(const SkMatrix44& a, const SkMatrix44& b) {
|
|
|
|
return SkMatrix44(a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** If this is invertible, return that in inverse and return true. If it is
|
2015-06-30 20:36:04 +00:00
|
|
|
not invertible, return false and leave the inverse parameter in an
|
|
|
|
unspecified state.
|
2011-06-13 14:02:52 +00:00
|
|
|
*/
|
|
|
|
bool invert(SkMatrix44* inverse) const;
|
|
|
|
|
2012-11-14 21:33:55 +00:00
|
|
|
/** Transpose this matrix in place. */
|
|
|
|
void transpose();
|
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
/** Apply the matrix to the src vector, returning the new vector in dst.
|
|
|
|
It is legal for src and dst to point to the same memory.
|
|
|
|
*/
|
2012-11-09 21:39:48 +00:00
|
|
|
void mapScalars(const SkScalar src[4], SkScalar dst[4]) const;
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void mapScalars(SkScalar vec[4]) const {
|
2012-11-09 21:39:48 +00:00
|
|
|
this->mapScalars(vec, vec);
|
|
|
|
}
|
|
|
|
|
2013-10-31 17:28:30 +00:00
|
|
|
SK_ATTR_DEPRECATED("use mapScalars")
|
2012-11-09 21:39:48 +00:00
|
|
|
void map(const SkScalar src[4], SkScalar dst[4]) const {
|
|
|
|
this->mapScalars(src, dst);
|
|
|
|
}
|
2013-10-31 17:28:30 +00:00
|
|
|
|
|
|
|
SK_ATTR_DEPRECATED("use mapScalars")
|
2011-06-13 14:02:52 +00:00
|
|
|
void map(SkScalar vec[4]) const {
|
2012-11-09 21:39:48 +00:00
|
|
|
this->mapScalars(vec, vec);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SK_MSCALAR_IS_DOUBLE
|
2012-11-12 20:43:59 +00:00
|
|
|
void mapMScalars(const SkMScalar src[4], SkMScalar dst[4]) const;
|
2012-11-13 20:12:00 +00:00
|
|
|
#elif defined SK_MSCALAR_IS_FLOAT
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void mapMScalars(const SkMScalar src[4], SkMScalar dst[4]) const {
|
2012-11-09 21:39:48 +00:00
|
|
|
this->mapScalars(src, dst);
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-03 21:19:52 +00:00
|
|
|
inline void mapMScalars(SkMScalar vec[4]) const {
|
2012-11-09 21:39:48 +00:00
|
|
|
this->mapMScalars(vec, vec);
|
2011-06-13 14:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
friend SkVector4 operator*(const SkMatrix44& m, const SkVector4& src) {
|
|
|
|
SkVector4 dst;
|
2013-10-31 17:28:30 +00:00
|
|
|
m.mapScalars(src.fData, dst.fData);
|
2011-06-13 14:02:52 +00:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2012-12-05 22:13:59 +00:00
|
|
|
/**
|
|
|
|
* map an array of [x, y, 0, 1] through the matrix, returning an array
|
|
|
|
* of [x', y', z', w'].
|
|
|
|
*
|
|
|
|
* @param src2 array of [x, y] pairs, with implied z=0 and w=1
|
|
|
|
* @param count number of [x, y] pairs in src2
|
|
|
|
* @param dst4 array of [x', y', z', w'] quads as the output.
|
|
|
|
*/
|
|
|
|
void map2(const float src2[], int count, float dst4[]) const;
|
|
|
|
void map2(const double src2[], int count, double dst4[]) const;
|
|
|
|
|
2014-09-26 18:45:48 +00:00
|
|
|
/** Returns true if transformating an axis-aligned square in 2d by this matrix
|
|
|
|
will produce another 2d axis-aligned square; typically means the matrix
|
|
|
|
is a scale with perhaps a 90-degree rotation. A 3d rotation through 90
|
|
|
|
degrees into a perpendicular plane collapses a square to a line, but
|
|
|
|
is still considered to be axis-aligned.
|
|
|
|
|
|
|
|
By default, tolerates very slight error due to float imprecisions;
|
|
|
|
a 90-degree rotation can still end up with 10^-17 of
|
|
|
|
"non-axis-aligned" result.
|
|
|
|
*/
|
|
|
|
bool preserves2dAxisAlignment(SkMScalar epsilon = SK_ScalarNearlyZero) const;
|
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
void dump() const;
|
|
|
|
|
2012-11-13 15:08:22 +00:00
|
|
|
double determinant() const;
|
|
|
|
|
2011-06-13 14:02:52 +00:00
|
|
|
private:
|
2013-01-15 14:54:00 +00:00
|
|
|
SkMScalar fMat[4][4];
|
|
|
|
mutable unsigned fTypeMask;
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
enum {
|
|
|
|
kUnknown_Mask = 0x80,
|
|
|
|
|
|
|
|
kAllPublic_Masks = 0xF
|
|
|
|
};
|
|
|
|
|
|
|
|
SkMScalar transX() const { return fMat[3][0]; }
|
|
|
|
SkMScalar transY() const { return fMat[3][1]; }
|
|
|
|
SkMScalar transZ() const { return fMat[3][2]; }
|
|
|
|
|
|
|
|
SkMScalar scaleX() const { return fMat[0][0]; }
|
|
|
|
SkMScalar scaleY() const { return fMat[1][1]; }
|
|
|
|
SkMScalar scaleZ() const { return fMat[2][2]; }
|
2012-12-06 02:01:25 +00:00
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
SkMScalar perspX() const { return fMat[0][3]; }
|
|
|
|
SkMScalar perspY() const { return fMat[1][3]; }
|
|
|
|
SkMScalar perspZ() const { return fMat[2][3]; }
|
2012-11-29 21:17:16 +00:00
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
int computeTypeMask() const;
|
|
|
|
|
|
|
|
inline void dirtyTypeMask() {
|
|
|
|
fTypeMask = kUnknown_Mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void setTypeMask(int mask) {
|
|
|
|
SkASSERT(0 == (~(kAllPublic_Masks | kUnknown_Mask) & mask));
|
|
|
|
fTypeMask = mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does not take the time to 'compute' the typemask. Only returns true if
|
|
|
|
* we already know that this matrix is identity.
|
|
|
|
*/
|
|
|
|
inline bool isTriviallyIdentity() const {
|
|
|
|
return 0 == fTypeMask;
|
|
|
|
}
|
2013-01-17 13:29:35 +00:00
|
|
|
};
|
2011-06-13 14:02:52 +00:00
|
|
|
|
|
|
|
#endif
|