`toAbsoluteRect` and `canSee` are wrong for a child of an ancestor that is rotated by a non-right angle
I maintainer di solito rispondono entro 1 giorno
Una pull request collegata è già stata integrata.
- #4109 di @ufrshubham — integrata
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Inizia da _toRectImpl in packages/flame/lib/src/components/position_component.dart, dove la scorciatoia angle == 0 proietta solo l'angolo in alto a sinistra e quello in basso a destra. Fai in modo che toAbsoluteRect() consideri il bounding box di tutti e quattro gli angoli proiettati, mentre toRect() mantiene la scorciatoia. Esegui i casi con antenati ruotati descritti nell'issue, inclusa la camera 2x2 di canSee() in (-7, 7), e verifica che i test esistenti a 90° e 180° continuino a passare.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
What happened?
PositionComponent.toAbsoluteRect() returns a rectangle that is too small when an ancestor of the
component is rotated by an angle that is not a multiple of a quarter turn (like 45°), and the
component has no rotation of its own.
CameraComponent.canSee() is built on toAbsoluteRect(), so it can return false for a component
that is partly visible.
This was found in a review comment on #4107:
https://github.com/flame-engine/flame/pull/4107#discussion_r4237700858
The cause is the angle == 0 shortcut in _toRectImpl
(link).
When the component's own angle is 0, it only projects the top left and the bottom right corner,
and builds the rectangle from those two. That is only correct when nothing above the component is
rotated. With a rotated ancestor, the other two corners can stick out of that rectangle.
Rotations by 90° and 180° still give the right result, because the two corners are then still the
extreme ones. That is why the existing tests don't catch this.
https://github.com/user-attachments/assets/84ad9a7c-2a12-4416-9d3a-dcc8b73f22e0
What do you expect?
The smallest rectangle that contains the whole component in world coordinates, so the one made from
all four corners. canSee() should then be true whenever any part of the component is inside the
view.
How can we reproduce this?
A 100x10 child with no rotation of its own, inside a parent that is rotated by 45°:
final child = PositionComponent(size: Vector2(100, 10));
world.add(PositionComponent(angle: pi / 4, children: [child]));
// The corners of the child in world coordinates are:
// top left (0, 0)
// top right (70.71, 70.71)
// bottom left (-7.07, 7.07)
// bottom right (63.64, 77.78)
final rect = child.toAbsoluteRect();
// Expected: left -7.07, top 0, right 70.71, bottom 77.78
// Actual: left 0, top 0, right 63.64, bottom 77.78
For canSee(), use a camera with a 2x2 viewport that looks at (-7, 7). That view only contains the
bottom left corner of the child, at (-7.07, 7.07):
final camera = CameraComponent(
world: world,
viewport: FixedSizeViewport(2, 2),
)..viewfinder.position = Vector2(-7, 7);
camera.canSee(child); // Expected: true, actual: false
What steps should take to fix this?
Make toAbsoluteRect() always use all four corners. toRect() can keep the shortcut, because it is
in the coordinate space of the parent, where only the component's own angle matters.
Add tests for both cases above, and for a rotated ancestor in toAbsoluteRect() and canSee().
- Lingua principale
- Dart
- Stelle
- 10.8k
- Fork
- 1.1k
- Merge medio
- 1g 17h
- PR unite (30g)
- 51
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di flame-engine/flame
-
enhancement v2
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
flame-engine/flame#4116 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
flame-engine/flame#4063 ·
I maintainer di solito rispondono entro 1 giorno
-
TextComponent shadows are not affected by OpacityEffectForse già presa @spydon l’ha presa 37 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
flame-engine/flame#4013 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
flame-engine/flame#4012 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
flame-engine/flame#3974 · 6 commenti · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di flame-engine/flame
Issue simili
-
Document supported hardwareApertaDocumentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Kazakh (kk_KZ) and Georgian (ka_GE) system locales get English instead of the shipped translationsApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
area: docs eco: dart good first issue help wanted lane: free-agent roadmap size: XS type: docs
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
arminazimi/evergreen#430 ·
I maintainer di solito rispondono entro 1 giorno
-
area: rust-core bug priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug direct-code
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
aaronified/fluenough#526 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno