minus method

List<Rect> minus(
  1. Rect other, {
  2. double epsilon = 0.0,
})

Implementation

List<Rect> minus(Rect other, {double epsilon = 0.0}) {
  final i = intersection(other);
  if (i == null) return [this];

  final out = <Rect>[];

  Rect? rectOrNull(double l, double t, double r, double b) =>
      ((r - l) <= epsilon || (b - t) <= epsilon)
          ? null
          : Rect.fromLTRB(l, t, r, b);

  final top = rectOrNull(left, topLeft.dy, right, i.top);
  final bottom = rectOrNull(left, i.bottom, right, bottomRight.dy);

  final leftBand = rectOrNull(left, i.top, i.left, i.bottom);
  final rightBand = rectOrNull(i.right, i.top, right, i.bottom);

  if (top != null) out.add(top);
  if (bottom != null) out.add(bottom);
  if (leftBand != null) out.add(leftBand);
  if (rightBand != null) out.add(rightBand);

  return out;
}