Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`toAbsoluteRect` and `canSee` are wrong for a child of an ancestor that is rotated by a non-right angle

Chiusa Adatta ai principianti
#4,108 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

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
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
dart, flutter, game-dev
Ambito
game-dev

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

bug
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

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di flame-engine/flame

Tutte le issue di flame-engine/flame

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.