@turf/boolean-disjoint
Advanced tools
Comparing version 6.0.0 to 6.0.1
80
index.js
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var boolean_point_in_polygon_1 = require("@turf/boolean-point-in-polygon"); | ||
var boolean_point_in_polygon_1 = __importDefault(require("@turf/boolean-point-in-polygon")); | ||
var line_intersect_1 = __importDefault(require("@turf/line-intersect")); | ||
var meta_1 = require("@turf/meta"); | ||
var line_intersect_1 = require("@turf/line-intersect"); | ||
var polygon_to_line_1 = require("@turf/polygon-to-line"); | ||
var polygon_to_line_1 = __importDefault(require("@turf/polygon-to-line")); | ||
/** | ||
@@ -22,11 +25,12 @@ * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set. | ||
function booleanDisjoint(feature1, feature2) { | ||
var boolean; | ||
var bool = true; | ||
meta_1.flattenEach(feature1, function (flatten1) { | ||
meta_1.flattenEach(feature2, function (flatten2) { | ||
if (boolean === false) | ||
if (bool === false) { | ||
return false; | ||
boolean = disjoint(flatten1.geometry, flatten2.geometry); | ||
} | ||
bool = disjoint(flatten1.geometry, flatten2.geometry); | ||
}); | ||
}); | ||
return boolean; | ||
return bool; | ||
} | ||
@@ -43,9 +47,9 @@ /** | ||
switch (geom1.type) { | ||
case 'Point': | ||
case "Point": | ||
switch (geom2.type) { | ||
case 'Point': | ||
case "Point": | ||
return !compareCoords(geom1.coordinates, geom2.coordinates); | ||
case 'LineString': | ||
case "LineString": | ||
return !isPointOnLine(geom2, geom1); | ||
case 'Polygon': | ||
case "Polygon": | ||
return !boolean_point_in_polygon_1.default(geom1, geom2); | ||
@@ -55,9 +59,9 @@ } | ||
break; | ||
case 'LineString': | ||
case "LineString": | ||
switch (geom2.type) { | ||
case 'Point': | ||
case "Point": | ||
return !isPointOnLine(geom1, geom2); | ||
case 'LineString': | ||
case "LineString": | ||
return !isLineOnLine(geom1, geom2); | ||
case 'Polygon': | ||
case "Polygon": | ||
return !isLineInPoly(geom2, geom1); | ||
@@ -67,17 +71,18 @@ } | ||
break; | ||
case 'Polygon': | ||
case "Polygon": | ||
switch (geom2.type) { | ||
case 'Point': | ||
case "Point": | ||
return !boolean_point_in_polygon_1.default(geom2, geom1); | ||
case 'LineString': | ||
case "LineString": | ||
return !isLineInPoly(geom1, geom2); | ||
case 'Polygon': | ||
case "Polygon": | ||
return !isPolyInPoly(geom2, geom1); | ||
} | ||
} | ||
return false; | ||
} | ||
// http://stackoverflow.com/a/11908158/1979085 | ||
function isPointOnLine(lineString, point) { | ||
function isPointOnLine(lineString, pt) { | ||
for (var i = 0; i < lineString.coordinates.length - 1; i++) { | ||
if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], point.coordinates)) { | ||
if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], pt.coordinates)) { | ||
return true; | ||
@@ -96,4 +101,5 @@ } | ||
function isLineInPoly(polygon, lineString) { | ||
for (var i = 0; i < lineString.coordinates.length; i++) { | ||
if (boolean_point_in_polygon_1.default(lineString.coordinates[i], polygon)) { | ||
for (var _i = 0, _a = lineString.coordinates; _i < _a.length; _i++) { | ||
var coord = _a[_i]; | ||
if (boolean_point_in_polygon_1.default(coord, polygon)) { | ||
return true; | ||
@@ -119,9 +125,11 @@ } | ||
function isPolyInPoly(feature1, feature2) { | ||
for (var i = 0; i < feature1.coordinates[0].length; i++) { | ||
if (boolean_point_in_polygon_1.default(feature1.coordinates[0][i], feature2)) { | ||
for (var _i = 0, _a = feature1.coordinates[0]; _i < _a.length; _i++) { | ||
var coord1 = _a[_i]; | ||
if (boolean_point_in_polygon_1.default(coord1, feature2)) { | ||
return true; | ||
} | ||
} | ||
for (var i2 = 0; i2 < feature2.coordinates[0].length; i2++) { | ||
if (boolean_point_in_polygon_1.default(feature2.coordinates[0][i2], feature1)) { | ||
for (var _b = 0, _c = feature2.coordinates[0]; _b < _c.length; _b++) { | ||
var coord2 = _c[_b]; | ||
if (boolean_point_in_polygon_1.default(coord2, feature1)) { | ||
return true; | ||
@@ -136,7 +144,7 @@ } | ||
} | ||
function isPointOnLineSegment(LineSegmentStart, LineSegmentEnd, Point) { | ||
var dxc = Point[0] - LineSegmentStart[0]; | ||
var dyc = Point[1] - LineSegmentStart[1]; | ||
var dxl = LineSegmentEnd[0] - LineSegmentStart[0]; | ||
var dyl = LineSegmentEnd[1] - LineSegmentStart[1]; | ||
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) { | ||
var dxc = pt[0] - lineSegmentStart[0]; | ||
var dyc = pt[1] - lineSegmentStart[1]; | ||
var dxl = lineSegmentEnd[0] - lineSegmentStart[0]; | ||
var dyl = lineSegmentEnd[1] - lineSegmentStart[1]; | ||
var cross = dxc * dyl - dyc * dxl; | ||
@@ -148,13 +156,13 @@ if (cross !== 0) { | ||
if (dxl > 0) { | ||
return LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0]; | ||
return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]; | ||
} | ||
else { | ||
return LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0]; | ||
return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0]; | ||
} | ||
} | ||
else if (dyl > 0) { | ||
return LineSegmentStart[1] <= Point[1] && Point[1] <= LineSegmentEnd[1]; | ||
return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]; | ||
} | ||
else { | ||
return LineSegmentEnd[1] <= Point[1] && Point[1] <= LineSegmentStart[1]; | ||
return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1]; | ||
} | ||
@@ -161,0 +169,0 @@ } |
101
index.ts
@@ -1,6 +0,6 @@ | ||
import booleanPointInPolygon from '@turf/boolean-point-in-polygon'; | ||
import { flattenEach } from '@turf/meta'; | ||
import lineIntersect from '@turf/line-intersect'; | ||
import polygonToLine from '@turf/polygon-to-line'; | ||
import { Feature, Geometry } from '@turf/helpers'; | ||
import booleanPointInPolygon from "@turf/boolean-point-in-polygon"; | ||
import { BBox, Feature, Geometry, LineString, Point, Polygon } from "@turf/helpers"; | ||
import lineIntersect from "@turf/line-intersect"; | ||
import { flattenEach } from "@turf/meta"; | ||
import polygonToLine from "@turf/polygon-to-line"; | ||
@@ -22,10 +22,10 @@ /** | ||
function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean { | ||
var boolean; | ||
flattenEach(feature1, function (flatten1) { | ||
flattenEach(feature2, function (flatten2) { | ||
if (boolean === false) return false; | ||
boolean = disjoint(flatten1.geometry, flatten2.geometry); | ||
let bool = true; | ||
flattenEach(feature1, (flatten1) => { | ||
flattenEach(feature2, (flatten2) => { | ||
if (bool === false) { return false; } | ||
bool = disjoint(flatten1.geometry, flatten2.geometry); | ||
}); | ||
}); | ||
return boolean; | ||
return bool; | ||
} | ||
@@ -41,11 +41,11 @@ | ||
*/ | ||
function disjoint(geom1, geom2) { | ||
function disjoint(geom1: any, geom2: any) { | ||
switch (geom1.type) { | ||
case 'Point': | ||
case "Point": | ||
switch (geom2.type) { | ||
case 'Point': | ||
case "Point": | ||
return !compareCoords(geom1.coordinates, geom2.coordinates); | ||
case 'LineString': | ||
case "LineString": | ||
return !isPointOnLine(geom2, geom1); | ||
case 'Polygon': | ||
case "Polygon": | ||
return !booleanPointInPolygon(geom1, geom2); | ||
@@ -55,9 +55,9 @@ } | ||
break; | ||
case 'LineString': | ||
case "LineString": | ||
switch (geom2.type) { | ||
case 'Point': | ||
case "Point": | ||
return !isPointOnLine(geom1, geom2); | ||
case 'LineString': | ||
case "LineString": | ||
return !isLineOnLine(geom1, geom2); | ||
case 'Polygon': | ||
case "Polygon": | ||
return !isLineInPoly(geom2, geom1); | ||
@@ -67,18 +67,19 @@ } | ||
break; | ||
case 'Polygon': | ||
case "Polygon": | ||
switch (geom2.type) { | ||
case 'Point': | ||
case "Point": | ||
return !booleanPointInPolygon(geom2, geom1); | ||
case 'LineString': | ||
case "LineString": | ||
return !isLineInPoly(geom1, geom2); | ||
case 'Polygon': | ||
case "Polygon": | ||
return !isPolyInPoly(geom2, geom1); | ||
} | ||
} | ||
return false; | ||
} | ||
// http://stackoverflow.com/a/11908158/1979085 | ||
function isPointOnLine(lineString, point) { | ||
for (var i = 0; i < lineString.coordinates.length - 1; i++) { | ||
if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], point.coordinates)) { | ||
function isPointOnLine(lineString: LineString, pt: Point) { | ||
for (let i = 0; i < lineString.coordinates.length - 1; i++) { | ||
if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], pt.coordinates)) { | ||
return true; | ||
@@ -90,4 +91,4 @@ } | ||
function isLineOnLine(lineString1, lineString2) { | ||
var doLinesIntersect = lineIntersect(lineString1, lineString2); | ||
function isLineOnLine(lineString1: LineString, lineString2: LineString) { | ||
const doLinesIntersect = lineIntersect(lineString1, lineString2); | ||
if (doLinesIntersect.features.length > 0) { | ||
@@ -99,9 +100,9 @@ return true; | ||
function isLineInPoly(polygon, lineString) { | ||
for (var i = 0; i < lineString.coordinates.length; i++) { | ||
if (booleanPointInPolygon(lineString.coordinates[i], polygon)) { | ||
function isLineInPoly(polygon: Polygon, lineString: LineString) { | ||
for (const coord of lineString.coordinates) { | ||
if (booleanPointInPolygon(coord, polygon)) { | ||
return true; | ||
} | ||
} | ||
var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon)); | ||
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon)); | ||
if (doLinesIntersect.features.length > 0) { | ||
@@ -123,14 +124,14 @@ return true; | ||
*/ | ||
function isPolyInPoly(feature1, feature2) { | ||
for (var i = 0; i < feature1.coordinates[0].length; i++) { | ||
if (booleanPointInPolygon(feature1.coordinates[0][i], feature2)) { | ||
function isPolyInPoly(feature1: Polygon, feature2: Polygon) { | ||
for (const coord1 of feature1.coordinates[0]) { | ||
if (booleanPointInPolygon(coord1, feature2)) { | ||
return true; | ||
} | ||
} | ||
for (var i2 = 0; i2 < feature2.coordinates[0].length; i2++) { | ||
if (booleanPointInPolygon(feature2.coordinates[0][i2], feature1)) { | ||
for (const coord2 of feature2.coordinates[0]) { | ||
if (booleanPointInPolygon(coord2, feature1)) { | ||
return true; | ||
} | ||
} | ||
var doLinesIntersect = lineIntersect(polygonToLine(feature1), polygonToLine(feature2)); | ||
const doLinesIntersect = lineIntersect(polygonToLine(feature1), polygonToLine(feature2)); | ||
if (doLinesIntersect.features.length > 0) { | ||
@@ -142,8 +143,8 @@ return true; | ||
function isPointOnLineSegment(LineSegmentStart, LineSegmentEnd, Point) { | ||
var dxc = Point[0] - LineSegmentStart[0]; | ||
var dyc = Point[1] - LineSegmentStart[1]; | ||
var dxl = LineSegmentEnd[0] - LineSegmentStart[0]; | ||
var dyl = LineSegmentEnd[1] - LineSegmentStart[1]; | ||
var cross = dxc * dyl - dyc * dxl; | ||
function isPointOnLineSegment(lineSegmentStart: number[], lineSegmentEnd: number[], pt: number[]) { | ||
const dxc = pt[0] - lineSegmentStart[0]; | ||
const dyc = pt[1] - lineSegmentStart[1]; | ||
const dxl = lineSegmentEnd[0] - lineSegmentStart[0]; | ||
const dyl = lineSegmentEnd[1] - lineSegmentStart[1]; | ||
const cross = dxc * dyl - dyc * dxl; | ||
if (cross !== 0) { | ||
@@ -154,10 +155,10 @@ return false; | ||
if (dxl > 0) { | ||
return LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0]; | ||
return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]; | ||
} else { | ||
return LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0]; | ||
return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0]; | ||
} | ||
} else if (dyl > 0) { | ||
return LineSegmentStart[1] <= Point[1] && Point[1] <= LineSegmentEnd[1]; | ||
return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]; | ||
} else { | ||
return LineSegmentEnd[1] <= Point[1] && Point[1] <= LineSegmentStart[1]; | ||
return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1]; | ||
} | ||
@@ -174,3 +175,3 @@ } | ||
*/ | ||
function compareCoords(pair1, pair2) { | ||
function compareCoords(pair1: number[], pair2: number[]) { | ||
return pair1[0] === pair2[0] && pair1[1] === pair2[1]; | ||
@@ -177,0 +178,0 @@ } |
{ | ||
"name": "@turf/boolean-disjoint", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "turf boolean-disjoint module", | ||
"main": "index", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.ts" | ||
"index.ts", | ||
"index.d.ts" | ||
], | ||
"scripts": { | ||
"prepare": "tsc", | ||
"pretest": "tsc", | ||
@@ -41,6 +44,8 @@ "test": "node test.js", | ||
"typescript": "*", | ||
"tape": "*" | ||
"tape": "*", | ||
"tslint": "*", | ||
"@types/tape": "*" | ||
}, | ||
"dependencies": { | ||
"@turf/boolean-point-in-polygon": "6.0.0", | ||
"@turf/boolean-point-in-polygon": "6.x", | ||
"@turf/helpers": "6.x", | ||
@@ -47,0 +52,0 @@ "@turf/line-intersect": "6.x", |
@@ -11,4 +11,4 @@ # @turf/boolean-disjoint | ||
- `feature1` **([Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<any>)** GeoJSON Feature or Geometry | ||
- `feature2` **([Geometry](https://tools.ietf.org/html/rfc7946#section-3.1) \| [Feature](https://tools.ietf.org/html/rfc7946#section-3.2)<any>)** GeoJSON Feature or Geometry | ||
- `feature1` **([Geometry][1] \| [Feature][2]<any>)** GeoJSON Feature or Geometry | ||
- `feature2` **([Geometry][1] \| [Feature][2]<any>)** GeoJSON Feature or Geometry | ||
@@ -25,4 +25,10 @@ **Examples** | ||
Returns **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** true/false | ||
Returns **[boolean][3]** true/false | ||
[1]: https://tools.ietf.org/html/rfc7946#section-3.1 | ||
[2]: https://tools.ietf.org/html/rfc7946#section-3.2 | ||
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean | ||
<!-- This file is automatically generated. Please don't edit it directly: | ||
@@ -29,0 +35,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
15859
6
351
60
0
7
+ Added@turf/boolean-point-in-polygon@6.5.0(transitive)
- Removed@turf/boolean-point-in-polygon@6.0.0(transitive)