intersection method

GRect intersection(
  1. GRect toIntersect
)

If the GRect object specified in the toIntersect parameter intersects with this GRect object, returns the area of intersection as a GRect object.

Implementation

GRect intersection(GRect toIntersect) {
  late GRect result;
  var x0 = x < toIntersect.x ? toIntersect.x : 0.0;
  var x1 = right > toIntersect.right ? toIntersect.right : right;
  if (x1 <= 0) {
    result = GRect();
  } else {
    var y0 = y < toIntersect.y ? toIntersect.y : y;
    var y1 = bottom > toIntersect.bottom ? toIntersect.bottom : bottom;
    if (y1 <= y0) {
      result = GRect();
    } else {
      result = GRect(x0, y0, x1 - x0, y1 - y0);
    }
  }
  return result;
}