toRect method

Rect toRect(
  1. Vector2 size, [
  2. Vector2 projector(
    1. Vector2 point
    )?
])

Implementation

Rect toRect(Vector2 size, [Vector2 Function(Vector2 point)? projector]) {
  final convert = projector ?? localToGlobal;

  final topLeft = convert(Vector2.zero());
  final bottomRight = convert(size);

  if (_angle == 0.0 && _skew.isZero()) {
    return Rect.fromPoints(topLeft.toOffset(), bottomRight.toOffset());
  }

  final topRight = convert(Vector2(size.x, 0));
  final bottomLeft = convert(Vector2(0, size.y));
  final xs = [topLeft.x, topRight.x, bottomLeft.x, bottomRight.x]..sort();
  final ys = [topLeft.y, topRight.y, bottomLeft.y, bottomRight.y]..sort();

  return Rect.fromLTRB(xs.first, ys.first, xs.last, ys.last);
}