Add Matrix4.tryInvert static method to support attempting to invert a matrix without throwing an
exception.
diff --git a/lib/src/vector_math/matrix4.dart b/lib/src/vector_math/matrix4.dart
index dafb779..837c5f9 100644
--- a/lib/src/vector_math/matrix4.dart
+++ b/lib/src/vector_math/matrix4.dart
@@ -148,6 +148,17 @@
               (a20 * b03 - a21 * b01 + a22 * b00) * bW);
   }
 
+  /// Returns a matrix that is the inverse of [other] if [other] is invertible,
+  /// otherwise `null`.
+  static Matrix4 tryInvert(Matrix4 other) {
+    final Matrix4 r = new Matrix4.zero();
+    final double determinant = r.copyInverse(other);
+    if (determinant == 0.0) {
+      return null;
+    }
+    return r;
+  }
+
   /// Return index in storage for [row], [col] value.
   int index(int row, int col) => (col * 4) + row;
 
diff --git a/test/matrix4_test.dart b/test/matrix4_test.dart
index 14254ea..10f9655 100644
--- a/test/matrix4_test.dart
+++ b/test/matrix4_test.dart
@@ -613,6 +613,12 @@
       equals(new Matrix4.identity()));
 }
 
+void testMatrix4tryInvert() {
+  expect(Matrix4.tryInvert(new Matrix4.zero()), isNull);
+  expect(Matrix4.tryInvert(new Matrix4.identity()),
+      equals(new Matrix4.identity()));
+}
+
 void testMatrix4SkewConstructor() {
   var m = new Matrix4.skew(0.0, 1.57);
   var m2 = new Matrix4.skewY(1.57);
@@ -701,6 +707,7 @@
     test('compose/decompose', testMatrix4Compose);
     test('equals', testMatrix4Equals);
     test('invert constructor', testMatrix4InvertConstructor);
+    test('tryInvert', testMatrix4tryInvert);
     test('skew constructor', testMatrix4SkewConstructor);
     test('leftTranslate', testLeftTranslate);
     test('matrix classifiers', testMatrixClassifiers);