S2LatLngRect.expanded

Returns a rectangle that has been expanded by margin.lat() on each side in the latitude direction, and by margin.lng() on each side in the longitude direction. If either margin is negative, then shrinks the rectangle on the corresponding sides instead. The resulting rectangle may be empty.

As noted above, the latitude-longitude space has the topology of a cylinder. Longitudes "wrap around" at +/-180 degrees, while latitudes are clamped to range [-90, 90]. This means that any expansion (positive or negative) of the full longitude range remains full (since the "rectangle" is actually a continuous band around the cylinder), while expansion of the full latitude range remains full only if the margin is positive.

If either the latitude or longitude interval becomes empty after expansion by a negative margin, the result is empty.

Note that if an expanded rectangle contains a pole, it may not contain all possible lat/lng representations of that pole (see header above). Use the PolarClosure() method if you do not want this behavior.

If you are trying to grow a rectangle by a certain *distance* on the sphere (e.g. 5km), use the ExpandedByDistance() method instead.

class S2LatLngRect
const
expanded

Meta