Bug 1074944 - Add Inverse functions on Matrix and Matrix4x4. r=Bas
authorKartikaya Gupta <kgupta@mozilla.com>
Wed, 01 Oct 2014 13:13:02 -0400
changeset 208228 f68b63f42f3ee364d8af9b23d9ef54725148ae1c
parent 208227 8a3de2f8ec3dbd504ca5a7a19b9398b94aad8595
child 208229 a8b3263797908ab04861b6910937f852405ee2d5
push id27580
push userkwierso@gmail.com
push dateWed, 01 Oct 2014 23:26:55 +0000
treeherderautoland@af6c928893c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas
bugs1074944
milestone35.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 1074944 - Add Inverse functions on Matrix and Matrix4x4. r=Bas
gfx/2d/Matrix.h
--- a/gfx/2d/Matrix.h
+++ b/gfx/2d/Matrix.h
@@ -6,16 +6,17 @@
 #ifndef MOZILLA_GFX_MATRIX_H_
 #define MOZILLA_GFX_MATRIX_H_
 
 #include "Types.h"
 #include "Rect.h"
 #include "Point.h"
 #include <math.h>
 #include "mozilla/Attributes.h"
+#include "mozilla/DebugOnly.h"
 
 namespace mozilla {
 namespace gfx {
 
 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;
 }
@@ -181,16 +182,24 @@ public:
     _21 = inv_det * B;
     _22 = inv_det * E;
     _31 = inv_det * C;
     _32 = inv_det * F;
 
     return true;
   }
 
+  Matrix Inverse() const
+  {
+    Matrix clone = *this;
+    DebugOnly<bool> inverted = clone.Invert();
+    MOZ_ASSERT(inverted, "Attempted to get the inverse of a non-invertible matrix");
+    return clone;
+  }
+
   Float Determinant() const
   {
     return _11 * _22 - _12 * _21;
   }
 
   Matrix operator*(const Matrix &aMatrix) const
   {
     Matrix resultMatrix;
@@ -666,16 +675,24 @@ public:
          + _13 * _21 * _32 * _44
          - _11 * _23 * _32 * _44
          - _12 * _21 * _33 * _44
          + _11 * _22 * _33 * _44;
   }
 
   bool Invert();
 
+  Matrix4x4 Inverse() const
+  {
+    Matrix4x4 clone = *this;
+    DebugOnly<bool> inverted = clone.Invert();
+    MOZ_ASSERT(inverted, "Attempted to get the inverse of a non-invertible matrix");
+    return clone;
+  }
+
   void Normalize()
   {
       for (int i = 0; i < 4; i++) {
           for (int j = 0; j < 4; j++) {
               (*this)[i][j] /= (*this)[3][3];
          }
       }
   }