Skip to content

Commit

Permalink
fix: Clone input vector before projecting it (#1255)
Browse files Browse the repository at this point in the history
* Clone input vector before flipping

* Add test for projectVector
  • Loading branch information
ufrshubham authored Dec 20, 2021
1 parent 4f0fb2d commit d1d6ad4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/flame_forge2d/lib/forge2d_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Forge2DCamera extends Camera {

@override
Vector2 projectVector(Vector2 worldCoordinates) {
return ((worldCoordinates..y *= -1) - position)..scale(zoom);
return ((worldCoordinates.clone()..y *= -1) - position)..scale(zoom);
}

@override
Expand Down
10 changes: 10 additions & 0 deletions packages/flame_forge2d/test/position_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ void main() {
});
},
);
group(
'Test input vector does not get modified while function call',
() {
test('Camera should not modify the input vector while projecting it', () {
final vec = Vector2(5, 6);
TestGame().camera.projectVector(vec);
expect(vec, Vector2(5, 6));
});
},
);
}

0 comments on commit d1d6ad4

Please sign in to comment.