Skip to content

Commit

Permalink
problems
Browse files Browse the repository at this point in the history
  • Loading branch information
renancaraujo committed Dec 14, 2024
1 parent 61c83c6 commit 7d8a1d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/flame/lib/src/extensions/matrix4.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension Matrix4Extension on Matrix4 {
return transform2(out);
}

Float64List get storage64 => Float64List.sublistView(storage);
Float64List get storage64 => Float64List.fromList(storage);

/// Create a scaled matrix.
///
Expand Down
20 changes: 11 additions & 9 deletions packages/flame/test/game/transform2d_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void main() {

t.position.setFrom(Vector2(7, 2.2));
expect(t.x, 7);
expect(t.y, 2.2);
expect(t.y, closeTo(2.2, _epsilon));
expect(notified, 4);

t.position.setZero();
Expand Down Expand Up @@ -93,12 +93,12 @@ void main() {
test('angle', () {
final t = Transform2D();
t.angle = tau / 6;
expect(t.angleDegrees, closeTo(60, 1e-10));
expect(t.angleDegrees, closeTo(60, 10e-6));
t.angleDegrees = 45;
expect(t.angle, closeTo(tau / 8, 1e-10));
expect(t.angle, closeTo(tau / 8, 10e-6));
t.angle = 1;
expect(t.angle, 1);
expect(t.angleDegrees, closeTo(360 / tau, 1e-10));
expect(t.angleDegrees, closeTo(360 / tau, 10e-6));
});

test('.closeTo', () {
Expand Down Expand Up @@ -173,16 +173,16 @@ void main() {
for (var k = 0; k < 16; k++) {
expect(
transform2d.transformMatrix.storage[k],
closeTo(matrix4.storage[k], 1e-10),
closeTo(matrix4.storage[k], 10e-6),
);
}
// Check round-trip conversion between local and global
final point1 =
Vector2((rnd.nextDouble() - 0.5) * 5, (rnd.nextDouble() - 0.5) * 5);
final point2 =
transform2d.globalToLocal(transform2d.localToGlobal(point1));
expect(point1.x, closeTo(point2.x, 1e-10));
expect(point1.y, closeTo(point2.y, 1e-10));
expect(point1.x, closeTo(point2.x, 10e-6));
expect(point1.y, closeTo(point2.y, 10e-6));
}
});

Expand All @@ -194,12 +194,14 @@ void main() {
expect(t.globalToLocal(point), Vector2(0, 0));

t.angleDegrees = 60;
expect(t.localToGlobal(point).x, closeTo(1 / 2, 1e-10));
expect(t.localToGlobal(point).y, closeTo(math.sqrt(3) / 2, 1e-10));
expect(t.localToGlobal(point).x, closeTo(1 / 2, 10e-6));
expect(t.localToGlobal(point).y, closeTo(math.sqrt(3) / 2, 10e-6));
expect(t.globalToLocal(point), Vector2(0, 0));

t.scale = Vector2(0, 1);
expect(t.globalToLocal(point), Vector2(0, 0));
});
});
}

const _epsilon = 10e-6;

0 comments on commit 7d8a1d0

Please sign in to comment.