makeIntersection method

RectangleGeographicArea makeIntersection(
  1. RectangleGeographicArea area
)

Creates the intersection of this rectangle with another rectangle.

Computes a new rectangle representing the overlapping area between this rectangle and the specified rectangle. If the rectangles do not intersect, the result may be an invalid rectangle with no area.

Parameters

Returns

  • A new RectangleGeographicArea representing the intersection area. May be invalid (empty) if the rectangles do not overlap. The user is responsible for checking validity after intersection.

Implementation

RectangleGeographicArea makeIntersection(final RectangleGeographicArea area) {
  return RectangleGeographicArea(
    topLeft: Coordinates(
      longitude: max(topLeft.longitude, area.topLeft.longitude),
      latitude: min(topLeft.latitude, area.topLeft.latitude),
    ),
    bottomRight: Coordinates(
      longitude: min(bottomRight.longitude, area.bottomRight.longitude),
      latitude: max(bottomRight.latitude, area.bottomRight.latitude),
    ),
  );
}