S2LatLngRect.expandedByDistance

Expands this rectangle so that it contains all points within the given distance of the boundary, and return the smallest such rectangle. If the distance is negative, then instead shrinks this rectangle so that it excludes all points within the given absolute distance of the boundary, and returns the largest such rectangle.

Unlike Expanded(), this method treats the rectangle as a set of points on the sphere, and measures distances on the sphere. For example, you can use this method to find a rectangle that contains all points within 5km of a given rectangle. Because this method uses the topology of the sphere, note the following:

- The full and empty rectangles have no boundary on the sphere. Any expansion (positive or negative) of these rectangles leaves them unchanged.

- Any rectangle that covers the full longitude range does not have an east or west boundary, therefore no expansion (positive or negative) will occur in that direction.

- Any rectangle that covers the full longitude range and also includes a pole will not be expanded or contracted at that pole, because it does not have a boundary there.

- If a rectangle is within the given distance of a pole, the result will include the full longitude range (because all longitudes are present at the poles).

Expansion and contraction are defined such that they are inverses whenver possible, i.e.

rect.ExpandedByDistance(x).ExpandedByDistance(-x) == rect

(approximately), so long as the first operation does not cause a rectangle boundary to disappear (i.e., the longitude range newly becomes full or empty, or the latitude range expands to include a pole).

class S2LatLngRect
const
expandedByDistance

Meta