Skip to content

Commit eb942f1

Browse files
committed
wip
1 parent 03a51c5 commit eb942f1

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

benchmark/matrix_bench.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,14 +395,14 @@ class Matrix4TranslateByDoubleBenchmark extends BenchmarkBase {
395395
void setup() {
396396
for (var i = 0; i < 10; i++) {
397397
temp.translateByDouble(
398-
i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble(), 1.0);
398+
i.toDouble(), (i * 10).toDouble(), (i * 5).toDouble());
399399
}
400400
}
401401

402402
@override
403403
void run() {
404404
for (var i = 0; i < 100; i++) {
405-
temp.translateByDouble(10.0, 20.0, 30.0, 1.0);
405+
temp.translateByDouble(10.0, 20.0, 30.0);
406406
}
407407
}
408408
}

lib/src/vector_math/matrix4.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,14 @@ class Matrix4 {
684684
} else if (x is Vector4) {
685685
translateByVector4(x);
686686
} else if (x is double) {
687-
translateByDouble(x, y, z, 1.0);
687+
translateByDouble(x, y, z);
688688
} else {
689689
throw UnimplementedError();
690690
}
691691
}
692692

693693
/// Translate this matrix by x, y, z, w.
694-
void translateByDouble(double tx, double ty, double tz, double tw) {
694+
void translateByDouble(double tx, double ty, double tz, [double tw = 1.0]) {
695695
final t1 = _m4storage[0] * tx +
696696
_m4storage[4] * ty +
697697
_m4storage[8] * tz +
@@ -721,8 +721,7 @@ class Matrix4 {
721721
@pragma('wasm:prefer-inline')
722722
@pragma('vm:prefer-inline')
723723
@pragma('dart2js:prefer-inline')
724-
void translateByVector3(Vector3 v3) =>
725-
translateByDouble(v3.x, v3.y, v3.z, 1.0);
724+
void translateByVector3(Vector3 v3) => translateByDouble(v3.x, v3.y, v3.z);
726725

727726
/// Translate this matrix by a [Vector4].
728727
@pragma('wasm:prefer-inline')
@@ -750,14 +749,15 @@ class Matrix4 {
750749
} else if (x is Vector4) {
751750
leftTranslateByVector4(x);
752751
} else if (x is double) {
753-
leftTranslateByDouble(x, y, z, 1.0);
752+
leftTranslateByDouble(x, y, z);
754753
} else {
755754
throw UnimplementedError();
756755
}
757756
}
758757

759758
/// Multiply this by a translation from the left.
760-
void leftTranslateByDouble(double tx, double ty, double tz, double tw) {
759+
void leftTranslateByDouble(double tx, double ty, double tz,
760+
[double tw = 1.0]) {
761761
// Column 1
762762
final r1 = _m4storage[3];
763763
_m4storage[0] += tx * r1;
@@ -792,7 +792,7 @@ class Matrix4 {
792792
@pragma('vm:prefer-inline')
793793
@pragma('dart2js:prefer-inline')
794794
void leftTranslateByVector3(Vector3 v3) =>
795-
leftTranslateByDouble(v3.x, v3.y, v3.z, 1.0);
795+
leftTranslateByDouble(v3.x, v3.y, v3.z);
796796

797797
/// Multiply this by a translation from the left.
798798
@pragma('wasm:prefer-inline')
@@ -928,14 +928,14 @@ class Matrix4 {
928928
} else if (x is Vector4) {
929929
scaleByVector4(x);
930930
} else if (x is double) {
931-
scaleByDouble(x, y ?? x, z ?? x, 1.0);
931+
scaleByDouble(x, y ?? x, z ?? x);
932932
} else {
933933
throw UnimplementedError();
934934
}
935935
}
936936

937937
/// Scale this matrix.
938-
void scaleByDouble(double sx, double sy, double sz, double sw) {
938+
void scaleByDouble(double sx, double sy, double sz, [double sw = 1.0]) {
939939
_m4storage[0] *= sx;
940940
_m4storage[1] *= sx;
941941
_m4storage[2] *= sx;
@@ -958,7 +958,7 @@ class Matrix4 {
958958
@pragma('wasm:prefer-inline')
959959
@pragma('vm:prefer-inline')
960960
@pragma('dart2js:prefer-inline')
961-
void scaleByVector3(Vector3 v3) => scaleByDouble(v3.x, v3.y, v3.z, 1.0);
961+
void scaleByVector3(Vector3 v3) => scaleByDouble(v3.x, v3.y, v3.z);
962962

963963
/// Scale this matrix.
964964
@pragma('wasm:prefer-inline')

lib/src/vector_math/opengl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) {
278278
Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
279279
final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
280280
planeNormal.storage[2], 0.0);
281-
final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0, 1.0);
281+
final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0);
282282
var r = Matrix4.zero();
283283
r = r - outer;
284284
final scale = 2.0 * planePoint.dot(planeNormal);

lib/src/vector_math_64/matrix4.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -684,14 +684,14 @@ class Matrix4 {
684684
} else if (x is Vector4) {
685685
translateByVector4(x);
686686
} else if (x is double) {
687-
translateByDouble(x, y, z, 1.0);
687+
translateByDouble(x, y, z);
688688
} else {
689689
throw UnimplementedError();
690690
}
691691
}
692692

693693
/// Translate this matrix by x, y, z, w.
694-
void translateByDouble(double tx, double ty, double tz, double tw) {
694+
void translateByDouble(double tx, double ty, double tz, [double tw = 1.0]) {
695695
final t1 = _m4storage[0] * tx +
696696
_m4storage[4] * ty +
697697
_m4storage[8] * tz +
@@ -721,8 +721,7 @@ class Matrix4 {
721721
@pragma('wasm:prefer-inline')
722722
@pragma('vm:prefer-inline')
723723
@pragma('dart2js:prefer-inline')
724-
void translateByVector3(Vector3 v3) =>
725-
translateByDouble(v3.x, v3.y, v3.z, 1.0);
724+
void translateByVector3(Vector3 v3) => translateByDouble(v3.x, v3.y, v3.z);
726725

727726
/// Translate this matrix by a [Vector4].
728727
@pragma('wasm:prefer-inline')
@@ -750,14 +749,15 @@ class Matrix4 {
750749
} else if (x is Vector4) {
751750
leftTranslateByVector4(x);
752751
} else if (x is double) {
753-
leftTranslateByDouble(x, y, z, 1.0);
752+
leftTranslateByDouble(x, y, z);
754753
} else {
755754
throw UnimplementedError();
756755
}
757756
}
758757

759758
/// Multiply this by a translation from the left.
760-
void leftTranslateByDouble(double tx, double ty, double tz, double tw) {
759+
void leftTranslateByDouble(double tx, double ty, double tz,
760+
[double tw = 1.0]) {
761761
// Column 1
762762
final r1 = _m4storage[3];
763763
_m4storage[0] += tx * r1;
@@ -792,7 +792,7 @@ class Matrix4 {
792792
@pragma('vm:prefer-inline')
793793
@pragma('dart2js:prefer-inline')
794794
void leftTranslateByVector3(Vector3 v3) =>
795-
leftTranslateByDouble(v3.x, v3.y, v3.z, 1.0);
795+
leftTranslateByDouble(v3.x, v3.y, v3.z);
796796

797797
/// Multiply this by a translation from the left.
798798
@pragma('wasm:prefer-inline')
@@ -928,14 +928,14 @@ class Matrix4 {
928928
} else if (x is Vector4) {
929929
scaleByVector4(x);
930930
} else if (x is double) {
931-
scaleByDouble(x, y ?? x, z ?? x, 1.0);
931+
scaleByDouble(x, y ?? x, z ?? x);
932932
} else {
933933
throw UnimplementedError();
934934
}
935935
}
936936

937937
/// Scale this matrix.
938-
void scaleByDouble(double sx, double sy, double sz, double sw) {
938+
void scaleByDouble(double sx, double sy, double sz, [double sw = 1.0]) {
939939
_m4storage[0] *= sx;
940940
_m4storage[1] *= sx;
941941
_m4storage[2] *= sx;
@@ -958,7 +958,7 @@ class Matrix4 {
958958
@pragma('wasm:prefer-inline')
959959
@pragma('vm:prefer-inline')
960960
@pragma('dart2js:prefer-inline')
961-
void scaleByVector3(Vector3 v3) => scaleByDouble(v3.x, v3.y, v3.z, 1.0);
961+
void scaleByVector3(Vector3 v3) => scaleByDouble(v3.x, v3.y, v3.z);
962962

963963
/// Scale this matrix.
964964
@pragma('wasm:prefer-inline')

lib/src/vector_math_64/opengl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Matrix4 makePlaneProjection(Vector3 planeNormal, Vector3 planePoint) {
278278
Matrix4 makePlaneReflection(Vector3 planeNormal, Vector3 planePoint) {
279279
final v = Vector4(planeNormal.storage[0], planeNormal.storage[1],
280280
planeNormal.storage[2], 0.0);
281-
final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0, 1.0);
281+
final outer = Matrix4.outer(v, v)..scaleByDouble(2.0, 2.0, 2.0);
282282
var r = Matrix4.zero();
283283
r = r - outer;
284284
final scale = 2.0 * planePoint.dot(planeNormal);

test/matrix4_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ void testMatrix4Translation() {
387387
output3[14] = input.dotRow(2, Vector4(4, 8, 12, 1));
388388
output3[15] = input.dotRow(3, Vector4(4, 8, 12, 1));
389389
relativeTest(
390-
input.clone()..translateByDouble(4.0, 8.0, 12.0, 1.0),
390+
input.clone()..translateByDouble(4.0, 8.0, 12.0),
391391
output3,
392392
);
393393
relativeTest(

0 commit comments

Comments
 (0)