diff --git a/CHANGELOG.md b/CHANGELOG.md index 935e2e5a..ac03ea2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## 2.4.0-wip - Remove the deprecated `SimplexNoise` class. +- Optimized the `identity` constructors on the `Matrix` classes. ## 2.3.0 diff --git a/lib/src/vector_math/matrix2.dart b/lib/src/vector_math/matrix2.dart index cd102bdc..52fff5f0 100644 --- a/lib/src/vector_math/matrix2.dart +++ b/lib/src/vector_math/matrix2.dart @@ -62,7 +62,10 @@ class Matrix2 { Matrix2.zero() : _m2storage = Float32List(4); /// Identity matrix. - factory Matrix2.identity() => Matrix2.zero()..setIdentity(); + factory Matrix2.identity() => + Matrix2.zero() + .._m2storage[0] = 1.0 + .._m2storage[3] = 1.0; /// Copies values from [other]. factory Matrix2.copy(Matrix2 other) => Matrix2.zero()..setFrom(other); diff --git a/lib/src/vector_math/matrix3.dart b/lib/src/vector_math/matrix3.dart index d58f539e..20ad1f37 100644 --- a/lib/src/vector_math/matrix3.dart +++ b/lib/src/vector_math/matrix3.dart @@ -131,7 +131,11 @@ class Matrix3 { Matrix3.zero() : _m3storage = Float32List(9); /// Identity matrix. - factory Matrix3.identity() => Matrix3.zero()..setIdentity(); + factory Matrix3.identity() => + Matrix3.zero() + .._m3storage[0] = 1.0 + .._m3storage[4] = 1.0 + .._m3storage[8] = 1.0; /// Copes values from [other]. factory Matrix3.copy(Matrix3 other) => Matrix3.zero()..setFrom(other); diff --git a/lib/src/vector_math/matrix4.dart b/lib/src/vector_math/matrix4.dart index 90b6f553..395c0ead 100644 --- a/lib/src/vector_math/matrix4.dart +++ b/lib/src/vector_math/matrix4.dart @@ -245,7 +245,12 @@ class Matrix4 { Matrix4.zero() : _m4storage = Float32List(16); /// Identity matrix. - factory Matrix4.identity() => Matrix4.zero()..setIdentity(); + factory Matrix4.identity() => + Matrix4.zero() + .._m4storage[0] = 1.0 + .._m4storage[5] = 1.0 + .._m4storage[10] = 1.0 + .._m4storage[15] = 1.0; /// Copies values from [other]. factory Matrix4.copy(Matrix4 other) => Matrix4.zero()..setFrom(other); @@ -1777,7 +1782,7 @@ class Matrix4 { /// Computes the result of `arg x this` and stores the result in-place in /// `this`. /// - /// This method does not alter the [Matrix4] in `arg`. + /// This method does not alter the [Matrix4] in [arg]. void leftMultiply(Matrix4 arg) { final argStorage = arg._m4storage; final m00 = argStorage[0]; diff --git a/lib/src/vector_math_64/matrix2.dart b/lib/src/vector_math_64/matrix2.dart index a35be282..ccc387c3 100644 --- a/lib/src/vector_math_64/matrix2.dart +++ b/lib/src/vector_math_64/matrix2.dart @@ -62,7 +62,10 @@ class Matrix2 { Matrix2.zero() : _m2storage = Float64List(4); /// Identity matrix. - factory Matrix2.identity() => Matrix2.zero()..setIdentity(); + factory Matrix2.identity() => + Matrix2.zero() + .._m2storage[0] = 1.0 + .._m2storage[3] = 1.0; /// Copies values from [other]. factory Matrix2.copy(Matrix2 other) => Matrix2.zero()..setFrom(other); diff --git a/lib/src/vector_math_64/matrix3.dart b/lib/src/vector_math_64/matrix3.dart index ffc5a22b..3bc7c9f9 100644 --- a/lib/src/vector_math_64/matrix3.dart +++ b/lib/src/vector_math_64/matrix3.dart @@ -131,7 +131,11 @@ class Matrix3 { Matrix3.zero() : _m3storage = Float64List(9); /// Identity matrix. - factory Matrix3.identity() => Matrix3.zero()..setIdentity(); + factory Matrix3.identity() => + Matrix3.zero() + .._m3storage[0] = 1.0 + .._m3storage[4] = 1.0 + .._m3storage[8] = 1.0; /// Copes values from [other]. factory Matrix3.copy(Matrix3 other) => Matrix3.zero()..setFrom(other); diff --git a/lib/src/vector_math_64/matrix4.dart b/lib/src/vector_math_64/matrix4.dart index bd7e5326..6252545f 100644 --- a/lib/src/vector_math_64/matrix4.dart +++ b/lib/src/vector_math_64/matrix4.dart @@ -245,7 +245,12 @@ class Matrix4 { Matrix4.zero() : _m4storage = Float64List(16); /// Identity matrix. - factory Matrix4.identity() => Matrix4.zero()..setIdentity(); + factory Matrix4.identity() => + Matrix4.zero() + .._m4storage[0] = 1.0 + .._m4storage[5] = 1.0 + .._m4storage[10] = 1.0 + .._m4storage[15] = 1.0; /// Copies values from [other]. factory Matrix4.copy(Matrix4 other) => Matrix4.zero()..setFrom(other);