overlayRect function

Rect overlayRect({
  1. required Offset origin,
  2. required Size size,
  3. required Alignment alignment,
  4. required bool rotate,
  5. double mapRotationRad = 0.0,
  6. EdgeInsets margin = EdgeInsets.zero,
  7. Offset pixelOffset = Offset.zero,
})

Implementation

Rect overlayRect({
  required Offset origin,
  required Size size,
  required Alignment alignment,
  required bool rotate,
  double mapRotationRad = 0.0,
  EdgeInsets margin = EdgeInsets.zero,
  Offset pixelOffset = Offset.zero,
}) {
  final f = _computeFrame(
    origin: origin,
    size: size,
    alignment: alignment,
    mapRotationRad: mapRotationRad,
    rotate: rotate,
    margin: margin,
  );

  if (!f.counter) {
    return Rect.fromLTWH(f.tl.dx, f.tl.dy, f.size.width, f.size.height)
        .shift(pixelOffset);
  }

  final theta = -mapRotationRad;
  final c = math.cos(theta);
  final s = math.sin(theta);

  final cx0 = f.tl.dx + 0.5 * f.size.width;
  final cy0 = f.tl.dy + 0.5 * f.size.height;

  final dx = cx0 - f.pivot.dx;
  final dy = cy0 - f.pivot.dy;
  final cx = f.pivot.dx + dx * c - dy * s;
  final cy = f.pivot.dy + dx * s + dy * c;

  final ac = c.abs(), as_ = s.abs();
  final rx = 0.5 * (f.size.width * ac + f.size.height * as_);
  final ry = 0.5 * (f.size.width * as_ + f.size.height * ac);

  return Rect.fromLTRB(cx - rx, cy - ry, cx + rx, cy + ry).shift(pixelOffset);
}