@turf/boolean-within
Advanced tools
Comparing version 5.1.5 to 6.0.0
150
index.js
@@ -1,6 +0,7 @@ | ||
import calcBbox from '@turf/bbox'; | ||
import booleanPointOnLine from '@turf/boolean-point-on-line'; | ||
import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; | ||
import { getGeom, getType } from '@turf/invariant'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var bbox_1 = require("@turf/bbox"); | ||
var boolean_point_on_line_1 = require("@turf/boolean-point-on-line"); | ||
var boolean_point_in_polygon_1 = require("@turf/boolean-point-in-polygon"); | ||
var invariant_1 = require("@turf/invariant"); | ||
/** | ||
@@ -24,51 +25,53 @@ * Boolean-within returns true if the first geometry is completely within the second geometry. | ||
function booleanWithin(feature1, feature2) { | ||
var type1 = getType(feature1); | ||
var type2 = getType(feature2); | ||
var geom1 = getGeom(feature1); | ||
var geom2 = getGeom(feature2); | ||
var type1 = invariant_1.getType(feature1); | ||
var type2 = invariant_1.getType(feature2); | ||
var geom1 = invariant_1.getGeom(feature1); | ||
var geom2 = invariant_1.getGeom(feature2); | ||
switch (type1) { | ||
case 'Point': | ||
switch (type2) { | ||
case 'Point': | ||
switch (type2) { | ||
case 'MultiPoint': | ||
return isPointInMultiPoint(geom1, geom2); | ||
case 'LineString': | ||
return boolean_point_on_line_1.default(geom1, geom2, { ignoreEndVertices: true }); | ||
case 'Polygon': | ||
case 'MultiPolygon': | ||
return boolean_point_in_polygon_1.default(geom1, geom2, { ignoreBoundary: true }); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'MultiPoint': | ||
return isPointInMultiPoint(geom1, geom2); | ||
switch (type2) { | ||
case 'MultiPoint': | ||
return isMultiPointInMultiPoint(geom1, geom2); | ||
case 'LineString': | ||
return isMultiPointOnLine(geom1, geom2); | ||
case 'Polygon': | ||
case 'MultiPolygon': | ||
return isMultiPointInPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'LineString': | ||
return booleanPointOnLine(geom1, geom2, {ignoreEndVertices: true}); | ||
switch (type2) { | ||
case 'LineString': | ||
return isLineOnLine(geom1, geom2); | ||
case 'Polygon': | ||
case 'MultiPolygon': | ||
return isLineInPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'Polygon': | ||
return booleanPointInPolygon(geom1, geom2, {ignoreBoundary: true}); | ||
switch (type2) { | ||
case 'Polygon': | ||
case 'MultiPolygon': | ||
return isPolyInPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'MultiPoint': | ||
switch (type2) { | ||
case 'MultiPoint': | ||
return isMultiPointInMultiPoint(geom1, geom2); | ||
case 'LineString': | ||
return isMultiPointOnLine(geom1, geom2); | ||
case 'Polygon': | ||
return isMultiPointInPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'LineString': | ||
switch (type2) { | ||
case 'LineString': | ||
return isLineOnLine(geom1, geom2); | ||
case 'Polygon': | ||
return isLineInPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'Polygon': | ||
switch (type2) { | ||
case 'Polygon': | ||
return isPolyInPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
default: | ||
throw new Error('feature1 ' + type1 + ' geometry not supported'); | ||
throw new Error('feature1 ' + type1 + ' geometry not supported'); | ||
} | ||
} | ||
function isPointInMultiPoint(point, multiPoint) { | ||
@@ -85,3 +88,2 @@ var i; | ||
} | ||
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) { | ||
@@ -101,12 +103,10 @@ for (var i = 0; i < multiPoint1.coordinates.length; i++) { | ||
} | ||
function isMultiPointOnLine(multiPoint, lineString) { | ||
var foundInsidePoint = false; | ||
for (var i = 0; i < multiPoint.coordinates.length; i++) { | ||
if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) { | ||
if (!boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString)) { | ||
return false; | ||
} | ||
if (!foundInsidePoint) { | ||
foundInsidePoint = booleanPointOnLine(multiPoint.coordinates[i], lineString, {ignoreEndVertices: true}); | ||
foundInsidePoint = boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString, { ignoreEndVertices: true }); | ||
} | ||
@@ -116,3 +116,2 @@ } | ||
} | ||
function isMultiPointInPoly(multiPoint, polygon) { | ||
@@ -122,3 +121,3 @@ var output = true; | ||
for (var i = 0; i < multiPoint.coordinates.length; i++) { | ||
var isInside = booleanPointInPolygon(multiPoint.coordinates[1], polygon); | ||
var isInside = boolean_point_in_polygon_1.default(multiPoint.coordinates[1], polygon); | ||
if (!isInside) { | ||
@@ -129,3 +128,3 @@ output = false; | ||
if (!oneInside) { | ||
isInside = booleanPointInPolygon(multiPoint.coordinates[1], polygon, {ignoreBoundary: true}); | ||
isInside = boolean_point_in_polygon_1.default(multiPoint.coordinates[1], polygon, { ignoreBoundary: true }); | ||
} | ||
@@ -135,6 +134,5 @@ } | ||
} | ||
function isLineOnLine(lineString1, lineString2) { | ||
for (var i = 0; i < lineString1.coordinates.length; i++) { | ||
if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) { | ||
if (!boolean_point_on_line_1.default(lineString1.coordinates[i], lineString2)) { | ||
return false; | ||
@@ -145,6 +143,5 @@ } | ||
} | ||
function isLineInPoly(linestring, polygon) { | ||
var polyBbox = calcBbox(polygon); | ||
var lineBbox = calcBbox(linestring); | ||
var polyBbox = bbox_1.default(polygon); | ||
var lineBbox = bbox_1.default(linestring); | ||
if (!doBBoxOverlap(polyBbox, lineBbox)) { | ||
@@ -154,14 +151,12 @@ return false; | ||
var foundInsidePoint = false; | ||
for (var i = 0; i < linestring.coordinates.length - 1; i++) { | ||
if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) { | ||
if (!boolean_point_in_polygon_1.default(linestring.coordinates[i], polygon)) { | ||
return false; | ||
} | ||
if (!foundInsidePoint) { | ||
foundInsidePoint = booleanPointInPolygon(linestring.coordinates[i], polygon, {ignoreBoundary: true}); | ||
foundInsidePoint = boolean_point_in_polygon_1.default(linestring.coordinates[i], polygon, { ignoreBoundary: true }); | ||
} | ||
if (!foundInsidePoint) { | ||
var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]); | ||
foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {ignoreBoundary: true}); | ||
foundInsidePoint = boolean_point_in_polygon_1.default(midpoint, polygon, { ignoreBoundary: true }); | ||
} | ||
@@ -171,3 +166,2 @@ } | ||
} | ||
/** | ||
@@ -183,4 +177,4 @@ * Is Polygon2 in Polygon1 | ||
function isPolyInPoly(feature1, feature2) { | ||
var poly1Bbox = calcBbox(feature1); | ||
var poly2Bbox = calcBbox(feature2); | ||
var poly1Bbox = bbox_1.default(feature1); | ||
var poly2Bbox = bbox_1.default(feature2); | ||
if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) { | ||
@@ -190,3 +184,3 @@ return false; | ||
for (var i = 0; i < feature1.coordinates[0].length; i++) { | ||
if (!booleanPointInPolygon(feature1.coordinates[0][i], feature2)) { | ||
if (!boolean_point_in_polygon_1.default(feature1.coordinates[0][i], feature2)) { | ||
return false; | ||
@@ -197,11 +191,13 @@ } | ||
} | ||
function doBBoxOverlap(bbox1, bbox2) { | ||
if (bbox1[0] > bbox2[0]) return false; | ||
if (bbox1[2] < bbox2[2]) return false; | ||
if (bbox1[1] > bbox2[1]) return false; | ||
if (bbox1[3] < bbox2[3]) return false; | ||
if (bbox1[0] > bbox2[0]) | ||
return false; | ||
if (bbox1[2] < bbox2[2]) | ||
return false; | ||
if (bbox1[1] > bbox2[1]) | ||
return false; | ||
if (bbox1[3] < bbox2[3]) | ||
return false; | ||
return true; | ||
} | ||
/** | ||
@@ -218,3 +214,2 @@ * compareCoords | ||
} | ||
/** | ||
@@ -231,3 +226,2 @@ * getMidpoint | ||
} | ||
export default booleanWithin; | ||
exports.default = booleanWithin; |
{ | ||
"name": "@turf/boolean-within", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf boolean-within 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" | ||
@@ -43,3 +38,2 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
@@ -50,16 +44,12 @@ "boolean-jsts": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"typescript": "*", | ||
"tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/bbox": "^5.1.5", | ||
"@turf/boolean-point-in-polygon": "^5.1.5", | ||
"@turf/boolean-point-on-line": "^5.1.5", | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/invariant": "^5.1.5" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/bbox": "6.x", | ||
"@turf/boolean-point-in-polygon": "6.x", | ||
"@turf/boolean-point-on-line": "6.x", | ||
"@turf/helpers": "6.x", | ||
"@turf/invariant": "6.x" | ||
} | ||
} |
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
7
18711
5
419
1
+ Added@turf/bbox@6.5.0(transitive)
+ Added@turf/boolean-point-in-polygon@6.5.0(transitive)
+ Added@turf/boolean-point-on-line@6.5.0(transitive)
+ Added@turf/helpers@6.5.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
+ Added@turf/meta@6.5.0(transitive)
- Removed@turf/bbox@5.1.5(transitive)
- Removed@turf/boolean-point-in-polygon@5.1.5(transitive)
- Removed@turf/boolean-point-on-line@5.1.5(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/invariant@5.2.0(transitive)
- Removed@turf/meta@5.2.0(transitive)
Updated@turf/bbox@6.x
Updated@turf/helpers@6.x
Updated@turf/invariant@6.x