@turf/boolean-crosses
Advanced tools
Comparing version 5.1.5 to 6.0.0
103
index.js
@@ -1,7 +0,8 @@ | ||
import { point } from '@turf/helpers'; | ||
import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; | ||
import lineIntersect from '@turf/line-intersect'; | ||
import polygonToLine from '@turf/polygon-to-line'; | ||
import { getGeom, getType } from '@turf/invariant'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var line_intersect_1 = require("@turf/line-intersect"); | ||
var polygon_to_line_1 = require("@turf/polygon-to-line"); | ||
var boolean_point_in_polygon_1 = require("@turf/boolean-point-in-polygon"); | ||
var invariant_1 = require("@turf/invariant"); | ||
var helpers_1 = require("@turf/helpers"); | ||
/** | ||
@@ -26,42 +27,40 @@ * Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than | ||
function booleanCrosses(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 'MultiPoint': | ||
switch (type2) { | ||
case 'MultiPoint': | ||
switch (type2) { | ||
case 'LineString': | ||
return doMultiPointAndLineStringCross(geom1, geom2); | ||
case 'Polygon': | ||
return doesMultiPointCrossPoly(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'LineString': | ||
return doMultiPointAndLineStringCross(geom1, geom2); | ||
switch (type2) { | ||
case 'MultiPoint':// An inverse operation | ||
return doMultiPointAndLineStringCross(geom2, geom1); | ||
case 'LineString': | ||
return doLineStringsCross(geom1, geom2); | ||
case 'Polygon': | ||
return doLineStringAndPolygonCross(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'Polygon': | ||
return doesMultiPointCrossPoly(geom1, geom2); | ||
switch (type2) { | ||
case 'MultiPoint':// An inverse operation | ||
return doesMultiPointCrossPoly(geom2, geom1); | ||
case 'LineString':// An inverse operation | ||
return doLineStringAndPolygonCross(geom2, geom1); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'LineString': | ||
switch (type2) { | ||
case 'MultiPoint': // An inverse operation | ||
return doMultiPointAndLineStringCross(geom2, geom1); | ||
case 'LineString': | ||
return doLineStringsCross(geom1, geom2); | ||
case 'Polygon': | ||
return doLineStringAndPolygonCross(geom1, geom2); | ||
default: | ||
throw new Error('feature2 ' + type2 + ' geometry not supported'); | ||
} | ||
case 'Polygon': | ||
switch (type2) { | ||
case 'MultiPoint': // An inverse operation | ||
return doesMultiPointCrossPoly(geom2, geom1); | ||
case 'LineString': // An inverse operation | ||
return doLineStringAndPolygonCross(geom2, geom1); | ||
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 doMultiPointAndLineStringCross(multiPoint, lineString) { | ||
@@ -80,3 +79,4 @@ var foundIntPoint = false; | ||
foundIntPoint = true; | ||
} else { | ||
} | ||
else { | ||
foundExtPoint = true; | ||
@@ -89,5 +89,4 @@ } | ||
} | ||
function doLineStringsCross(lineString1, lineString2) { | ||
var doLinesIntersect = lineIntersect(lineString1, lineString2); | ||
var doLinesIntersect = line_intersect_1.default(lineString1, lineString2); | ||
if (doLinesIntersect.features.length > 0) { | ||
@@ -108,5 +107,5 @@ for (var i = 0; i < lineString1.coordinates.length - 1; i++) { | ||
} | ||
function doLineStringAndPolygonCross(lineString, polygon) { | ||
var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon)); | ||
var line = polygon_to_line_1.polygonToLine(polygon); | ||
var doLinesIntersect = line_intersect_1.default(lineString, line); | ||
if (doLinesIntersect.features.length > 0) { | ||
@@ -117,3 +116,2 @@ return true; | ||
} | ||
function doesMultiPointCrossPoly(multiPoint, polygon) { | ||
@@ -125,5 +123,6 @@ var foundIntPoint = false; | ||
while (i < pointLength && foundIntPoint && foundExtPoint) { | ||
if (booleanPointInPolygon(point(multiPoint.coordinates[0][i]), polygon)) { | ||
if (boolean_point_in_polygon_1.default(helpers_1.point(multiPoint.coordinates[0][i]), polygon)) { | ||
foundIntPoint = true; | ||
} else { | ||
} | ||
else { | ||
foundExtPoint = true; | ||
@@ -133,6 +132,4 @@ } | ||
} | ||
return foundExtPoint && foundExtPoint; | ||
} | ||
/** | ||
@@ -164,3 +161,4 @@ * Is a point on a line segment | ||
return dyl > 0 ? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1] : lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1]; | ||
} else { | ||
} | ||
else { | ||
if (Math.abs(dxl) >= Math.abs(dyl)) { | ||
@@ -172,3 +170,2 @@ return dxl > 0 ? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0] : lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0]; | ||
} | ||
export default booleanCrosses; | ||
exports.default = booleanCrosses; |
{ | ||
"name": "@turf/boolean-crosses", | ||
"version": "5.1.5", | ||
"version": "6.0.0", | ||
"description": "turf boolean-crosses 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" | ||
@@ -42,3 +37,2 @@ }, | ||
"devDependencies": { | ||
"@std/esm": "*", | ||
"benchmark": "*", | ||
@@ -48,16 +42,12 @@ "boolean-shapely": "*", | ||
"load-json-file": "*", | ||
"rollup": "*", | ||
"typescript": "*", | ||
"tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/boolean-point-in-polygon": "^5.1.5", | ||
"@turf/helpers": "^5.1.5", | ||
"@turf/invariant": "^5.1.5", | ||
"@turf/line-intersect": "^5.1.5", | ||
"@turf/polygon-to-line": "^5.1.5" | ||
}, | ||
"@std/esm": { | ||
"esm": "js", | ||
"cjs": true | ||
"@turf/boolean-point-in-polygon": "6.x", | ||
"@turf/helpers": "6.x", | ||
"@turf/invariant": "6.x", | ||
"@turf/line-intersect": "6.x", | ||
"@turf/polygon-to-line": "6.x" | ||
} | ||
} |
@@ -54,1 +54,6 @@ # @turf/boolean-crosses | ||
``` | ||
### Diagrams | ||
![esri-crosses](diagrams/esri-crosses.gif) |
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
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
6
58
17492
5
319
1
+ Added@turf/bbox@7.1.0(transitive)
+ Added@turf/boolean-point-in-polygon@6.5.0(transitive)
+ Added@turf/helpers@6.5.07.1.0(transitive)
+ Added@turf/invariant@6.5.0(transitive)
+ Added@turf/line-intersect@6.5.0(transitive)
+ Added@turf/line-segment@6.5.0(transitive)
+ Added@turf/meta@6.5.07.1.0(transitive)
+ Added@turf/polygon-to-line@6.5.0(transitive)
+ Added@types/geojson@7946.0.157946.0.8(transitive)
+ Addedgeojson-rbush@3.2.0(transitive)
+ Addedquickselect@2.0.0(transitive)
+ Addedrbush@3.0.1(transitive)
+ Addedtslib@2.8.1(transitive)
- Removed@turf/boolean-point-in-polygon@5.1.5(transitive)
- Removed@turf/helpers@5.1.5(transitive)
- Removed@turf/invariant@5.2.0(transitive)
- Removed@turf/line-intersect@5.1.5(transitive)
- Removed@turf/line-segment@5.1.5(transitive)
- Removed@turf/meta@5.2.0(transitive)
- Removed@turf/polygon-to-line@5.1.5(transitive)
- Removedgeojson-rbush@2.1.0(transitive)
- Removedquickselect@3.0.0(transitive)
- Removedrbush@4.0.1(transitive)
Updated@turf/helpers@6.x
Updated@turf/invariant@6.x
Updated@turf/line-intersect@6.x
Updated@turf/polygon-to-line@6.x