intersection method

SdlxFRect? intersection(
  1. SdlxFRect other
)

Implementation

SdlxFRect? intersection(SdlxFRect other) {
  final x0 = math.max(x, other.x);
  final x1 = math.min(x + w, other.x + other.w);
  if (x0 <= x1) {
    final y0 = math.max(y, other.y);
    final y1 = math.min(y + h, other.y + other.h);
    if (y0 <= y1) {
      return SdlxFRect(x: x0, y: y0, w: x1 - x0, h: y1 - y0);
    }
  }
  return null;
}