Bug 1074944 - Add Inverse functions on Matrix and Matrix4x4. r=Bas

This commit is contained in:
Kartikaya Gupta 2014-10-01 13:13:02 -04:00
parent e3e7c8f2fb
commit ab1a3f24c5

View File

@ -11,6 +11,7 @@
#include "Point.h" #include "Point.h"
#include <math.h> #include <math.h>
#include "mozilla/Attributes.h" #include "mozilla/Attributes.h"
#include "mozilla/DebugOnly.h"
namespace mozilla { namespace mozilla {
namespace gfx { namespace gfx {
@ -186,6 +187,14 @@ public:
return true; 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 Float Determinant() const
{ {
return _11 * _22 - _12 * _21; return _11 * _22 - _12 * _21;
@ -671,6 +680,14 @@ public:
bool Invert(); 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() void Normalize()
{ {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {