Socket
Socket
Sign inDemoInstall

@turf/boolean-point-in-polygon

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/boolean-point-in-polygon - npm Package Compare versions

Comparing version 5.1.5 to 6.0.0

index.ts

65

index.js

@@ -1,7 +0,7 @@

import { getCoord, getCoords } from '@turf/invariant';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var invariant_1 = require("@turf/invariant");
// http://en.wikipedia.org/wiki/Even%E2%80%93odd_rule
// modified from: https://github.com/substack/point-in-polygon/blob/master/index.js
// which was modified from http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
/**

@@ -31,25 +31,22 @@ * Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point resides inside the polygon. The polygon can

function booleanPointInPolygon(point, polygon, options) {
// Optional parameters
options = options || {};
if (typeof options !== 'object') throw new Error('options is invalid');
var ignoreBoundary = options.ignoreBoundary;
if (options === void 0) { options = {}; }
// validation
if (!point) throw new Error('point is required');
if (!polygon) throw new Error('polygon is required');
var pt = getCoord(point);
var polys = getCoords(polygon);
var type = (polygon.geometry) ? polygon.geometry.type : polygon.type;
if (!point)
throw new Error('point is required');
if (!polygon)
throw new Error('polygon is required');
var pt = invariant_1.getCoord(point);
var geom = invariant_1.getGeom(polygon);
var type = geom.type;
var bbox = polygon.bbox;
var polys = geom.coordinates;
// Quick elimination if point is not inside bbox
if (bbox && inBBox(pt, bbox) === false) return false;
if (bbox && inBBox(pt, bbox) === false)
return false;
// normalize to multipolygon
if (type === 'Polygon') polys = [polys];
if (type === 'Polygon')
polys = [polys];
for (var i = 0, insidePoly = false; i < polys.length && !insidePoly; i++) {
// check if it is in the outer ring first
if (inRing(pt, polys[i][0], ignoreBoundary)) {
if (inRing(pt, polys[i][0], options.ignoreBoundary)) {
var inHole = false;

@@ -59,3 +56,3 @@ var k = 1;

while (k < polys[i].length && !inHole) {
if (inRing(pt, polys[i][k], !ignoreBoundary)) {
if (inRing(pt, polys[i][k], !options.ignoreBoundary)) {
inHole = true;

@@ -65,3 +62,4 @@ }

}
if (!inHole) insidePoly = true;
if (!inHole)
insidePoly = true;
}

@@ -71,3 +69,3 @@ }

}
exports.default = booleanPointInPolygon;
/**

@@ -84,4 +82,4 @@ * inRing

var isInside = false;
if (ring[0][0] === ring[ring.length - 1][0] && ring[0][1] === ring[ring.length - 1][1]) ring = ring.slice(0, ring.length - 1);
if (ring[0][0] === ring[ring.length - 1][0] && ring[0][1] === ring[ring.length - 1][1])
ring = ring.slice(0, ring.length - 1);
for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {

@@ -92,10 +90,11 @@ var xi = ring[i][0], yi = ring[i][1];

((xi - pt[0]) * (xj - pt[0]) <= 0) && ((yi - pt[1]) * (yj - pt[1]) <= 0);
if (onBoundary) return !ignoreBoundary;
if (onBoundary)
return !ignoreBoundary;
var intersect = ((yi > pt[1]) !== (yj > pt[1])) &&
(pt[0] < (xj - xi) * (pt[1] - yi) / (yj - yi) + xi);
if (intersect) isInside = !isInside;
(pt[0] < (xj - xi) * (pt[1] - yi) / (yj - yi) + xi);
if (intersect)
isInside = !isInside;
}
return isInside;
}
/**

@@ -111,7 +110,5 @@ * inBBox

return bbox[0] <= pt[0] &&
bbox[1] <= pt[1] &&
bbox[2] >= pt[0] &&
bbox[3] >= pt[1];
bbox[1] <= pt[1] &&
bbox[2] >= pt[0] &&
bbox[3] >= pt[1];
}
export default booleanPointInPolygon;

@@ -0,19 +1,15 @@

{
"name": "@turf/boolean-point-in-polygon",
"version": "5.1.5",
"version": "6.0.0",
"description": "turf boolean-point-in-polygon module",
"main": "main.js",
"module": "main.es.js",
"types": "index.d.ts",
"main": "index",
"files": [
"index.js",
"index.d.ts",
"main.js",
"main.es.js"
"index.ts"
],
"scripts": {
"pretest": "rollup -c ../../rollup.config.js",
"test": "node -r @std/esm test.js",
"posttest": "node -r @std/esm ../../scripts/validate-es5-dependencies.js",
"bench": "node -r @std/esm bench.js",
"pretest": "tsc",
"test": "node test.js",
"bench": "node bench.js",
"docs": "node ../../scripts/generate-readmes"

@@ -40,15 +36,10 @@ },

"devDependencies": {
"@std/esm": "*",
"benchmark": "*",
"rollup": "*",
"typescript": "*",
"tape": "*"
},
"dependencies": {
"@turf/helpers": "^5.1.5",
"@turf/invariant": "^5.1.5"
},
"@std/esm": {
"esm": "js",
"cjs": true
"@turf/helpers": "6.x",
"@turf/invariant": "6.x"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc