From b89038c2653ebf6fdf85551d993e91efbc2d100e Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 20:32:37 +0000 Subject: [PATCH 1/9] feat: use vector_math 32 --- packages/flame/lib/src/camera/behaviors/follow_behavior.dart | 2 +- .../flame/lib/src/camera/viewports/circular_viewport.dart | 2 +- .../lib/src/camera/viewports/fixed_aspect_ratio_viewport.dart | 2 +- .../flame/lib/src/camera/viewports/fixed_size_viewport.dart | 2 +- packages/flame/lib/src/camera/viewports/max_viewport.dart | 2 +- packages/flame/lib/src/camera/world.dart | 2 +- .../flame/lib/src/components/mixins/coordinate_transform.dart | 2 +- packages/flame/lib/src/effects/anchor_by_effect.dart | 2 +- packages/flame/lib/src/effects/anchor_to_effect.dart | 2 +- packages/flame/lib/src/effects/move_by_effect.dart | 2 +- packages/flame/lib/src/effects/move_to_effect.dart | 2 +- .../src/experimental/geometry/shapes/rounded_rectangle.dart | 2 +- .../flame/lib/src/experimental/geometry/shapes/shape.dart | 2 +- packages/flame/lib/src/extensions/matrix4.dart | 4 ++-- packages/flame/lib/src/extensions/vector2.dart | 4 ++-- packages/flame/lib/src/game/notifying_vector2.dart | 2 +- packages/flame/lib/src/game/transform2d.dart | 2 +- packages/flame/lib/src/math/tmp_vector2.dart | 2 +- packages/flame/lib/src/rendering/rotate3d_decorator.dart | 2 +- packages/flame/lib/src/rendering/shadow3d_decorator.dart | 2 +- .../camera/behaviors/viewport_aware_bounds_behavior_test.dart | 2 +- .../camera/viewports/fixed_aspect_ratio_viewport_test.dart | 2 +- packages/flame/test/components/text_component_test.dart | 2 +- packages/flame/test/extensions/aabb_test.dart | 2 +- packages/flame/test/game/notifying_vector2_test.dart | 2 +- packages/flame/test/game/transform2d_test.dart | 2 +- packages/flame_test/lib/src/close_to_aabb.dart | 2 +- packages/flame_test/lib/src/close_to_vector.dart | 2 +- packages/flame_test/test/close_to_aabb_test.dart | 2 +- packages/flame_test/test/close_to_vector_test.dart | 2 +- 30 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/flame/lib/src/camera/behaviors/follow_behavior.dart b/packages/flame/lib/src/camera/behaviors/follow_behavior.dart index c6e99e13275..2e38dafe015 100644 --- a/packages/flame/lib/src/camera/behaviors/follow_behavior.dart +++ b/packages/flame/lib/src/camera/behaviors/follow_behavior.dart @@ -3,7 +3,7 @@ import 'package:flame/src/camera/viewport.dart'; import 'package:flame/src/components/core/component.dart'; import 'package:flame/src/components/position_component.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// This behavior will make the [owner] follow the [target]. /// diff --git a/packages/flame/lib/src/camera/viewports/circular_viewport.dart b/packages/flame/lib/src/camera/viewports/circular_viewport.dart index 2230dd67b04..022bd675aca 100644 --- a/packages/flame/lib/src/camera/viewports/circular_viewport.dart +++ b/packages/flame/lib/src/camera/viewports/circular_viewport.dart @@ -1,7 +1,7 @@ import 'dart:ui'; import 'package:flame/src/camera/viewport.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// A fixed-size viewport in the shape of a circle (or ellipse). /// diff --git a/packages/flame/lib/src/camera/viewports/fixed_aspect_ratio_viewport.dart b/packages/flame/lib/src/camera/viewports/fixed_aspect_ratio_viewport.dart index a4aced611a9..2508bf952be 100644 --- a/packages/flame/lib/src/camera/viewports/fixed_aspect_ratio_viewport.dart +++ b/packages/flame/lib/src/camera/viewports/fixed_aspect_ratio_viewport.dart @@ -2,7 +2,7 @@ import 'dart:ui'; import 'package:flame/src/camera/viewport.dart'; import 'package:meta/meta.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// [FixedAspectRatioViewport] is a rectangular viewport which auto-expands to /// take as much space as possible within the canvas, while maintaining a fixed diff --git a/packages/flame/lib/src/camera/viewports/fixed_size_viewport.dart b/packages/flame/lib/src/camera/viewports/fixed_size_viewport.dart index 542d3a8a145..b626c0ac9a7 100644 --- a/packages/flame/lib/src/camera/viewports/fixed_size_viewport.dart +++ b/packages/flame/lib/src/camera/viewports/fixed_size_viewport.dart @@ -1,7 +1,7 @@ import 'dart:ui'; import 'package:flame/src/camera/viewport.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// A rectangular viewport with fixed dimensions. /// diff --git a/packages/flame/lib/src/camera/viewports/max_viewport.dart b/packages/flame/lib/src/camera/viewports/max_viewport.dart index 9ae3b75bd0f..b90c7015317 100644 --- a/packages/flame/lib/src/camera/viewports/max_viewport.dart +++ b/packages/flame/lib/src/camera/viewports/max_viewport.dart @@ -2,7 +2,7 @@ import 'dart:ui'; import 'package:flame/src/camera/viewport.dart'; import 'package:meta/meta.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// The default viewport, which is as big as the game canvas allows. /// diff --git a/packages/flame/lib/src/camera/world.dart b/packages/flame/lib/src/camera/world.dart index a2a023ba0ca..28a06c01ad8 100644 --- a/packages/flame/lib/src/camera/world.dart +++ b/packages/flame/lib/src/camera/world.dart @@ -3,7 +3,7 @@ import 'dart:ui'; import 'package:flame/src/camera/camera_component.dart'; import 'package:flame/src/components/core/component.dart'; import 'package:flame/src/components/mixins/coordinate_transform.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// The root component for all game world elements. /// diff --git a/packages/flame/lib/src/components/mixins/coordinate_transform.dart b/packages/flame/lib/src/components/mixins/coordinate_transform.dart index 8bc451908a3..c93100c710f 100644 --- a/packages/flame/lib/src/components/mixins/coordinate_transform.dart +++ b/packages/flame/lib/src/components/mixins/coordinate_transform.dart @@ -1,5 +1,5 @@ import 'package:flame/src/components/core/component.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// Interface to be implemented by components that perform a coordinate change. /// diff --git a/packages/flame/lib/src/effects/anchor_by_effect.dart b/packages/flame/lib/src/effects/anchor_by_effect.dart index edc7b7bf812..5aa28fe1075 100644 --- a/packages/flame/lib/src/effects/anchor_by_effect.dart +++ b/packages/flame/lib/src/effects/anchor_by_effect.dart @@ -2,7 +2,7 @@ import 'package:flame/src/anchor.dart'; import 'package:flame/src/effects/anchor_effect.dart'; import 'package:flame/src/effects/controllers/effect_controller.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// An [AnchorEffect] that changes its target's anchor by the specified offset. /// diff --git a/packages/flame/lib/src/effects/anchor_to_effect.dart b/packages/flame/lib/src/effects/anchor_to_effect.dart index 8b881a59f18..d6e74b3adc0 100644 --- a/packages/flame/lib/src/effects/anchor_to_effect.dart +++ b/packages/flame/lib/src/effects/anchor_to_effect.dart @@ -2,7 +2,7 @@ import 'package:flame/src/anchor.dart'; import 'package:flame/src/effects/anchor_effect.dart'; import 'package:flame/src/effects/controllers/effect_controller.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// An effect that moves the target's anchor to the specified value. /// diff --git a/packages/flame/lib/src/effects/move_by_effect.dart b/packages/flame/lib/src/effects/move_by_effect.dart index 1e1bbf7eb67..43052d04bff 100644 --- a/packages/flame/lib/src/effects/move_by_effect.dart +++ b/packages/flame/lib/src/effects/move_by_effect.dart @@ -1,7 +1,7 @@ import 'package:flame/src/effects/controllers/effect_controller.dart'; import 'package:flame/src/effects/move_effect.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// A [MoveEffect] that moves its target by the specified offset vector. /// diff --git a/packages/flame/lib/src/effects/move_to_effect.dart b/packages/flame/lib/src/effects/move_to_effect.dart index 81e86db8612..89b1107d1ae 100644 --- a/packages/flame/lib/src/effects/move_to_effect.dart +++ b/packages/flame/lib/src/effects/move_to_effect.dart @@ -2,7 +2,7 @@ import 'package:flame/src/effects/controllers/effect_controller.dart'; import 'package:flame/src/effects/move_by_effect.dart'; import 'package:flame/src/effects/move_effect.dart'; import 'package:flame/src/effects/provider_interfaces.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// A [MoveEffect] that moves its target towards the given destination point. /// diff --git a/packages/flame/lib/src/experimental/geometry/shapes/rounded_rectangle.dart b/packages/flame/lib/src/experimental/geometry/shapes/rounded_rectangle.dart index 40aa5ff18f0..15dce372269 100644 --- a/packages/flame/lib/src/experimental/geometry/shapes/rounded_rectangle.dart +++ b/packages/flame/lib/src/experimental/geometry/shapes/rounded_rectangle.dart @@ -5,7 +5,7 @@ import 'package:flame/geometry.dart'; import 'package:flame/math.dart'; import 'package:flame/src/experimental/geometry/shapes/shape.dart'; import 'package:flame/src/game/transform2d.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// An axis-aligned rectangle with rounded corners. /// diff --git a/packages/flame/lib/src/experimental/geometry/shapes/shape.dart b/packages/flame/lib/src/experimental/geometry/shapes/shape.dart index e905e5c9989..c906cee0b43 100644 --- a/packages/flame/lib/src/experimental/geometry/shapes/shape.dart +++ b/packages/flame/lib/src/experimental/geometry/shapes/shape.dart @@ -6,7 +6,7 @@ import 'package:flame/src/experimental/geometry/shapes/polygon.dart'; import 'package:flame/src/experimental/geometry/shapes/rectangle.dart'; import 'package:flame/src/experimental/geometry/shapes/rounded_rectangle.dart'; import 'package:flame/src/game/transform2d.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// Base class for various 2D geometric primitives defined on a Cartesian /// coordinate plane. diff --git a/packages/flame/lib/src/extensions/matrix4.dart b/packages/flame/lib/src/extensions/matrix4.dart index 0c2efb24d0a..f875cce77ef 100644 --- a/packages/flame/lib/src/extensions/matrix4.dart +++ b/packages/flame/lib/src/extensions/matrix4.dart @@ -1,6 +1,6 @@ -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; -export 'package:vector_math/vector_math_64.dart' hide Colors; +export 'package:vector_math/vector_math.dart' hide Colors; extension Matrix4Extension on Matrix4 { /// A first row and first column value. diff --git a/packages/flame/lib/src/extensions/vector2.dart b/packages/flame/lib/src/extensions/vector2.dart index 5fbec23e2f2..aceae4b7925 100644 --- a/packages/flame/lib/src/extensions/vector2.dart +++ b/packages/flame/lib/src/extensions/vector2.dart @@ -1,9 +1,9 @@ import 'dart:math'; import 'dart:ui'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; -export 'package:vector_math/vector_math_64.dart' hide Colors; +export 'package:vector_math/vector_math.dart' hide Colors; extension Vector2Extension on Vector2 { /// This is a reusable vector that can be used within the [Vector2Extension] diff --git a/packages/flame/lib/src/game/notifying_vector2.dart b/packages/flame/lib/src/game/notifying_vector2.dart index aed3dcb4a21..649aab4cd96 100644 --- a/packages/flame/lib/src/game/notifying_vector2.dart +++ b/packages/flame/lib/src/game/notifying_vector2.dart @@ -1,5 +1,5 @@ import 'package:flutter/foundation.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// Extension of the standard [Vector2] class, implementing the [ChangeNotifier] /// functionality. This allows any interested party to be notified when the diff --git a/packages/flame/lib/src/game/transform2d.dart b/packages/flame/lib/src/game/transform2d.dart index edd84b18580..ebce5418f44 100644 --- a/packages/flame/lib/src/game/transform2d.dart +++ b/packages/flame/lib/src/game/transform2d.dart @@ -3,7 +3,7 @@ import 'dart:math' as math; import 'package:flame/geometry.dart' as geometry; import 'package:flame/src/game/notifying_vector2.dart'; import 'package:flutter/foundation.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// This class describes a generic 2D transform, which is a combination of /// translations, rotations, reflections and scaling. These transforms are diff --git a/packages/flame/lib/src/math/tmp_vector2.dart b/packages/flame/lib/src/math/tmp_vector2.dart index d3d112550d3..e2d07cf8c5b 100644 --- a/packages/flame/lib/src/math/tmp_vector2.dart +++ b/packages/flame/lib/src/math/tmp_vector2.dart @@ -1,5 +1,5 @@ import 'package:meta/meta.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// Use internally when you need a temporary [Vector2] object but don't want to /// instantiate a new one due to performance. diff --git a/packages/flame/lib/src/rendering/rotate3d_decorator.dart b/packages/flame/lib/src/rendering/rotate3d_decorator.dart index 83e0030aa77..52c4fef05ed 100644 --- a/packages/flame/lib/src/rendering/rotate3d_decorator.dart +++ b/packages/flame/lib/src/rendering/rotate3d_decorator.dart @@ -2,7 +2,7 @@ import 'dart:ui'; import 'package:flame/geometry.dart'; import 'package:flame/src/rendering/decorator.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// [Rotate3DDecorator] treats the underlying component as if it was a flat /// sheet of paper, and applies a 3D rotation to it. diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index 47c96a37d88..1e00569b812 100644 --- a/packages/flame/lib/src/rendering/shadow3d_decorator.dart +++ b/packages/flame/lib/src/rendering/shadow3d_decorator.dart @@ -2,7 +2,7 @@ import 'dart:ui'; import 'package:flame/src/palette.dart'; import 'package:flame/src/rendering/decorator.dart'; -import 'package:vector_math/vector_math_64.dart' show Matrix4, Vector2; +import 'package:vector_math/vector_math.dart' show Matrix4, Vector2; /// [Shadow3DDecorator] casts a realistic-looking shadow from the component /// onto the ground. diff --git a/packages/flame/test/camera/behaviors/viewport_aware_bounds_behavior_test.dart b/packages/flame/test/camera/behaviors/viewport_aware_bounds_behavior_test.dart index fe9fe7bce97..f6f7ffa8b4c 100644 --- a/packages/flame/test/camera/behaviors/viewport_aware_bounds_behavior_test.dart +++ b/packages/flame/test/camera/behaviors/viewport_aware_bounds_behavior_test.dart @@ -4,7 +4,7 @@ import 'package:flame/camera.dart'; import 'package:flame/experimental.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('ViewportAwareBoundsBehavior', () { diff --git a/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart b/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart index b8fff2cb71a..18c14461b88 100644 --- a/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart +++ b/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart @@ -4,7 +4,7 @@ import 'dart:ui'; import 'package:flame/camera.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('FixedAspectRatioViewport', () { diff --git a/packages/flame/test/components/text_component_test.dart b/packages/flame/test/components/text_component_test.dart index 5c9dda23871..d1c3cfd5806 100644 --- a/packages/flame/test/components/text_component_test.dart +++ b/packages/flame/test/components/text_component_test.dart @@ -1,6 +1,6 @@ import 'package:flame/src/components/text_component.dart'; import 'package:test/test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('TextComponent', () { diff --git a/packages/flame/test/extensions/aabb_test.dart b/packages/flame/test/extensions/aabb_test.dart index f143e0091cf..fbd98107189 100644 --- a/packages/flame/test/extensions/aabb_test.dart +++ b/packages/flame/test/extensions/aabb_test.dart @@ -7,7 +7,7 @@ import 'package:test/test.dart'; void main() { group('Aabb2Extension', () { // aabb2 is an axis aligned bounding box between a min and a max - // see https://api.flutter.dev/flutter/vector_math_64/Aabb2-class.html + // see https://api.flutter.dev/flutter/vector_math/Aabb2-class.html // The extension is used to convert this bounding box to a rect. test('Default aabb constructor', () { final aab2 = Aabb2(); diff --git a/packages/flame/test/game/notifying_vector2_test.dart b/packages/flame/test/game/notifying_vector2_test.dart index 6f5eeeddecb..8ef0495089f 100644 --- a/packages/flame/test/game/notifying_vector2_test.dart +++ b/packages/flame/test/game/notifying_vector2_test.dart @@ -1,6 +1,6 @@ import 'package:flame/src/game/notifying_vector2.dart'; import 'package:test/test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { /// This helper function creates a "normal" Vector2 copy of [v1], diff --git a/packages/flame/test/game/transform2d_test.dart b/packages/flame/test/game/transform2d_test.dart index cb2e80eb01b..4eba2acc092 100644 --- a/packages/flame/test/game/transform2d_test.dart +++ b/packages/flame/test/game/transform2d_test.dart @@ -3,7 +3,7 @@ import 'dart:math' as math; import 'package:flame/geometry.dart'; import 'package:flame/src/game/transform2d.dart'; import 'package:test/test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('Transform2D', () { diff --git a/packages/flame_test/lib/src/close_to_aabb.dart b/packages/flame_test/lib/src/close_to_aabb.dart index 1bf79134a7c..92712a54fcb 100644 --- a/packages/flame_test/lib/src/close_to_aabb.dart +++ b/packages/flame_test/lib/src/close_to_aabb.dart @@ -1,5 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// Returns a matcher which checks if the argument is an axis-aligned bounding /// box sufficiently close (within distance [epsilon]) to [expected]. Example diff --git a/packages/flame_test/lib/src/close_to_vector.dart b/packages/flame_test/lib/src/close_to_vector.dart index b6b17a9bd3b..1525bf77023 100644 --- a/packages/flame_test/lib/src/close_to_vector.dart +++ b/packages/flame_test/lib/src/close_to_vector.dart @@ -1,5 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; /// Returns a matcher which checks if the argument is a vector within distance /// [epsilon] of [vector]. For example: diff --git a/packages/flame_test/test/close_to_aabb_test.dart b/packages/flame_test/test/close_to_aabb_test.dart index 3f1d4e2efcf..391daa01bd3 100644 --- a/packages/flame_test/test/close_to_aabb_test.dart +++ b/packages/flame_test/test/close_to_aabb_test.dart @@ -1,6 +1,6 @@ import 'package:flame_test/src/close_to_aabb.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('closeToAabb', () { diff --git a/packages/flame_test/test/close_to_vector_test.dart b/packages/flame_test/test/close_to_vector_test.dart index 2b519370227..80cbd7f7f65 100644 --- a/packages/flame_test/test/close_to_vector_test.dart +++ b/packages/flame_test/test/close_to_vector_test.dart @@ -1,6 +1,6 @@ import 'package:flame_test/src/close_to_vector.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:vector_math/vector_math_64.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('closeToVector', () { From 8ea2120db742f7f9dd9b0ab4f1f3848c0ac8325f Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 20:52:26 +0000 Subject: [PATCH 2/9] deal with matrix4 --- packages/flame/lib/extensions.dart | 1 - packages/flame/lib/extensions_matrix4.dart | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 packages/flame/lib/extensions_matrix4.dart diff --git a/packages/flame/lib/extensions.dart b/packages/flame/lib/extensions.dart index 28d422f2b1a..5792b6f81b5 100644 --- a/packages/flame/lib/extensions.dart +++ b/packages/flame/lib/extensions.dart @@ -4,7 +4,6 @@ export 'src/extensions/color.dart'; export 'src/extensions/double.dart'; export 'src/extensions/image.dart'; export 'src/extensions/list.dart'; -export 'src/extensions/matrix4.dart'; export 'src/extensions/offset.dart'; export 'src/extensions/paint.dart'; export 'src/extensions/picture.dart'; diff --git a/packages/flame/lib/extensions_matrix4.dart b/packages/flame/lib/extensions_matrix4.dart new file mode 100644 index 00000000000..46e8e0011b6 --- /dev/null +++ b/packages/flame/lib/extensions_matrix4.dart @@ -0,0 +1 @@ +export 'src/extensions/matrix4.dart'; From dd103b42e2bf79a72f8d12c0f218a1d4c5226052 Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 21:45:54 +0000 Subject: [PATCH 3/9] refactors renames and other stuff --- .../camera_component_example.dart | 19 ++++++++++++++++--- .../lib/src/components/mixins/snapshot.dart | 9 ++++----- packages/flame/lib/src/extensions/canvas.dart | 3 ++- .../flame/lib/src/game/notifying_vector2.dart | 2 +- .../lib/src/rendering/rotate3d_decorator.dart | 3 ++- .../lib/src/rendering/shadow3d_decorator.dart | 3 ++- .../src/rendering/transform2d_decorator.dart | 3 ++- packages/flame/lib/src/sprite_batch.dart | 3 ++- .../test/components/mixins/snapshot_test.dart | 1 - .../flame/test/extensions/matrix4_test.dart | 2 +- .../flame_forge2d/lib/body_component.dart | 3 ++- packages/flame_forge2d/pubspec.yaml | 2 +- .../src/widgets/panels/hierarchy_view.dart | 2 +- 13 files changed, 36 insertions(+), 19 deletions(-) diff --git a/examples/lib/stories/camera_and_viewport/camera_component_example.dart b/examples/lib/stories/camera_and_viewport/camera_component_example.dart index e7cb8ea6d10..4e4b045dc08 100644 --- a/examples/lib/stories/camera_and_viewport/camera_component_example.dart +++ b/examples/lib/stories/camera_and_viewport/camera_component_example.dart @@ -1,4 +1,5 @@ import 'dart:math'; +import 'dart:typed_data'; import 'package:flame/camera.dart'; import 'package:flame/components.dart'; @@ -116,13 +117,25 @@ class Bezel extends PositionComponent { const Radius.circular(5.0), ), )) - .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); + .transform( + Float64List.fromList( + (Matrix4.identity()..rotateZ(pi / 4)).storage, + ), + ); connector = (Path() ..addArc(Rect.fromLTRB(-outer, -outer, outer, outer), -0.22, 0.44)) - .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); + .transform( + Float64List.fromList( + (Matrix4.identity()..rotateZ(pi / 4)).storage, + ), + ); specularHighlight = (Path() ..addOval(Rect.fromLTWH(-radius * 0.8, -8, 16, radius * 0.3))) - .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); + .transform( + Float64List.fromList( + (Matrix4.identity()..rotateZ(pi / 4)).storage, + ), + ); glassPaint = Paint()..color = const Color(0x1400ffae); rimBorderPaint = Paint() diff --git a/packages/flame/lib/src/components/mixins/snapshot.dart b/packages/flame/lib/src/components/mixins/snapshot.dart index a8ac48689d3..3580467438b 100644 --- a/packages/flame/lib/src/components/mixins/snapshot.dart +++ b/packages/flame/lib/src/components/mixins/snapshot.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/components.dart'; @@ -47,7 +48,7 @@ mixin Snapshot on PositionComponent { } else { final recorder = PictureRecorder(); final canvas = Canvas(recorder); - canvas.transform(transform.storage); + canvas.transform(Float64List.fromList(transform.storage)); canvas.drawPicture(_picture!); final picture = recorder.endRecording(); return picture.toImageSync(width, height); @@ -63,7 +64,7 @@ mixin Snapshot on PositionComponent { final canvas = Canvas(recorder); final matrix = transformMatrix.clone(); matrix.invert(); - canvas.transform(matrix.storage); + canvas.transform(Float64List.fromList(matrix.storage)); super.renderTree(canvas); _picture = recorder.endRecording(); return _picture!; @@ -82,9 +83,7 @@ mixin Snapshot on PositionComponent { takeSnapshot(); } canvas.save(); - canvas.transform( - transformMatrix.storage, - ); + canvas.transform(Float64List.fromList(transformMatrix.storage)); canvas.drawPicture(_picture!); canvas.restore(); } else { diff --git a/packages/flame/lib/src/extensions/canvas.dart b/packages/flame/lib/src/extensions/canvas.dart index b9e739169e8..d54478a4a66 100644 --- a/packages/flame/lib/src/extensions/canvas.dart +++ b/packages/flame/lib/src/extensions/canvas.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/palette.dart'; @@ -59,6 +60,6 @@ extension CanvasExtension on Canvas { /// Use the [Transform2D] object to [transform] the canvas. void transform2D(Transform2D transform2D) { - transform(transform2D.transformMatrix.storage); + transform(Float64List.fromList(transform2D.transformMatrix.storage)); } } diff --git a/packages/flame/lib/src/game/notifying_vector2.dart b/packages/flame/lib/src/game/notifying_vector2.dart index 649aab4cd96..7c25662931c 100644 --- a/packages/flame/lib/src/game/notifying_vector2.dart +++ b/packages/flame/lib/src/game/notifying_vector2.dart @@ -185,5 +185,5 @@ class NotifyingVector2 extends Vector2 with ChangeNotifier { } @override - Float64List get storage => super.storage.asUnmodifiableView(); + Float32List get storage => super.storage.asUnmodifiableView(); } diff --git a/packages/flame/lib/src/rendering/rotate3d_decorator.dart b/packages/flame/lib/src/rendering/rotate3d_decorator.dart index 52c4fef05ed..647fdb1d579 100644 --- a/packages/flame/lib/src/rendering/rotate3d_decorator.dart +++ b/packages/flame/lib/src/rendering/rotate3d_decorator.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/geometry.dart'; @@ -61,7 +62,7 @@ class Rotate3DDecorator extends Decorator { ..rotateY(angleY) ..rotateZ(angleZ) ..translate(-center.x, -center.y); - canvas.transform(matrix.storage); + canvas.transform(Float64List.fromList(matrix.storage)); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index 1e00569b812..600c57cf693 100644 --- a/packages/flame/lib/src/rendering/shadow3d_decorator.dart +++ b/packages/flame/lib/src/rendering/shadow3d_decorator.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/src/palette.dart'; @@ -156,7 +157,7 @@ class Shadow3DDecorator extends Decorator { canvas.saveLayer(null, _paint!); canvas.translate(base.x + _shift, base.y); - canvas.transform(_transformMatrix!.storage); + canvas.transform(Float64List.fromList(_transformMatrix!.storage)); draw(canvas); canvas.restore(); draw(canvas); diff --git a/packages/flame/lib/src/rendering/transform2d_decorator.dart b/packages/flame/lib/src/rendering/transform2d_decorator.dart index 3a1cd83401a..5585285305f 100644 --- a/packages/flame/lib/src/rendering/transform2d_decorator.dart +++ b/packages/flame/lib/src/rendering/transform2d_decorator.dart @@ -1,3 +1,4 @@ +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/src/components/position_component.dart'; @@ -17,7 +18,7 @@ class Transform2DDecorator extends Decorator { @override void apply(void Function(Canvas) draw, Canvas canvas) { canvas.save(); - canvas.transform(transform2d.transformMatrix.storage); + canvas.transform(Float64List.fromList(transform2d.transformMatrix.storage)); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/sprite_batch.dart b/packages/flame/lib/src/sprite_batch.dart index 6b3beeec0ae..b74477ef06b 100644 --- a/packages/flame/lib/src/sprite_batch.dart +++ b/packages/flame/lib/src/sprite_batch.dart @@ -1,5 +1,6 @@ import 'dart:collection'; import 'dart:math' show pi; +import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/cache.dart'; @@ -431,7 +432,7 @@ class SpriteBatch { canvas ..save() - ..transform(batchItem.matrix.storage) + ..transform(Float64List.fromList(batchItem.matrix.storage)) ..drawRect(batchItem.destination, batchItem.paint) ..drawImageRect( atlas, diff --git a/packages/flame/test/components/mixins/snapshot_test.dart b/packages/flame/test/components/mixins/snapshot_test.dart index f02805c1858..2d86e6d3e49 100644 --- a/packages/flame/test/components/mixins/snapshot_test.dart +++ b/packages/flame/test/components/mixins/snapshot_test.dart @@ -5,7 +5,6 @@ import 'package:flame/components.dart'; import 'package:flame/extensions.dart'; import 'package:flame/game.dart'; import 'package:flame_test/flame_test.dart'; -import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/packages/flame/test/extensions/matrix4_test.dart b/packages/flame/test/extensions/matrix4_test.dart index 7f33c76c90a..b4ad5bfbdf9 100644 --- a/packages/flame/test/extensions/matrix4_test.dart +++ b/packages/flame/test/extensions/matrix4_test.dart @@ -1,6 +1,6 @@ import 'dart:math'; -import 'package:flame/extensions.dart'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame_test/flame_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; diff --git a/packages/flame_forge2d/lib/body_component.dart b/packages/flame_forge2d/lib/body_component.dart index 513fab088c9..404042f0dd2 100644 --- a/packages/flame_forge2d/lib/body_component.dart +++ b/packages/flame_forge2d/lib/body_component.dart @@ -3,6 +3,7 @@ import 'dart:ui'; import 'package:flame/components.dart' hide World; import 'package:flame/effects.dart'; import 'package:flame/extensions.dart'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/game.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flutter/foundation.dart'; @@ -101,7 +102,7 @@ class BodyComponent extends Component _lastAngle = angle; } canvas.save(); - canvas.transform(matrix.storage); + canvas.transform(Float64List.fromList(matrix.storage)); super.renderTree(canvas); canvas.restore(); } diff --git a/packages/flame_forge2d/pubspec.yaml b/packages/flame_forge2d/pubspec.yaml index 44ca0b56e38..ba0057b00fa 100644 --- a/packages/flame_forge2d/pubspec.yaml +++ b/packages/flame_forge2d/pubspec.yaml @@ -19,7 +19,7 @@ dependencies: flame: ^1.22.0 flutter: sdk: flutter - forge2d: ^0.13.1 + forge2d: ^0.14.0 dev_dependencies: dartdoc: ^8.0.8 diff --git a/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart b/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart index 65e72a6c57b..0226116996a 100644 --- a/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart +++ b/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart @@ -1,4 +1,4 @@ -import 'package:flame/components.dart'; +import 'package:flame/components.dart' show Component; import 'package:flame_studio/src/core/component_tree.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; From e712848f905b432f538bff38d89821ef84d09b71 Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 21:51:57 +0000 Subject: [PATCH 4/9] hide matrix --- .../camera_component_example.dart | 21 ++++--------------- .../lib/src/components/mixins/snapshot.dart | 1 + .../src/components/position_component.dart | 1 + .../flame/lib/src/extensions/vector2.dart | 5 ++--- packages/flame/lib/src/sprite_batch.dart | 1 + .../test/components/mixins/snapshot_test.dart | 1 + .../components/position_component_test.dart | 1 + packages/flame/test/extensions/rect_test.dart | 1 + .../src/widgets/panels/hierarchy_view.dart | 2 +- 9 files changed, 13 insertions(+), 21 deletions(-) diff --git a/examples/lib/stories/camera_and_viewport/camera_component_example.dart b/examples/lib/stories/camera_and_viewport/camera_component_example.dart index 4e4b045dc08..6ee5804f8cd 100644 --- a/examples/lib/stories/camera_and_viewport/camera_component_example.dart +++ b/examples/lib/stories/camera_and_viewport/camera_component_example.dart @@ -1,5 +1,4 @@ import 'dart:math'; -import 'dart:typed_data'; import 'package:flame/camera.dart'; import 'package:flame/components.dart'; @@ -8,7 +7,7 @@ import 'package:flame/extensions.dart' show OffsetExtension; import 'package:flame/game.dart'; import 'package:flame/geometry.dart'; import 'package:flame/input.dart'; -import 'package:flutter/painting.dart'; +import 'package:flutter/widgets.dart'; class CameraComponentExample extends FlameGame with PanDetector { static const description = ''' @@ -117,25 +116,13 @@ class Bezel extends PositionComponent { const Radius.circular(5.0), ), )) - .transform( - Float64List.fromList( - (Matrix4.identity()..rotateZ(pi / 4)).storage, - ), - ); + .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); connector = (Path() ..addArc(Rect.fromLTRB(-outer, -outer, outer, outer), -0.22, 0.44)) - .transform( - Float64List.fromList( - (Matrix4.identity()..rotateZ(pi / 4)).storage, - ), - ); + .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); specularHighlight = (Path() ..addOval(Rect.fromLTWH(-radius * 0.8, -8, 16, radius * 0.3))) - .transform( - Float64List.fromList( - (Matrix4.identity()..rotateZ(pi / 4)).storage, - ), - ); + .transform((Matrix4.identity()..rotateZ(pi / 4)).storage); glassPaint = Paint()..color = const Color(0x1400ffae); rimBorderPaint = Paint() diff --git a/packages/flame/lib/src/components/mixins/snapshot.dart b/packages/flame/lib/src/components/mixins/snapshot.dart index 3580467438b..d585685d192 100644 --- a/packages/flame/lib/src/components/mixins/snapshot.dart +++ b/packages/flame/lib/src/components/mixins/snapshot.dart @@ -2,6 +2,7 @@ import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/components.dart'; +import 'package:vector_math/vector_math.dart'; /// A mixin that enables caching a component and all its children. If /// [renderSnapshot] is set to `true`, the component and its children will be diff --git a/packages/flame/lib/src/components/position_component.dart b/packages/flame/lib/src/components/position_component.dart index 39d49e97cde..c64e3b9be1e 100644 --- a/packages/flame/lib/src/components/position_component.dart +++ b/packages/flame/lib/src/components/position_component.dart @@ -14,6 +14,7 @@ import 'package:flame/src/game/notifying_vector2.dart'; import 'package:flame/src/game/transform2d.dart'; import 'package:flame/src/rendering/decorator.dart'; import 'package:flame/src/rendering/transform2d_decorator.dart'; +import 'package:vector_math/vector_math.dart'; /// A [Component] implementation that represents an object that can be /// freely moved around the screen, rotated, and scaled. diff --git a/packages/flame/lib/src/extensions/vector2.dart b/packages/flame/lib/src/extensions/vector2.dart index aceae4b7925..3a680f6ad01 100644 --- a/packages/flame/lib/src/extensions/vector2.dart +++ b/packages/flame/lib/src/extensions/vector2.dart @@ -1,9 +1,8 @@ import 'dart:math'; import 'dart:ui'; -import 'package:vector_math/vector_math.dart'; - -export 'package:vector_math/vector_math.dart' hide Colors; +import 'package:vector_math/vector_math.dart' hide Colors, Matrix4; +export 'package:vector_math/vector_math.dart' hide Colors, Matrix4; extension Vector2Extension on Vector2 { /// This is a reusable vector that can be used within the [Vector2Extension] diff --git a/packages/flame/lib/src/sprite_batch.dart b/packages/flame/lib/src/sprite_batch.dart index b74477ef06b..f47df475f84 100644 --- a/packages/flame/lib/src/sprite_batch.dart +++ b/packages/flame/lib/src/sprite_batch.dart @@ -8,6 +8,7 @@ import 'package:flame/extensions.dart'; import 'package:flame/flame.dart'; import 'package:flame/game.dart'; import 'package:meta/meta.dart'; +import 'package:vector_math/vector_math.dart'; extension SpriteBatchExtension on Game { /// Utility method to load and cache the image for a [SpriteBatch] based on diff --git a/packages/flame/test/components/mixins/snapshot_test.dart b/packages/flame/test/components/mixins/snapshot_test.dart index 2d86e6d3e49..6bfe249f20d 100644 --- a/packages/flame/test/components/mixins/snapshot_test.dart +++ b/packages/flame/test/components/mixins/snapshot_test.dart @@ -6,6 +6,7 @@ import 'package:flame/extensions.dart'; import 'package:flame/game.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group( diff --git a/packages/flame/test/components/position_component_test.dart b/packages/flame/test/components/position_component_test.dart index c63b2995136..6c6ff17ee78 100644 --- a/packages/flame/test/components/position_component_test.dart +++ b/packages/flame/test/components/position_component_test.dart @@ -8,6 +8,7 @@ import 'package:flame/game.dart'; import 'package:flame/geometry.dart'; import 'package:flame_test/flame_test.dart'; import 'package:test/test.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('PositionComponent', () { diff --git a/packages/flame/test/extensions/rect_test.dart b/packages/flame/test/extensions/rect_test.dart index 387e07bbe8a..67bd3304c4a 100644 --- a/packages/flame/test/extensions/rect_test.dart +++ b/packages/flame/test/extensions/rect_test.dart @@ -6,6 +6,7 @@ import 'package:flame/geometry.dart'; import 'package:flame_test/flame_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:test/test.dart'; +import 'package:vector_math/vector_math.dart'; void main() { group('RectExtension', () { diff --git a/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart b/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart index 0226116996a..65e72a6c57b 100644 --- a/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart +++ b/packages/flame_studio/lib/src/widgets/panels/hierarchy_view.dart @@ -1,4 +1,4 @@ -import 'package:flame/components.dart' show Component; +import 'package:flame/components.dart'; import 'package:flame_studio/src/core/component_tree.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; From 37835a29432c99bee750f9e8f38e884d0df0cf3a Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 22:15:53 +0000 Subject: [PATCH 5/9] sublistView --- packages/flame/lib/src/components/mixins/snapshot.dart | 6 +++--- packages/flame/lib/src/extensions/canvas.dart | 2 +- packages/flame/lib/src/rendering/rotate3d_decorator.dart | 2 +- packages/flame/lib/src/rendering/shadow3d_decorator.dart | 2 +- packages/flame/lib/src/rendering/transform2d_decorator.dart | 3 ++- packages/flame/lib/src/sprite_batch.dart | 2 +- packages/flame_forge2d/lib/body_component.dart | 2 +- 7 files changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/flame/lib/src/components/mixins/snapshot.dart b/packages/flame/lib/src/components/mixins/snapshot.dart index d585685d192..bd20e646122 100644 --- a/packages/flame/lib/src/components/mixins/snapshot.dart +++ b/packages/flame/lib/src/components/mixins/snapshot.dart @@ -49,7 +49,7 @@ mixin Snapshot on PositionComponent { } else { final recorder = PictureRecorder(); final canvas = Canvas(recorder); - canvas.transform(Float64List.fromList(transform.storage)); + canvas.transform(Float64List.sublistView(transform.storage)); canvas.drawPicture(_picture!); final picture = recorder.endRecording(); return picture.toImageSync(width, height); @@ -65,7 +65,7 @@ mixin Snapshot on PositionComponent { final canvas = Canvas(recorder); final matrix = transformMatrix.clone(); matrix.invert(); - canvas.transform(Float64List.fromList(matrix.storage)); + canvas.transform(Float64List.sublistView(matrix.storage)); super.renderTree(canvas); _picture = recorder.endRecording(); return _picture!; @@ -84,7 +84,7 @@ mixin Snapshot on PositionComponent { takeSnapshot(); } canvas.save(); - canvas.transform(Float64List.fromList(transformMatrix.storage)); + canvas.transform(Float64List.sublistView(transformMatrix.storage)); canvas.drawPicture(_picture!); canvas.restore(); } else { diff --git a/packages/flame/lib/src/extensions/canvas.dart b/packages/flame/lib/src/extensions/canvas.dart index d54478a4a66..8fc847fac22 100644 --- a/packages/flame/lib/src/extensions/canvas.dart +++ b/packages/flame/lib/src/extensions/canvas.dart @@ -60,6 +60,6 @@ extension CanvasExtension on Canvas { /// Use the [Transform2D] object to [transform] the canvas. void transform2D(Transform2D transform2D) { - transform(Float64List.fromList(transform2D.transformMatrix.storage)); + transform(Float64List.sublistView(transform2D.transformMatrix.storage)); } } diff --git a/packages/flame/lib/src/rendering/rotate3d_decorator.dart b/packages/flame/lib/src/rendering/rotate3d_decorator.dart index 647fdb1d579..0b6c6195a16 100644 --- a/packages/flame/lib/src/rendering/rotate3d_decorator.dart +++ b/packages/flame/lib/src/rendering/rotate3d_decorator.dart @@ -62,7 +62,7 @@ class Rotate3DDecorator extends Decorator { ..rotateY(angleY) ..rotateZ(angleZ) ..translate(-center.x, -center.y); - canvas.transform(Float64List.fromList(matrix.storage)); + canvas.transform(Float64List.sublistView(matrix.storage)); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index 600c57cf693..cfe08f03b1b 100644 --- a/packages/flame/lib/src/rendering/shadow3d_decorator.dart +++ b/packages/flame/lib/src/rendering/shadow3d_decorator.dart @@ -157,7 +157,7 @@ class Shadow3DDecorator extends Decorator { canvas.saveLayer(null, _paint!); canvas.translate(base.x + _shift, base.y); - canvas.transform(Float64List.fromList(_transformMatrix!.storage)); + canvas.transform(Float64List.sublistView(_transformMatrix!.storage)); draw(canvas); canvas.restore(); draw(canvas); diff --git a/packages/flame/lib/src/rendering/transform2d_decorator.dart b/packages/flame/lib/src/rendering/transform2d_decorator.dart index 5585285305f..d4d979812cf 100644 --- a/packages/flame/lib/src/rendering/transform2d_decorator.dart +++ b/packages/flame/lib/src/rendering/transform2d_decorator.dart @@ -18,7 +18,8 @@ class Transform2DDecorator extends Decorator { @override void apply(void Function(Canvas) draw, Canvas canvas) { canvas.save(); - canvas.transform(Float64List.fromList(transform2d.transformMatrix.storage)); + canvas.transform( + Float64List.sublistView(transform2d.transformMatrix.storage)); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/sprite_batch.dart b/packages/flame/lib/src/sprite_batch.dart index f47df475f84..21c8ba23f24 100644 --- a/packages/flame/lib/src/sprite_batch.dart +++ b/packages/flame/lib/src/sprite_batch.dart @@ -433,7 +433,7 @@ class SpriteBatch { canvas ..save() - ..transform(Float64List.fromList(batchItem.matrix.storage)) + ..transform(Float64List.sublistView(batchItem.matrix.storage)) ..drawRect(batchItem.destination, batchItem.paint) ..drawImageRect( atlas, diff --git a/packages/flame_forge2d/lib/body_component.dart b/packages/flame_forge2d/lib/body_component.dart index 404042f0dd2..85ed8f17e98 100644 --- a/packages/flame_forge2d/lib/body_component.dart +++ b/packages/flame_forge2d/lib/body_component.dart @@ -102,7 +102,7 @@ class BodyComponent extends Component _lastAngle = angle; } canvas.save(); - canvas.transform(Float64List.fromList(matrix.storage)); + canvas.transform(Float64List.sublistView(matrix.storage)); super.renderTree(canvas); canvas.restore(); } From 65fb07efc5843fe5faeee953f2a65e4fcc24f61a Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 22:24:32 +0000 Subject: [PATCH 6/9] extension --- packages/flame/lib/src/components/mixins/snapshot.dart | 9 ++++----- packages/flame/lib/src/extensions/canvas.dart | 4 ++-- packages/flame/lib/src/extensions/matrix4.dart | 4 ++++ packages/flame/lib/src/rendering/rotate3d_decorator.dart | 5 ++--- packages/flame/lib/src/rendering/shadow3d_decorator.dart | 5 ++--- .../flame/lib/src/rendering/transform2d_decorator.dart | 5 ++--- packages/flame/lib/src/sprite_batch.dart | 5 ++--- packages/flame_forge2d/lib/body_component.dart | 2 +- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/packages/flame/lib/src/components/mixins/snapshot.dart b/packages/flame/lib/src/components/mixins/snapshot.dart index bd20e646122..2f9abbe4363 100644 --- a/packages/flame/lib/src/components/mixins/snapshot.dart +++ b/packages/flame/lib/src/components/mixins/snapshot.dart @@ -1,8 +1,7 @@ -import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/components.dart'; -import 'package:vector_math/vector_math.dart'; +import 'package:flame/extensions_matrix4.dart'; /// A mixin that enables caching a component and all its children. If /// [renderSnapshot] is set to `true`, the component and its children will be @@ -49,7 +48,7 @@ mixin Snapshot on PositionComponent { } else { final recorder = PictureRecorder(); final canvas = Canvas(recorder); - canvas.transform(Float64List.sublistView(transform.storage)); + canvas.transform(transform.storage64); canvas.drawPicture(_picture!); final picture = recorder.endRecording(); return picture.toImageSync(width, height); @@ -65,7 +64,7 @@ mixin Snapshot on PositionComponent { final canvas = Canvas(recorder); final matrix = transformMatrix.clone(); matrix.invert(); - canvas.transform(Float64List.sublistView(matrix.storage)); + canvas.transform(matrix.storage64); super.renderTree(canvas); _picture = recorder.endRecording(); return _picture!; @@ -84,7 +83,7 @@ mixin Snapshot on PositionComponent { takeSnapshot(); } canvas.save(); - canvas.transform(Float64List.sublistView(transformMatrix.storage)); + canvas.transform(transformMatrix.storage64); canvas.drawPicture(_picture!); canvas.restore(); } else { diff --git a/packages/flame/lib/src/extensions/canvas.dart b/packages/flame/lib/src/extensions/canvas.dart index 8fc847fac22..fddae21361c 100644 --- a/packages/flame/lib/src/extensions/canvas.dart +++ b/packages/flame/lib/src/extensions/canvas.dart @@ -1,6 +1,6 @@ -import 'dart:typed_data'; import 'dart:ui'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/palette.dart'; import 'package:flame/src/extensions/vector2.dart'; import 'package:flame/src/game/transform2d.dart'; @@ -60,6 +60,6 @@ extension CanvasExtension on Canvas { /// Use the [Transform2D] object to [transform] the canvas. void transform2D(Transform2D transform2D) { - transform(Float64List.sublistView(transform2D.transformMatrix.storage)); + transform(transform2D.transformMatrix.storage64); } } diff --git a/packages/flame/lib/src/extensions/matrix4.dart b/packages/flame/lib/src/extensions/matrix4.dart index f875cce77ef..b4fd95ce007 100644 --- a/packages/flame/lib/src/extensions/matrix4.dart +++ b/packages/flame/lib/src/extensions/matrix4.dart @@ -1,3 +1,5 @@ +import 'dart:typed_data'; + import 'package:vector_math/vector_math.dart'; export 'package:vector_math/vector_math.dart' hide Colors; @@ -78,6 +80,8 @@ extension Matrix4Extension on Matrix4 { return transform2(out); } + Float64List get storage64 => Float64List.sublistView(storage); + /// Create a scaled matrix. /// /// Scale by a [Vector3], [Vector4], or x,y,z diff --git a/packages/flame/lib/src/rendering/rotate3d_decorator.dart b/packages/flame/lib/src/rendering/rotate3d_decorator.dart index 0b6c6195a16..a5c81f0de9f 100644 --- a/packages/flame/lib/src/rendering/rotate3d_decorator.dart +++ b/packages/flame/lib/src/rendering/rotate3d_decorator.dart @@ -1,9 +1,8 @@ -import 'dart:typed_data'; import 'dart:ui'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/geometry.dart'; import 'package:flame/src/rendering/decorator.dart'; -import 'package:vector_math/vector_math.dart'; /// [Rotate3DDecorator] treats the underlying component as if it was a flat /// sheet of paper, and applies a 3D rotation to it. @@ -62,7 +61,7 @@ class Rotate3DDecorator extends Decorator { ..rotateY(angleY) ..rotateZ(angleZ) ..translate(-center.x, -center.y); - canvas.transform(Float64List.sublistView(matrix.storage)); + canvas.transform(matrix.storage64); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/rendering/shadow3d_decorator.dart b/packages/flame/lib/src/rendering/shadow3d_decorator.dart index cfe08f03b1b..7d01ede9cb5 100644 --- a/packages/flame/lib/src/rendering/shadow3d_decorator.dart +++ b/packages/flame/lib/src/rendering/shadow3d_decorator.dart @@ -1,9 +1,8 @@ -import 'dart:typed_data'; import 'dart:ui'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/src/palette.dart'; import 'package:flame/src/rendering/decorator.dart'; -import 'package:vector_math/vector_math.dart' show Matrix4, Vector2; /// [Shadow3DDecorator] casts a realistic-looking shadow from the component /// onto the ground. @@ -157,7 +156,7 @@ class Shadow3DDecorator extends Decorator { canvas.saveLayer(null, _paint!); canvas.translate(base.x + _shift, base.y); - canvas.transform(Float64List.sublistView(_transformMatrix!.storage)); + canvas.transform(_transformMatrix!.storage64); draw(canvas); canvas.restore(); draw(canvas); diff --git a/packages/flame/lib/src/rendering/transform2d_decorator.dart b/packages/flame/lib/src/rendering/transform2d_decorator.dart index d4d979812cf..9c03cd1853b 100644 --- a/packages/flame/lib/src/rendering/transform2d_decorator.dart +++ b/packages/flame/lib/src/rendering/transform2d_decorator.dart @@ -1,6 +1,6 @@ -import 'dart:typed_data'; import 'dart:ui'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/src/components/position_component.dart'; import 'package:flame/src/game/transform2d.dart'; import 'package:flame/src/rendering/decorator.dart'; @@ -18,8 +18,7 @@ class Transform2DDecorator extends Decorator { @override void apply(void Function(Canvas) draw, Canvas canvas) { canvas.save(); - canvas.transform( - Float64List.sublistView(transform2d.transformMatrix.storage)); + canvas.transform(transform2d.transformMatrix.storage64); draw(canvas); canvas.restore(); } diff --git a/packages/flame/lib/src/sprite_batch.dart b/packages/flame/lib/src/sprite_batch.dart index 21c8ba23f24..23eacc7a51c 100644 --- a/packages/flame/lib/src/sprite_batch.dart +++ b/packages/flame/lib/src/sprite_batch.dart @@ -1,14 +1,13 @@ import 'dart:collection'; import 'dart:math' show pi; -import 'dart:typed_data'; import 'dart:ui'; import 'package:flame/cache.dart'; import 'package:flame/extensions.dart'; +import 'package:flame/extensions_matrix4.dart'; import 'package:flame/flame.dart'; import 'package:flame/game.dart'; import 'package:meta/meta.dart'; -import 'package:vector_math/vector_math.dart'; extension SpriteBatchExtension on Game { /// Utility method to load and cache the image for a [SpriteBatch] based on @@ -433,7 +432,7 @@ class SpriteBatch { canvas ..save() - ..transform(Float64List.sublistView(batchItem.matrix.storage)) + ..transform(batchItem.matrix.storage64) ..drawRect(batchItem.destination, batchItem.paint) ..drawImageRect( atlas, diff --git a/packages/flame_forge2d/lib/body_component.dart b/packages/flame_forge2d/lib/body_component.dart index 85ed8f17e98..6796ac13e04 100644 --- a/packages/flame_forge2d/lib/body_component.dart +++ b/packages/flame_forge2d/lib/body_component.dart @@ -102,7 +102,7 @@ class BodyComponent extends Component _lastAngle = angle; } canvas.save(); - canvas.transform(Float64List.sublistView(matrix.storage)); + canvas.transform(matrix.storage64); super.renderTree(canvas); canvas.restore(); } From 122533a4ae6242813060c2e38f9f9327b0d64667 Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Sat, 14 Dec 2024 23:10:06 +0000 Subject: [PATCH 7/9] problems --- .../flame/lib/src/extensions/matrix4.dart | 2 +- .../flame/test/game/transform2d_test.dart | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/flame/lib/src/extensions/matrix4.dart b/packages/flame/lib/src/extensions/matrix4.dart index b4fd95ce007..6f4a78167d2 100644 --- a/packages/flame/lib/src/extensions/matrix4.dart +++ b/packages/flame/lib/src/extensions/matrix4.dart @@ -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. /// diff --git a/packages/flame/test/game/transform2d_test.dart b/packages/flame/test/game/transform2d_test.dart index 4eba2acc092..a7415ac610a 100644 --- a/packages/flame/test/game/transform2d_test.dart +++ b/packages/flame/test/game/transform2d_test.dart @@ -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(); @@ -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', () { @@ -173,7 +173,7 @@ 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 @@ -181,8 +181,8 @@ void main() { 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)); } }); @@ -194,8 +194,8 @@ 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); @@ -203,3 +203,5 @@ void main() { }); }); } + +const _epsilon = 10e-6; \ No newline at end of file From 9a083699758fee0271e0791792c6ff39e770cc2c Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Mon, 16 Dec 2024 12:39:27 +0000 Subject: [PATCH 8/9] format --- packages/flame/test/game/transform2d_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/flame/test/game/transform2d_test.dart b/packages/flame/test/game/transform2d_test.dart index a7415ac610a..2f64e8dd99f 100644 --- a/packages/flame/test/game/transform2d_test.dart +++ b/packages/flame/test/game/transform2d_test.dart @@ -204,4 +204,4 @@ void main() { }); } -const _epsilon = 10e-6; \ No newline at end of file +const _epsilon = 10e-6; From 451a8c65d73fef0847741de6c83161c9b32ddbdd Mon Sep 17 00:00:00 2001 From: Renan araujo Date: Mon, 16 Dec 2024 12:50:32 +0000 Subject: [PATCH 9/9] more imprecision --- .../camera/behaviors/follow_behavior_test.dart | 6 +++--- packages/flame/test/camera/viewfinder_test.dart | 6 +++--- .../fixed_aspect_ratio_viewport_test.dart | 4 ++-- .../flame/test/effects/anchor_by_effect_test.dart | 8 ++++---- packages/flame/test/effects/scale_effect_test.dart | 12 ++++++------ .../flame/test/effects/sequence_effect_test.dart | 14 +++++++------- packages/flame/test/effects/size_effect_test.dart | 2 +- .../geometry/shapes/rounded_rectangle_test.dart | 4 ++-- 8 files changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/flame/test/camera/behaviors/follow_behavior_test.dart b/packages/flame/test/camera/behaviors/follow_behavior_test.dart index 708e37cfcad..8e9c83f4f4a 100644 --- a/packages/flame/test/camera/behaviors/follow_behavior_test.dart +++ b/packages/flame/test/camera/behaviors/follow_behavior_test.dart @@ -74,7 +74,7 @@ void main() { const dt = 0.11; for (var i = 0; i < 20; i++) { - expect(followTarget, closeToVector(Vector2(3, 1 + i * dt), 1e-14)); + expect(followTarget, closeToVector(Vector2(3, 1 + i * dt), 1e-6)); game.update(dt); } }); @@ -91,7 +91,7 @@ void main() { game.update(0.01); expect( pursuer.position, - closeToVector(target.position, 1e-12), + closeToVector(target.position, 1e-4), ); } }); @@ -111,7 +111,7 @@ void main() { final distance = speed * i * dt; expect( pursuer.position, - closeToVector(Vector2(distance * 0.6, distance * 0.8), 1e-12), + closeToVector(Vector2(distance * 0.6, distance * 0.8), 1e-3), ); game.update(dt); } diff --git a/packages/flame/test/camera/viewfinder_test.dart b/packages/flame/test/camera/viewfinder_test.dart index 44a8301ebf6..3e15627de24 100644 --- a/packages/flame/test/camera/viewfinder_test.dart +++ b/packages/flame/test/camera/viewfinder_test.dart @@ -126,11 +126,11 @@ void main() { for (var t = 0.0; t < 1.0; t += 0.1) { expect( camera.viewfinder.position, - closeToVector(Vector2(5 * t, 13 * t), 1e-14), + closeToVector(Vector2(5 * t, 13 * t), 1e-6), ); expect( camera.viewport.position, - closeToVector(Vector2(40 * t, -77 * t), 1e-12), + closeToVector(Vector2(40 * t, -77 * t), 1e-5), ); game.update(0.1); } @@ -174,7 +174,7 @@ void main() { await game.ready(); for (var t = 0.0; t < 1.0; t += 0.1) { - expect(camera.viewfinder.zoom, closeTo(1 + t, 1e-14)); + expect(camera.viewfinder.zoom, closeTo(1 + t, 1e-6)); game.update(0.1); } }, diff --git a/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart b/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart index 18c14461b88..184e21e00cd 100644 --- a/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart +++ b/packages/flame/test/camera/viewports/fixed_aspect_ratio_viewport_test.dart @@ -50,8 +50,8 @@ void main() { final width = random.nextDouble() * 1000.0 + 10.0; final height = random.nextDouble() * 1000.0 + 10.0; game.onGameResize(Vector2(width, height)); - expect(viewport.size.x == width || viewport.size.y == height, true); - expect(viewport.size.x / viewport.size.y, closeTo(2.0, 1e-10)); + + expect(viewport.size.x / viewport.size.y, closeTo(2.0, 1e-6)); if (viewport.size.x == width) { expect(viewport.position.x, 0); expect( diff --git a/packages/flame/test/effects/anchor_by_effect_test.dart b/packages/flame/test/effects/anchor_by_effect_test.dart index eb6b0d3953a..81f1eaf2d49 100644 --- a/packages/flame/test/effects/anchor_by_effect_test.dart +++ b/packages/flame/test/effects/anchor_by_effect_test.dart @@ -18,8 +18,8 @@ void main() { AnchorEffect.by(Vector2(0.3, 0.5), EffectController(duration: 1)), ); for (var t = 0.0; t <= 1.0; t += 0.1) { - expect(component.anchor.x, closeTo(0.5 + 0.3 * t, 1e-15)); - expect(component.anchor.y, closeTo(0.5 + 0.5 * t, 1e-15)); + expect(component.anchor.x, closeTo(0.5 + 0.3 * t, 13-6)); + expect(component.anchor.y, closeTo(0.5 + 0.5 * t, 13-6)); game.update(0.1); } }); @@ -37,8 +37,8 @@ void main() { await game.ready(); for (var t = 0.0; t <= 1.0; t += 0.1) { - expect(component.anchor.x, closeTo(0.5 - 0.2 * t, 1e-15)); - expect(component.anchor.y, closeTo(0.0 + 0.6 * t, 1e-15)); + expect(component.anchor.x, closeTo(0.5 - 0.2 * t, 13-6)); + expect(component.anchor.y, closeTo(0.0 + 0.6 * t, 13-6)); game.update(0.1); } }); diff --git a/packages/flame/test/effects/scale_effect_test.dart b/packages/flame/test/effects/scale_effect_test.dart index fd5d8b8e68d..c65497a7aa3 100644 --- a/packages/flame/test/effects/scale_effect_test.dart +++ b/packages/flame/test/effects/scale_effect_test.dart @@ -109,16 +109,16 @@ void main() { ); game.update(1); - expect(component.scale.x, closeTo(0.7, 1e-15)); // (1 + 0.4) * 0.5 - expect(component.scale.y, closeTo(-0.7, 1e-15)); + expect(component.scale.x, closeTo(0.7, 1e-6)); // (1 + 0.4) * 0.5 + expect(component.scale.y, closeTo(-0.7, 1e-6)); game.update(1); - expect(component.scale.x, closeTo(1.8, 1e-15)); // (1 + 2*0.4) * 1 - expect(component.scale.y, closeTo(-1.8, 1e-15)); + expect(component.scale.x, closeTo(1.8, 1e-6)); // (1 + 2*0.4) * 1 + expect(component.scale.y, closeTo(-1.8, 1e-6)); for (var i = 0; i < 8; i++) { game.update(1); } - expect(component.scale.x, closeTo(5, 1e-15)); - expect(component.scale.y, closeTo(-5, 1e-15)); + expect(component.scale.x, closeTo(5, 1e-6)); + expect(component.scale.y, closeTo(-5, 1e-6)); game.update(0); expect(component.children.length, 0); }); diff --git a/packages/flame/test/effects/sequence_effect_test.dart b/packages/flame/test/effects/sequence_effect_test.dart index dc6240b74f4..41c1efc8a9b 100644 --- a/packages/flame/test/effects/sequence_effect_test.dart +++ b/packages/flame/test/effects/sequence_effect_test.dart @@ -60,7 +60,7 @@ void main() { ); expect( effect.controller.duration, - closeTo(randomEffect.controller.duration! * 2000, 1e-15), + closeTo(randomEffect.controller.duration! * 2000, 1e-6), ); expect(effect.controller.isRandom, true); }); @@ -105,7 +105,7 @@ void main() { Vector2(30, 40), ]; for (final p in expectedPositions) { - expect(component.position, closeToVector(p, 1e-12)); + expect(component.position, closeToVector(p, 1e-5)); game.update(0.1); } }); @@ -171,7 +171,7 @@ void main() { for (var i = 10.0; i > 0; i--) Vector2(i, 0), ]; for (final p in expectedPath) { - expect(component.position, closeToVector(p, 1e-14)); + expect(component.position, closeToVector(p, 1e-6)); game.update(0.1); } game.update(0.001); @@ -205,11 +205,11 @@ void main() { ...forwardPath.reversed, ]; for (final p in expectedPath) { - expect(component.position, closeToVector(p, 1e-14)); + expect(component.position, closeToVector(p, 1e-5)); game.update(0.1); } game.update(0.001); - expect(component.position, closeToVector(Vector2.zero())); + expect(component.position, closeToVector(Vector2.zero(), 1e-5)); expect(effect.controller.completed, true); }); @@ -233,7 +233,7 @@ void main() { testWithFlameGame('sequence in sequence', (game) async { EffectController duration(double t) => EffectController(duration: t); const dt = 0.01; - const x0 = 0.0; + const x0 = 0.0;S const y0 = 0.0; const x1 = 10.0; const y1 = 10.0; @@ -314,7 +314,7 @@ void main() { ...forwardPath.reversed, ]; for (final p in expectedPath) { - expect(component.position, closeToVector(p, 1e-12)); + expect(component.position, closeToVector(p, 1e-3)); game.update(dt); } game.update(1e-5); diff --git a/packages/flame/test/effects/size_effect_test.dart b/packages/flame/test/effects/size_effect_test.dart index 695ad2af863..868e49a869a 100644 --- a/packages/flame/test/effects/size_effect_test.dart +++ b/packages/flame/test/effects/size_effect_test.dart @@ -144,7 +144,7 @@ void main() { game.update(1000 - totalTime); // Typically, `component.size` could accumulate numeric discrepancy on the // order of 1e-11 .. 1e-12 by now. - expect(component.size, closeToVector(Vector2(0, 0), 1e-10)); + expect(component.size, closeToVector(Vector2(0, 0), 1e-6)); }); }); } diff --git a/packages/flame/test/experimental/geometry/shapes/rounded_rectangle_test.dart b/packages/flame/test/experimental/geometry/shapes/rounded_rectangle_test.dart index a9ea36d10b2..fbf4c8dd557 100644 --- a/packages/flame/test/experimental/geometry/shapes/rounded_rectangle_test.dart +++ b/packages/flame/test/experimental/geometry/shapes/rounded_rectangle_test.dart @@ -178,7 +178,7 @@ void main() { final expected = rect.support(direction) + circle.support(direction); expect( rrect.support(direction), - closeToVector(expected, 1e-14), + closeToVector(expected, 1e-5), ); } }); @@ -238,7 +238,7 @@ void main() { ); expect( rrect.nearestPoint(Vector2(0, -10)), - Vector2(5.52786404500042, 1.0557280900008408), + Vector2(5.52786404500042, 1.0557279586791992), ); expect(rrect.nearestPoint(Vector2(10, -10)), Vector2(10, 0)); expect(rrect.nearestPoint(Vector2(30, -10)), Vector2(30, 0));