inscribe method

Rect inscribe(
  1. Size size,
  2. Rect rect
)

Returns a rect of the given size, aligned within given rect as specified by this alignment.

For example, a 100×100 size inscribed on a 200×200 rect using Alignment.topLeft would be the 100×100 rect at the top left of the 200×200 rect.

Implementation

Rect inscribe(Size size, Rect rect) {
  final double halfWidthDelta = (rect.width - size.width) / 2.0;
  final double halfHeightDelta = (rect.height - size.height) / 2.0;
  return Rect.fromLTWH(
    rect.left + halfWidthDelta + x * halfWidthDelta,
    rect.top + halfHeightDelta + y * halfHeightDelta,
    size.width,
    size.height,
  );
}