Subject: [Geojson] Polar bounding boxen (#47)

From: Martin Thomson <[email-masked]>
Date: Sat, 30 Jan 2016 18:20:58 +1100

In reviewing this, I think that this is easy.  Antarctica can be
described by [-90, -180, -70 (or whatever), 180]  Obviously anything
less than the full 360 degrees of longitude will have a strange shape.
We should be clear that attempting to create a strange shape by using
latitudes greater than 90 or less than -90 is not valid.

What I find more interesting is those that cross the 180th meridian.
I think that the intent of the draft is to do the most complicated but
most flexible option.  I've opened #133 to track this.

We need to make sure that the obvious, wrong code isn't written.  And
this is wrong:

isPointInBox(point, box) {
return point.lat >= box.min.lat && point.lat <= box.max.lat &&
    point.lng >= box.min.lng && point.lng <= box.max.lng;
}

What we actually need is a different test:

isPointInBox(point, box) {
  var lngDelta = (point.lng - box.min.lng + 360) % 360;
  var lngWidth = (box.max.lng - box.min.lng + 360) % 360;
  return point.lat >= box.min.lat && point.lat <= box.max.lat &&
      lngDelta >= 0 && lngDelta <= lngWidth;
}