insetSourceRect static method

Rect insetSourceRect(
  1. Rect source,
  2. Rect image, {
  3. double inset = sourceInset,
})

sourceRect without needing an image, so it can be unit tested.

Implementation

static Rect insetSourceRect(
  Rect source,
  Rect image, {
  double inset = sourceInset,
}) {
  if (inset <= 0 || source == image) {
    return source;
  }
  // Never trim more than a quarter of the cell, so one pixel tiles survive.
  final dx = math.min(inset, source.width / 4);
  final dy = math.min(inset, source.height / 4);
  return Rect.fromLTRB(
    source.left + dx,
    source.top + dy,
    source.right - dx,
    source.bottom - dy,
  );
}