From 60f6d79d8f4e3f4bd305b7933d8be64ec458001a Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Wed, 10 Sep 2025 20:37:42 -0400 Subject: [PATCH 1/4] feat: Add leftTranslateByVector2 method to Matrix4 --- lib/src/vector_math/matrix4.dart | 7 +++++++ lib/src/vector_math_64/matrix4.dart | 7 +++++++ test/matrix4_test.dart | 14 ++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/lib/src/vector_math/matrix4.dart b/lib/src/vector_math/matrix4.dart index 1eac7b1b..734c4874 100644 --- a/lib/src/vector_math/matrix4.dart +++ b/lib/src/vector_math/matrix4.dart @@ -838,6 +838,13 @@ class Matrix4 { _m4storage[15] = tw * r4; } + /// Multiply this by a translation from the left. + @pragma('wasm:prefer-inline') + @pragma('vm:prefer-inline') + @pragma('dart2js:prefer-inline') + void leftTranslateByVector2(Vector2 v2) => + leftTranslateByDouble(v2.x, v2.y, 0.0, 1.0); + /// Multiply this by a translation from the left. @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') diff --git a/lib/src/vector_math_64/matrix4.dart b/lib/src/vector_math_64/matrix4.dart index 53b7d17b..fbcaf4b2 100644 --- a/lib/src/vector_math_64/matrix4.dart +++ b/lib/src/vector_math_64/matrix4.dart @@ -838,6 +838,13 @@ class Matrix4 { _m4storage[15] = tw * r4; } + /// Multiply this by a translation from the left. + @pragma('wasm:prefer-inline') + @pragma('vm:prefer-inline') + @pragma('dart2js:prefer-inline') + void leftTranslateByVector2(Vector2 v2) => + leftTranslateByDouble(v2.x, v2.y, 0.0, 1.0); + /// Multiply this by a translation from the left. @pragma('wasm:prefer-inline') @pragma('vm:prefer-inline') diff --git a/test/matrix4_test.dart b/test/matrix4_test.dart index 523a00d9..0ddc2d39 100644 --- a/test/matrix4_test.dart +++ b/test/matrix4_test.dart @@ -822,6 +822,20 @@ void testLeftTranslate() { expect(result.x, equals(3.0)); expect(result.y, equals(0.0)); expect(result.z, equals(0.0)); + + // Matrix4 alternative methods + final m2 = Matrix4.diagonal3Values(2.0, 3.0, 4.0); + final result2 = Matrix4.columns( + Vector4(2.0, 0.0, 0.0, 0.0), + Vector4(0.0, 3.0, 0.0, 0.0), + Vector4(0.0, 0.0, 4.0, 0.0), + Vector4(1.0, 0.0, 0.0, 1.0), + ); + + expect(m2.clone()..leftTranslateByDouble(1, 0, 0, 1), result2); + expect(m2.clone()..leftTranslateByVector2(Vector2(1, 0)), result2); + expect(m2.clone()..leftTranslateByVector3(Vector3(1, 0, 0)), result2); + expect(m2.clone()..leftTranslateByVector4(Vector4(1, 0, 0, 1)), result2); } void testMatrixClassifiers() { From bdb9df7ce2c0a35cb99c5aa995d4efaa69ad4d5b Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Fri, 14 Nov 2025 14:58:21 -0500 Subject: [PATCH 2/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6282472c..60aa18ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 2.3.0-wip +- Add leftTranslateByVector2 method to Matrix4. - Add translateByVector2 method to Matrix4. - Require `sdk: ^3.7.0`. From 3cef7625d8e83a3bc15fd15a1e74bf66dc38978d Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Fri, 14 Nov 2025 16:38:35 -0500 Subject: [PATCH 3/4] Add more details to the changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60aa18ec..8656a21c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ## 2.3.0-wip -- Add leftTranslateByVector2 method to Matrix4. +- Add leftTranslateByVector2 method to Matrix4 + Equivalent to the leftTranslate set of methods, that multiplies this matrix by a translation matrix from the left. + - Add translateByVector2 method to Matrix4. - Require `sdk: ^3.7.0`. From d8bfa741557c7c4ef44b58a4550808e87272978b Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Wed, 26 Nov 2025 09:59:09 -0500 Subject: [PATCH 4/4] Update CHANGELOG.md Co-authored-by: Kevin Moore --- CHANGELOG.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8656a21c..7d6f2d1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,7 @@ ## 2.3.0-wip -- Add leftTranslateByVector2 method to Matrix4 - Equivalent to the leftTranslate set of methods, that multiplies this matrix by a translation matrix from the left. - +- Add `leftTranslateByVector2` method to `Matrix4`. + Equivalent to the `leftTranslate` set of methods, that multiplies this matrix by a translation matrix from the left. - Add translateByVector2 method to Matrix4. - Require `sdk: ^3.7.0`.