Skip to content

Instantly share code, notes, and snippets.

@ivalkenburg
Created October 10, 2019 10:35
Show Gist options
  • Save ivalkenburg/667d16266e5692e53af566c105d42006 to your computer and use it in GitHub Desktop.
Save ivalkenburg/667d16266e5692e53af566c105d42006 to your computer and use it in GitHub Desktop.
const box = {
sw: {long: -16.14990234375, lat: -26.980828590472107}, // bl
ne: {long: 39.7265625, lat: 20.632784250388028}, // tr
};
const points = [
{long: 21.62109375, lat: 3.601142320158735}, // inside
{long: -11.513671874999998, lat: 16.551961721972525}, // inside
{long: 28.4765625, lat: -19.228176737766248}, // inside
{long: 4.130859375, lat: 0.4394488164139768}, // inside
{long: 13.359375, lat: 26.115985925333536}, // outside
{long: 46.7578125, lat: -4.039617826768424}, // outside
{long: 11.25, lat: -27.293689224852393}, // outside
{long: -19.335937499999996, lat: 3.0746950723696944}, // outside
];
const withinBox = function(sw, ne, point) {
return point.lat >= sw.lat && point.lat <= ne.lat
&& (ne.long < sw.long ? (point.long >= sw.long || point.long <= ne.long) : (point.long >= sw.long && point.long <= ne.long));
};
const inside = points.filter(point => {
return withinBox(box.sw, box.ne, point);
});
console.log(inside);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment