Functional Weave
Code in Python

geo.bounding-box@1.0.0

vectors.json

2,743 bytes · view raw

[
  { "name": "10 km around central London", "args": [51.5074, -0.1278, 10000], "expect": { "minLat": 51.4174679, "minLng": -0.2722893, "maxLat": 51.5973321, "maxLng": 0.0166893 } },
  { "name": "100 km around the origin is square in degrees on the equator", "args": [0, 0, 100000], "expect": { "minLat": -0.8993204, "minLng": -0.8993204, "maxLat": 0.8993204, "maxLng": 0.8993204 } },
  { "name": "at 60 degrees north the longitude span is about twice the latitude span", "args": [60, 10, 100000], "expect": { "minLat": 59.1006796, "minLng": 8.2011376, "maxLat": 60.8993204, "maxLng": 11.7988624 } },
  { "name": "southern and eastern hemispheres", "args": [-33.8688, 151.2093, 5000], "expect": { "minLat": -33.9137661, "minLng": 151.1551446, "maxLat": -33.8238339, "maxLng": 151.2634554 } },
  { "name": "zero distance is the point itself, not nudged a grid step outward by its binary value", "args": [51.5074, -0.1278, 0], "expect": { "minLat": 51.5074, "minLng": -0.1278, "maxLat": 51.5074, "maxLng": -0.1278 } },
  { "name": "crossing the antimeridian wraps maxLng round, so minLng > maxLng", "args": [0, 179.9, 50000], "expect": { "minLat": -0.4496602, "minLng": 179.4503398, "maxLat": 0.4496602, "maxLng": -179.6503398 } },
  { "name": "a centre on the antimeridian wraps minLng round", "args": [45, -180, 1000], "expect": { "minLat": 44.9910067, "minLng": 179.9872816, "maxLat": 45.0089933, "maxLng": -179.9872816 } },
  { "name": "a circle over the north pole covers every longitude (the asin formula alone gives NaN here)", "args": [89.9, 0, 20000], "expect": { "minLat": 89.7201359, "minLng": -180, "maxLat": 90, "maxLng": 180 } },
  { "name": "a circle over the south pole covers every longitude", "args": [-89.95, 45, 10000], "expect": { "minLat": -90, "minLng": -180, "maxLat": -89.8600679, "maxLng": 180 } },
  { "name": "just short of the pole the longitude span is very wide but not global", "args": [80, 0, 1100000], "expect": { "minLat": 70.1074759, "minLng": -81.6344542, "maxLat": 89.8925241, "maxLng": 81.6344542 } },
  { "name": "a radius larger than the Earth is the whole globe", "args": [0, 0, 30000000], "expect": { "minLat": -90, "minLng": -180, "maxLat": 90, "maxLng": 180 } },
  { "name": "negative distance is an error", "args": [51.5, 0, -1], "expectError": "distance must be 0 or more metres" },
  { "name": "latitude out of range is an error", "args": [95, 0, 1000], "expectError": "latitude must be between -90 and 90 degrees" },
  { "name": "longitude out of range is an error", "args": [0, -181, 1000], "expectError": "longitude must be between -180 and 180 degrees" },
  { "name": "a distance that is not a number is an error", "args": [0, 0, "10km"], "expectError": "distance must be a finite number" }
]