Bug 931769, part 2 - Add IsSingular and operator*= methods to Matrix. r=Bas
authorJonathan Watt <jwatt@jwatt.org>
Tue, 29 Oct 2013 08:14:40 +0000
changeset 152606 6123376c20f14aa5938eeb1c7e1c6bc5794c923b
parent 152605 194ba1b8f191cab6f5f97105b33d1b99b13148d4
child 152607 05d9c6a32d8b32b3f2a80431c23dfd49bd9f72b3
push id35591
push userjwatt@jwatt.org
push dateTue, 29 Oct 2013 08:15:00 +0000
treeherdermozilla-inbound@e09fa7cac06b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs931769
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 931769, part 2 - Add IsSingular and operator*= methods to Matrix. r=Bas
gfx/2d/Matrix.h
--- a/gfx/2d/Matrix.h
+++ b/gfx/2d/Matrix.h
@@ -117,16 +117,22 @@ public:
     resultMatrix._21 = this->_21 * aMatrix._11 + this->_22 * aMatrix._21;
     resultMatrix._22 = this->_21 * aMatrix._12 + this->_22 * aMatrix._22;
     resultMatrix._31 = this->_31 * aMatrix._11 + this->_32 * aMatrix._21 + aMatrix._31;
     resultMatrix._32 = this->_31 * aMatrix._12 + this->_32 * aMatrix._22 + aMatrix._32;
 
     return resultMatrix;
   }
 
+  Matrix& operator*=(const Matrix &aMatrix)
+  {
+    Matrix resultMatrix = *this * aMatrix;
+    return *this = resultMatrix;
+  }
+
   /* Returns true if the other matrix is fuzzy-equal to this matrix.
    * Note that this isn't a cheap comparison!
    */
   bool operator==(const Matrix& other) const
   {
     return FuzzyEqual(_11, other._11) && FuzzyEqual(_12, other._12) &&
            FuzzyEqual(_21, other._21) && FuzzyEqual(_22, other._22) &&
            FuzzyEqual(_31, other._31) && FuzzyEqual(_32, other._32);
@@ -154,16 +160,23 @@ public:
    */
   bool IsIdentity() const
   {
     return _11 == 1.0f && _12 == 0.0f &&
            _21 == 0.0f && _22 == 1.0f &&
            _31 == 0.0f && _32 == 0.0f;
   }
 
+  /* Returns true if the matrix is singular.
+   */
+  bool IsSingular() const
+  {
+    return Determinant() == 0;
+  }
+
   GFX2D_API void NudgeToIntegers();
 
 private:
   static bool FuzzyEqual(Float aV1, Float aV2) {
     // XXX - Check if fabs does the smart thing and just negates the sign bit.
     return fabs(aV2 - aV1) < 1e-6;
   }
 };