Skip to content

Commit 0568f24

Browse files
committed
feat: Add leftTranslateByVector2 method to Matrix4
1 parent 3939545 commit 0568f24

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

lib/src/vector_math/matrix4.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,13 @@ class Matrix4 {
831831
_m4storage[15] = tw * r4;
832832
}
833833

834+
/// Multiply this by a translation from the left.
835+
@pragma('wasm:prefer-inline')
836+
@pragma('vm:prefer-inline')
837+
@pragma('dart2js:prefer-inline')
838+
void leftTranslateByVector2(Vector2 v2) =>
839+
leftTranslateByDouble(v2.x, v2.y, 0.0, 1.0);
840+
834841
/// Multiply this by a translation from the left.
835842
@pragma('wasm:prefer-inline')
836843
@pragma('vm:prefer-inline')

lib/src/vector_math_64/matrix4.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,13 @@ class Matrix4 {
831831
_m4storage[15] = tw * r4;
832832
}
833833

834+
/// Multiply this by a translation from the left.
835+
@pragma('wasm:prefer-inline')
836+
@pragma('vm:prefer-inline')
837+
@pragma('dart2js:prefer-inline')
838+
void leftTranslateByVector2(Vector2 v2) =>
839+
leftTranslateByDouble(v2.x, v2.y, 0.0, 1.0);
840+
834841
/// Multiply this by a translation from the left.
835842
@pragma('wasm:prefer-inline')
836843
@pragma('vm:prefer-inline')

test/matrix4_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,20 @@ void testLeftTranslate() {
815815
expect(result.x, equals(3.0));
816816
expect(result.y, equals(0.0));
817817
expect(result.z, equals(0.0));
818+
819+
// Matrix4 alternative methods
820+
final m2 = Matrix4.diagonal3Values(2.0, 3.0, 4.0);
821+
final result2 = Matrix4.columns(
822+
Vector4(2.0, 0.0, 0.0, 0.0),
823+
Vector4(0.0, 3.0, 0.0, 0.0),
824+
Vector4(0.0, 0.0, 4.0, 0.0),
825+
Vector4(1.0, 0.0, 0.0, 1.0),
826+
);
827+
828+
expect(m2.clone()..leftTranslateByDouble(1, 0, 0, 1), result2);
829+
expect(m2.clone()..leftTranslateByVector2(Vector2(1, 0)), result2);
830+
expect(m2.clone()..leftTranslateByVector3(Vector3(1, 0, 0)), result2);
831+
expect(m2.clone()..leftTranslateByVector4(Vector4(1, 0, 0, 1)), result2);
818832
}
819833

820834
void testMatrixClassifiers() {

0 commit comments

Comments
 (0)