Matrix2f.invert() returns null on failure
This commit is contained in:
parent
f348be1033
commit
1af7c6ba6d
|
@ -291,7 +291,7 @@ public class Matrix2f extends Matrix implements Serializable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invert this matrix
|
* Invert this matrix
|
||||||
* @return this
|
* @return this if successful, null otherwise
|
||||||
*/
|
*/
|
||||||
public Matrix invert()
|
public Matrix invert()
|
||||||
{
|
{
|
||||||
|
@ -300,18 +300,21 @@ public class Matrix2f extends Matrix implements Serializable {
|
||||||
inv(A) = 1/det(A) * adj(A);
|
inv(A) = 1/det(A) * adj(A);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float determinant = m00 * m11 - m01*m10;
|
float determinant = determinant();
|
||||||
float t00 = m11/determinant;
|
if (determinant != 0) {
|
||||||
float t01 = -m01/determinant;
|
float determinant_inv = 1f/determinant;
|
||||||
float t11 = m00/determinant;
|
float t00 = m11*determinant_inv;
|
||||||
float t10 = -m10/determinant;
|
float t01 = -m01*determinant_inv;
|
||||||
|
float t11 = m00*determinant_inv;
|
||||||
|
float t10 = -m10*determinant_inv;
|
||||||
|
|
||||||
m00 = t00;
|
m00 = t00;
|
||||||
m01 = t01;
|
m01 = t01;
|
||||||
m10 = t10;
|
m10 = t10;
|
||||||
m11 = t11;
|
m11 = t11;
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
} else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue