@turf/boolean-point-in-polygon
Advanced tools
Comparing version 6.0.0 to 6.0.1
44
index.js
@@ -8,4 +8,4 @@ "use strict"; | ||
/** | ||
* Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point resides inside the polygon. The polygon can | ||
* be convex or concave. The function accounts for holes. | ||
* Takes a {@link Point} and a {@link Polygon} or {@link MultiPolygon} and determines if the point | ||
* resides inside the polygon. The polygon can be convex or concave. The function accounts for holes. | ||
* | ||
@@ -16,3 +16,4 @@ * @name booleanPointInPolygon | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if the point is inside the polygon otherwise false. | ||
* @param {boolean} [options.ignoreBoundary=false] True if polygon boundary should be ignored when determining if | ||
* the point is inside the polygon otherwise false. | ||
* @returns {boolean} `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon | ||
@@ -35,6 +36,8 @@ * @example | ||
// validation | ||
if (!point) | ||
throw new Error('point is required'); | ||
if (!polygon) | ||
throw new Error('polygon is required'); | ||
if (!point) { | ||
throw new Error("point is required"); | ||
} | ||
if (!polygon) { | ||
throw new Error("polygon is required"); | ||
} | ||
var pt = invariant_1.getCoord(point); | ||
@@ -46,8 +49,11 @@ var geom = invariant_1.getGeom(polygon); | ||
// Quick elimination if point is not inside bbox | ||
if (bbox && inBBox(pt, bbox) === false) | ||
if (bbox && inBBox(pt, bbox) === false) { | ||
return false; | ||
} | ||
// normalize to multipolygon | ||
if (type === 'Polygon') | ||
if (type === "Polygon") { | ||
polys = [polys]; | ||
for (var i = 0, insidePoly = false; i < polys.length && !insidePoly; i++) { | ||
} | ||
var insidePoly = false; | ||
for (var i = 0; i < polys.length && !insidePoly; i++) { | ||
// check if it is in the outer ring first | ||
@@ -64,4 +70,5 @@ if (inRing(pt, polys[i][0], options.ignoreBoundary)) { | ||
} | ||
if (!inHole) | ||
if (!inHole) { | ||
insidePoly = true; | ||
} | ||
} | ||
@@ -83,15 +90,20 @@ } | ||
var isInside = false; | ||
if (ring[0][0] === ring[ring.length - 1][0] && ring[0][1] === ring[ring.length - 1][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++) { | ||
var xi = ring[i][0], yi = ring[i][1]; | ||
var xj = ring[j][0], yj = ring[j][1]; | ||
var xi = ring[i][0]; | ||
var yi = ring[i][1]; | ||
var xj = ring[j][0]; | ||
var yj = ring[j][1]; | ||
var onBoundary = (pt[1] * (xi - xj) + yi * (xj - pt[0]) + yj * (pt[0] - xi) === 0) && | ||
((xi - pt[0]) * (xj - pt[0]) <= 0) && ((yi - pt[1]) * (yj - pt[1]) <= 0); | ||
if (onBoundary) | ||
if (onBoundary) { | ||
return !ignoreBoundary; | ||
} | ||
var intersect = ((yi > pt[1]) !== (yj > pt[1])) && | ||
(pt[0] < (xj - xi) * (pt[1] - yi) / (yj - yi) + xi); | ||
if (intersect) | ||
if (intersect) { | ||
isInside = !isInside; | ||
} | ||
} | ||
@@ -98,0 +110,0 @@ return isInside; |
@@ -1,12 +0,13 @@ | ||
{ | ||
"name": "@turf/boolean-point-in-polygon", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "turf boolean-point-in-polygon module", | ||
"main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.ts" | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
@@ -38,3 +39,5 @@ "test": "node test.js", | ||
"typescript": "*", | ||
"tape": "*" | ||
"tape": "*", | ||
"tslint": "*", | ||
"@types/tape": "*" | ||
}, | ||
@@ -41,0 +44,0 @@ "dependencies": { |
@@ -7,3 +7,3 @@ # @turf/boolean-point-in-polygon | ||
Takes a [Point](https://tools.ietf.org/html/rfc7946#section-3.1.2) and a [Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) or [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7) and determines if the point resides inside the polygon. The polygon can | ||
Takes a [Point][1] and a [Polygon][2] or [MultiPolygon][3] and determines if the point resides inside the polygon. The polygon can | ||
be convex or concave. The function accounts for holes. | ||
@@ -13,6 +13,6 @@ | ||
- `point` **[Coord](https://tools.ietf.org/html/rfc7946#section-3.1.1)** input point | ||
- `polygon` **[Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<([Polygon](https://tools.ietf.org/html/rfc7946#section-3.1.6) \| [MultiPolygon](https://tools.ietf.org/html/rfc7946#section-3.1.7))>** input polygon or multipolygon | ||
- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** Optional parameters (optional, default `{}`) | ||
- `options.ignoreBoundary` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** True if polygon boundary should be ignored when determining if the point is inside the polygon otherwise false. (optional, default `false`) | ||
- `point` **[Coord][4]** input point | ||
- `polygon` **[Feature][5]<([Polygon][6] \| [MultiPolygon][7])>** input polygon or multipolygon | ||
- `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
- `options.ignoreBoundary` **[boolean][9]** True if polygon boundary should be ignored when determining if the point is inside the polygon otherwise false. (optional, default `false`) | ||
@@ -35,4 +35,22 @@ **Examples** | ||
Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon | ||
Returns **[boolean][9]** `true` if the Point is inside the Polygon; `false` if the Point is not inside the Polygon | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
[2]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[3]: https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
[4]: https://tools.ietf.org/html/rfc7946#section-3.1.1 | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.6 | ||
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.7 | ||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean | ||
<!-- This file is automatically generated. Please don't edit it directly: | ||
@@ -39,0 +57,0 @@ if you find an error, edit the source file (likely index.js), and re-run |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
77
0
9548
5
147