[GIS] Specifying a rectangle as two latitude/longitude pairs, one for center and one for size

distancegooglelatitude longitudespherical-geometry

I am trying to make sense of the Google S2 library for spherical math (it works like this). I need to get a rectangle for searching for nearby entities in a database, based on a point and a distance (say, 10km, the distances do not have to be exact, I filter the entities later).

In the S2 library there is a function with the signature:

RectFromCenterSize(center, size LatLng)

Both parameters are latitude/longitude pairs.

I am having difficulty understanding what this means (the documentation is unfortunately very poor). The center point I get, but how does the a lat/lng pair specify the size?

Any help would be greatly appreciated.

Best Answer

From the code it appears that they are using the size to construct half of the rectangle, and then possibly mirroring this half rectangle about the center point, thereby creating the full rectangle.

func RectFromCenterSize(center, size LatLng) Rect {
        half := LatLng{size.Lat / 2, size.Lng / 2}
        return RectFromLatLng(center).expanded(half)