worldBounds method

Aabb2 worldBounds(
  1. Shape shape,
  2. Matrix3 transform
)

This node's world-space AABB for shape, given its already-computed transform (see absoluteTransform).

The returned AABB is owned by this node and should not be retained.

TODO: Reconsider this name - it no longer computes a transform itself, just applies one the caller already has.

Implementation

Aabb2 worldBounds(Shape shape, Matrix3 transform) {
  final bounds = _lastWorldBounds;
  final width = shape.width;
  final height = shape.height;

  // Compute the shape's center, adjusted for the anchor and absolute transform.
  _CENTER_SCRATCH
    ..setValues(width * (0.5 - anchor.x), height * (0.5 - anchor.y))
    ..transform(transform);

  // Compute the shape's half-extents, adjusted for absolute rotation (*not* transform).
  _HALF_EXTENTS_SCRATCH
    ..setValues(width / 2, height / 2)
    ..absoluteRotate2(transform);

  bounds.setCenterAndHalfExtents(_CENTER_SCRATCH, _HALF_EXTENTS_SCRATCH);
  return bounds;
}