Repository navigation
fix: Use all four corners in PositionComponent.toAbsoluteRect - #4109
Merged
Merged
Conversation
A child without a rotation of its own was measured with only two corners. That is too small when an ancestor is rotated by an angle that is not a multiple of a quarter turn, and it made CameraComponent.canSee return false for components that are partly visible.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The focused implementation correctly resolves #4108 and includes coverage for the affected behavior.
0 open findings
What changed in this PR
Fixes world-space bounding rectangles for components beneath rotated ancestors, resolving incorrect camera visibility checks.
Changes:
- Computes absolute bounds from all four corners.
- Preserves the optimized parent-space calculation.
- Adds regression tests for bounding and camera visibility.
| File | Description |
|---|---|
packages/flame/lib/src/components/position_component.dart |
Corrects absolute bounding-box calculation. |
packages/flame/test/components/position_component_test.dart |
Tests rotated-ancestor bounds and parent-space behavior. |
packages/flame/test/camera/camera_component_test.dart |
Tests visibility beneath a rotated ancestor. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
PositionComponent.toAbsoluteRect
5 of 6 tasks
luanpotter
approved these changes
Oct 11, 2026
Replaces the nested min and max calls in PositionComponent._boundsOfCorners with the existing fromVertices extension, as suggested in the review. It is about 37 ns slower per call in an AOT build (48 ns against 11 ns), which is small next to projecting the four corners.
erickzanardo
approved these changes
Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PositionComponent.toAbsoluteRect()has a shortcut for components whose ownangleis 0: it onlyprojects the top left and the bottom right corner. That is not enough when an ancestor is rotated by
an angle that is not a multiple of a quarter turn (like 45°), because the other two corners can then
stick out of the rectangle. The result was a rectangle that is too small, and
CameraComponent.canSee(), which uses it, could returnfalsefor a component that is partlyvisible.
toAbsoluteRect()now always uses all four corners.toRect()keeps the shortcut, because it is inthe coordinate space of the parent, where only the rotation of the component itself matters.
Tests are added for
toAbsoluteRect()with a rotated ancestor, forcanSee()with a rotatedancestor, and a test that
toRect()ignores the rotation of the parent.This was found in a review comment on #4107:
#4107 (comment)
Before the fix:
to_absolute_rect_bug.mp4
After the fix:
to_absolute_rect_fixed.mp4
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?
Related Issues
Closes #4108