@turf/boolean-disjoint 7.0.0-alpha.1 → 7.0.0-alpha.110
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -9
- package/dist/cjs/index.cjs +143 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +4 -2
- package/dist/esm/index.d.mts +19 -0
- package/dist/esm/index.mjs +143 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +34 -29
- package/dist/es/index.js +0 -165
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -168
package/README.md
CHANGED
|
@@ -29,26 +29,21 @@ Returns **[boolean][3]** true/false
|
|
|
29
29
|
|
|
30
30
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
31
31
|
|
|
32
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
33
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
34
|
-
./scripts/generate-readmes in the turf project. -->
|
|
32
|
+
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
|
|
35
33
|
|
|
36
34
|
---
|
|
37
35
|
|
|
38
|
-
This module is part of the [Turfjs project](
|
|
39
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
40
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
41
|
-
PRs and issues.
|
|
36
|
+
This module is part of the [Turfjs project](https://turfjs.org/), an open source module collection dedicated to geographic algorithms. It is maintained in the [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create PRs and issues.
|
|
42
37
|
|
|
43
38
|
### Installation
|
|
44
39
|
|
|
45
|
-
Install this module individually:
|
|
40
|
+
Install this single module individually:
|
|
46
41
|
|
|
47
42
|
```sh
|
|
48
43
|
$ npm install @turf/boolean-disjoint
|
|
49
44
|
```
|
|
50
45
|
|
|
51
|
-
Or install the
|
|
46
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
52
47
|
|
|
53
48
|
```sh
|
|
54
49
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
|
|
6
|
+
var _lineintersect = require('@turf/line-intersect');
|
|
7
|
+
var _meta = require('@turf/meta');
|
|
8
|
+
var _polygontoline = require('@turf/polygon-to-line');
|
|
9
|
+
function booleanDisjoint(feature1, feature2) {
|
|
10
|
+
let bool = true;
|
|
11
|
+
_meta.flattenEach.call(void 0, feature1, (flatten1) => {
|
|
12
|
+
_meta.flattenEach.call(void 0, feature2, (flatten2) => {
|
|
13
|
+
if (bool === false) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
bool = disjoint(flatten1.geometry, flatten2.geometry);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return bool;
|
|
20
|
+
}
|
|
21
|
+
__name(booleanDisjoint, "booleanDisjoint");
|
|
22
|
+
function disjoint(geom1, geom2) {
|
|
23
|
+
switch (geom1.type) {
|
|
24
|
+
case "Point":
|
|
25
|
+
switch (geom2.type) {
|
|
26
|
+
case "Point":
|
|
27
|
+
return !compareCoords(geom1.coordinates, geom2.coordinates);
|
|
28
|
+
case "LineString":
|
|
29
|
+
return !isPointOnLine(geom2, geom1);
|
|
30
|
+
case "Polygon":
|
|
31
|
+
return !_booleanpointinpolygon.booleanPointInPolygon.call(void 0, geom1, geom2);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "LineString":
|
|
35
|
+
switch (geom2.type) {
|
|
36
|
+
case "Point":
|
|
37
|
+
return !isPointOnLine(geom1, geom2);
|
|
38
|
+
case "LineString":
|
|
39
|
+
return !isLineOnLine(geom1, geom2);
|
|
40
|
+
case "Polygon":
|
|
41
|
+
return !isLineInPoly(geom2, geom1);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case "Polygon":
|
|
45
|
+
switch (geom2.type) {
|
|
46
|
+
case "Point":
|
|
47
|
+
return !_booleanpointinpolygon.booleanPointInPolygon.call(void 0, geom2, geom1);
|
|
48
|
+
case "LineString":
|
|
49
|
+
return !isLineInPoly(geom1, geom2);
|
|
50
|
+
case "Polygon":
|
|
51
|
+
return !isPolyInPoly(geom2, geom1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
__name(disjoint, "disjoint");
|
|
57
|
+
function isPointOnLine(lineString, pt) {
|
|
58
|
+
for (let i = 0; i < lineString.coordinates.length - 1; i++) {
|
|
59
|
+
if (isPointOnLineSegment(
|
|
60
|
+
lineString.coordinates[i],
|
|
61
|
+
lineString.coordinates[i + 1],
|
|
62
|
+
pt.coordinates
|
|
63
|
+
)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
__name(isPointOnLine, "isPointOnLine");
|
|
70
|
+
function isLineOnLine(lineString1, lineString2) {
|
|
71
|
+
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString1, lineString2);
|
|
72
|
+
if (doLinesIntersect.features.length > 0) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
__name(isLineOnLine, "isLineOnLine");
|
|
78
|
+
function isLineInPoly(polygon, lineString) {
|
|
79
|
+
for (const coord of lineString.coordinates) {
|
|
80
|
+
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord, polygon)) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString, _polygontoline.polygonToLine.call(void 0, polygon));
|
|
85
|
+
if (doLinesIntersect.features.length > 0) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
__name(isLineInPoly, "isLineInPoly");
|
|
91
|
+
function isPolyInPoly(feature1, feature2) {
|
|
92
|
+
for (const coord1 of feature1.coordinates[0]) {
|
|
93
|
+
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord1, feature2)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const coord2 of feature2.coordinates[0]) {
|
|
98
|
+
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord2, feature1)) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0,
|
|
103
|
+
_polygontoline.polygonToLine.call(void 0, feature1),
|
|
104
|
+
_polygontoline.polygonToLine.call(void 0, feature2)
|
|
105
|
+
);
|
|
106
|
+
if (doLinesIntersect.features.length > 0) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
__name(isPolyInPoly, "isPolyInPoly");
|
|
112
|
+
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
|
|
113
|
+
const dxc = pt[0] - lineSegmentStart[0];
|
|
114
|
+
const dyc = pt[1] - lineSegmentStart[1];
|
|
115
|
+
const dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
116
|
+
const dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
117
|
+
const cross = dxc * dyl - dyc * dxl;
|
|
118
|
+
if (cross !== 0) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
122
|
+
if (dxl > 0) {
|
|
123
|
+
return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];
|
|
124
|
+
} else {
|
|
125
|
+
return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
126
|
+
}
|
|
127
|
+
} else if (dyl > 0) {
|
|
128
|
+
return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];
|
|
129
|
+
} else {
|
|
130
|
+
return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
__name(isPointOnLineSegment, "isPointOnLineSegment");
|
|
134
|
+
function compareCoords(pair1, pair2) {
|
|
135
|
+
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
136
|
+
}
|
|
137
|
+
__name(compareCoords, "compareCoords");
|
|
138
|
+
var turf_boolean_disjoint_default = booleanDisjoint;
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
exports.booleanDisjoint = booleanDisjoint; exports.default = turf_boolean_disjoint_default;
|
|
143
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;AACA,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAgB9B,SAAS,gBACP,UACA,UACS;AACT,MAAI,OAAO;AACX,cAAY,UAAU,CAAC,aAAa;AAClC,gBAAY,UAAU,CAAC,aAAa;AAClC,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AACA,aAAO,SAAS,SAAS,UAAU,SAAS,QAAQ;AAAA,IACtD,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAdS;AAwBT,SAAS,SAAS,OAAY,OAAY;AACxC,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iBAAO,CAAC,cAAc,MAAM,aAAa,MAAM,WAAW;AAAA,QAC5D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AG,CAAC,KAAK,GAAG,CAAC,KAAK,iBAAiB,CAAC;AAAA,EAClE;AACF;AAxBS;AAkCT,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAFS;AAKT,IAAO,gCAAQ","sourcesContent":["import { Feature, Geometry, LineString, Point, Polygon } from \"geojson\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { polygonToLine } from \"@turf/polygon-to-line\";\n\n/**\n * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.\n *\n * @name booleanDisjoint\n * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry\n * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry\n * @returns {boolean} true/false\n * @example\n * var point = turf.point([2, 2]);\n * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n *\n * turf.booleanDisjoint(line, point);\n * //=true\n */\nfunction booleanDisjoint(\n feature1: Feature<any> | Geometry,\n feature2: Feature<any> | Geometry\n): boolean {\n let bool = true;\n flattenEach(feature1, (flatten1) => {\n flattenEach(feature2, (flatten2) => {\n if (bool === false) {\n return false;\n }\n bool = disjoint(flatten1.geometry, flatten2.geometry);\n });\n });\n return bool;\n}\n\n/**\n * Disjoint operation for simple Geometries (Point/LineString/Polygon)\n *\n * @private\n * @param {Geometry<any>} geom1 GeoJSON Geometry\n * @param {Geometry<any>} geom2 GeoJSON Geometry\n * @returns {boolean} true/false\n */\nfunction disjoint(geom1: any, geom2: any) {\n switch (geom1.type) {\n case \"Point\":\n switch (geom2.type) {\n case \"Point\":\n return !compareCoords(geom1.coordinates, geom2.coordinates);\n case \"LineString\":\n return !isPointOnLine(geom2, geom1);\n case \"Polygon\":\n return !booleanPointInPolygon(geom1, geom2);\n }\n /* istanbul ignore next */\n break;\n case \"LineString\":\n switch (geom2.type) {\n case \"Point\":\n return !isPointOnLine(geom1, geom2);\n case \"LineString\":\n return !isLineOnLine(geom1, geom2);\n case \"Polygon\":\n return !isLineInPoly(geom2, geom1);\n }\n /* istanbul ignore next */\n break;\n case \"Polygon\":\n switch (geom2.type) {\n case \"Point\":\n return !booleanPointInPolygon(geom2, geom1);\n case \"LineString\":\n return !isLineInPoly(geom1, geom2);\n case \"Polygon\":\n return !isPolyInPoly(geom2, geom1);\n }\n }\n return false;\n}\n\n// http://stackoverflow.com/a/11908158/1979085\nfunction isPointOnLine(lineString: LineString, pt: Point) {\n for (let i = 0; i < lineString.coordinates.length - 1; i++) {\n if (\n isPointOnLineSegment(\n lineString.coordinates[i],\n lineString.coordinates[i + 1],\n pt.coordinates\n )\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isLineOnLine(lineString1: LineString, lineString2: LineString) {\n const doLinesIntersect = lineIntersect(lineString1, lineString2);\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isLineInPoly(polygon: Polygon, lineString: LineString) {\n for (const coord of lineString.coordinates) {\n if (booleanPointInPolygon(coord, polygon)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\n/**\n * Is Polygon (geom1) in Polygon (geom2)\n * Only takes into account outer rings\n * See http://stackoverflow.com/a/4833823/1979085\n *\n * @private\n * @param {Geometry|Feature<Polygon>} feature1 Polygon1\n * @param {Geometry|Feature<Polygon>} feature2 Polygon2\n * @returns {boolean} true/false\n */\nfunction isPolyInPoly(feature1: Polygon, feature2: Polygon) {\n for (const coord1 of feature1.coordinates[0]) {\n if (booleanPointInPolygon(coord1, feature2)) {\n return true;\n }\n }\n for (const coord2 of feature2.coordinates[0]) {\n if (booleanPointInPolygon(coord2, feature1)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(\n polygonToLine(feature1),\n polygonToLine(feature2)\n );\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isPointOnLineSegment(\n lineSegmentStart: number[],\n lineSegmentEnd: number[],\n pt: number[]\n) {\n const dxc = pt[0] - lineSegmentStart[0];\n const dyc = pt[1] - lineSegmentStart[1];\n const dxl = lineSegmentEnd[0] - lineSegmentStart[0];\n const dyl = lineSegmentEnd[1] - lineSegmentStart[1];\n const cross = dxc * dyl - dyc * dxl;\n if (cross !== 0) {\n return false;\n }\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n if (dxl > 0) {\n return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];\n } else {\n return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];\n }\n } else if (dyl > 0) {\n return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];\n } else {\n return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];\n }\n}\n\n/**\n * compareCoords\n *\n * @private\n * @param {Position} pair1 point [x,y]\n * @param {Position} pair2 point [x,y]\n * @returns {boolean} true/false if coord pairs match\n */\nfunction compareCoords(pair1: number[], pair2: number[]) {\n return pair1[0] === pair2[0] && pair1[1] === pair2[1];\n}\n\nexport { booleanDisjoint };\nexport default booleanDisjoint;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feature, Geometry } from
|
|
1
|
+
import { Feature, Geometry } from 'geojson';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
|
|
4
5
|
*
|
|
@@ -14,4 +15,5 @@ import { Feature, Geometry } from "geojson";
|
|
|
14
15
|
* //=true
|
|
15
16
|
*/
|
|
16
17
|
declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
export { booleanDisjoint, booleanDisjoint as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Feature, Geometry } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
|
|
5
|
+
*
|
|
6
|
+
* @name booleanDisjoint
|
|
7
|
+
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
8
|
+
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
9
|
+
* @returns {boolean} true/false
|
|
10
|
+
* @example
|
|
11
|
+
* var point = turf.point([2, 2]);
|
|
12
|
+
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
13
|
+
*
|
|
14
|
+
* turf.booleanDisjoint(line, point);
|
|
15
|
+
* //=true
|
|
16
|
+
*/
|
|
17
|
+
declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
|
|
18
|
+
|
|
19
|
+
export { booleanDisjoint, booleanDisjoint as default };
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
|
|
6
|
+
import { lineIntersect } from "@turf/line-intersect";
|
|
7
|
+
import { flattenEach } from "@turf/meta";
|
|
8
|
+
import { polygonToLine } from "@turf/polygon-to-line";
|
|
9
|
+
function booleanDisjoint(feature1, feature2) {
|
|
10
|
+
let bool = true;
|
|
11
|
+
flattenEach(feature1, (flatten1) => {
|
|
12
|
+
flattenEach(feature2, (flatten2) => {
|
|
13
|
+
if (bool === false) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
bool = disjoint(flatten1.geometry, flatten2.geometry);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
return bool;
|
|
20
|
+
}
|
|
21
|
+
__name(booleanDisjoint, "booleanDisjoint");
|
|
22
|
+
function disjoint(geom1, geom2) {
|
|
23
|
+
switch (geom1.type) {
|
|
24
|
+
case "Point":
|
|
25
|
+
switch (geom2.type) {
|
|
26
|
+
case "Point":
|
|
27
|
+
return !compareCoords(geom1.coordinates, geom2.coordinates);
|
|
28
|
+
case "LineString":
|
|
29
|
+
return !isPointOnLine(geom2, geom1);
|
|
30
|
+
case "Polygon":
|
|
31
|
+
return !booleanPointInPolygon(geom1, geom2);
|
|
32
|
+
}
|
|
33
|
+
break;
|
|
34
|
+
case "LineString":
|
|
35
|
+
switch (geom2.type) {
|
|
36
|
+
case "Point":
|
|
37
|
+
return !isPointOnLine(geom1, geom2);
|
|
38
|
+
case "LineString":
|
|
39
|
+
return !isLineOnLine(geom1, geom2);
|
|
40
|
+
case "Polygon":
|
|
41
|
+
return !isLineInPoly(geom2, geom1);
|
|
42
|
+
}
|
|
43
|
+
break;
|
|
44
|
+
case "Polygon":
|
|
45
|
+
switch (geom2.type) {
|
|
46
|
+
case "Point":
|
|
47
|
+
return !booleanPointInPolygon(geom2, geom1);
|
|
48
|
+
case "LineString":
|
|
49
|
+
return !isLineInPoly(geom1, geom2);
|
|
50
|
+
case "Polygon":
|
|
51
|
+
return !isPolyInPoly(geom2, geom1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
__name(disjoint, "disjoint");
|
|
57
|
+
function isPointOnLine(lineString, pt) {
|
|
58
|
+
for (let i = 0; i < lineString.coordinates.length - 1; i++) {
|
|
59
|
+
if (isPointOnLineSegment(
|
|
60
|
+
lineString.coordinates[i],
|
|
61
|
+
lineString.coordinates[i + 1],
|
|
62
|
+
pt.coordinates
|
|
63
|
+
)) {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
__name(isPointOnLine, "isPointOnLine");
|
|
70
|
+
function isLineOnLine(lineString1, lineString2) {
|
|
71
|
+
const doLinesIntersect = lineIntersect(lineString1, lineString2);
|
|
72
|
+
if (doLinesIntersect.features.length > 0) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
__name(isLineOnLine, "isLineOnLine");
|
|
78
|
+
function isLineInPoly(polygon, lineString) {
|
|
79
|
+
for (const coord of lineString.coordinates) {
|
|
80
|
+
if (booleanPointInPolygon(coord, polygon)) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
|
|
85
|
+
if (doLinesIntersect.features.length > 0) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
__name(isLineInPoly, "isLineInPoly");
|
|
91
|
+
function isPolyInPoly(feature1, feature2) {
|
|
92
|
+
for (const coord1 of feature1.coordinates[0]) {
|
|
93
|
+
if (booleanPointInPolygon(coord1, feature2)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
for (const coord2 of feature2.coordinates[0]) {
|
|
98
|
+
if (booleanPointInPolygon(coord2, feature1)) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const doLinesIntersect = lineIntersect(
|
|
103
|
+
polygonToLine(feature1),
|
|
104
|
+
polygonToLine(feature2)
|
|
105
|
+
);
|
|
106
|
+
if (doLinesIntersect.features.length > 0) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
__name(isPolyInPoly, "isPolyInPoly");
|
|
112
|
+
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
|
|
113
|
+
const dxc = pt[0] - lineSegmentStart[0];
|
|
114
|
+
const dyc = pt[1] - lineSegmentStart[1];
|
|
115
|
+
const dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
116
|
+
const dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
117
|
+
const cross = dxc * dyl - dyc * dxl;
|
|
118
|
+
if (cross !== 0) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
122
|
+
if (dxl > 0) {
|
|
123
|
+
return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];
|
|
124
|
+
} else {
|
|
125
|
+
return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
126
|
+
}
|
|
127
|
+
} else if (dyl > 0) {
|
|
128
|
+
return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];
|
|
129
|
+
} else {
|
|
130
|
+
return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
__name(isPointOnLineSegment, "isPointOnLineSegment");
|
|
134
|
+
function compareCoords(pair1, pair2) {
|
|
135
|
+
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
136
|
+
}
|
|
137
|
+
__name(compareCoords, "compareCoords");
|
|
138
|
+
var turf_boolean_disjoint_default = booleanDisjoint;
|
|
139
|
+
export {
|
|
140
|
+
booleanDisjoint,
|
|
141
|
+
turf_boolean_disjoint_default as default
|
|
142
|
+
};
|
|
143
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, Geometry, LineString, Point, Polygon } from \"geojson\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { polygonToLine } from \"@turf/polygon-to-line\";\n\n/**\n * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.\n *\n * @name booleanDisjoint\n * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry\n * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry\n * @returns {boolean} true/false\n * @example\n * var point = turf.point([2, 2]);\n * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n *\n * turf.booleanDisjoint(line, point);\n * //=true\n */\nfunction booleanDisjoint(\n feature1: Feature<any> | Geometry,\n feature2: Feature<any> | Geometry\n): boolean {\n let bool = true;\n flattenEach(feature1, (flatten1) => {\n flattenEach(feature2, (flatten2) => {\n if (bool === false) {\n return false;\n }\n bool = disjoint(flatten1.geometry, flatten2.geometry);\n });\n });\n return bool;\n}\n\n/**\n * Disjoint operation for simple Geometries (Point/LineString/Polygon)\n *\n * @private\n * @param {Geometry<any>} geom1 GeoJSON Geometry\n * @param {Geometry<any>} geom2 GeoJSON Geometry\n * @returns {boolean} true/false\n */\nfunction disjoint(geom1: any, geom2: any) {\n switch (geom1.type) {\n case \"Point\":\n switch (geom2.type) {\n case \"Point\":\n return !compareCoords(geom1.coordinates, geom2.coordinates);\n case \"LineString\":\n return !isPointOnLine(geom2, geom1);\n case \"Polygon\":\n return !booleanPointInPolygon(geom1, geom2);\n }\n /* istanbul ignore next */\n break;\n case \"LineString\":\n switch (geom2.type) {\n case \"Point\":\n return !isPointOnLine(geom1, geom2);\n case \"LineString\":\n return !isLineOnLine(geom1, geom2);\n case \"Polygon\":\n return !isLineInPoly(geom2, geom1);\n }\n /* istanbul ignore next */\n break;\n case \"Polygon\":\n switch (geom2.type) {\n case \"Point\":\n return !booleanPointInPolygon(geom2, geom1);\n case \"LineString\":\n return !isLineInPoly(geom1, geom2);\n case \"Polygon\":\n return !isPolyInPoly(geom2, geom1);\n }\n }\n return false;\n}\n\n// http://stackoverflow.com/a/11908158/1979085\nfunction isPointOnLine(lineString: LineString, pt: Point) {\n for (let i = 0; i < lineString.coordinates.length - 1; i++) {\n if (\n isPointOnLineSegment(\n lineString.coordinates[i],\n lineString.coordinates[i + 1],\n pt.coordinates\n )\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isLineOnLine(lineString1: LineString, lineString2: LineString) {\n const doLinesIntersect = lineIntersect(lineString1, lineString2);\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isLineInPoly(polygon: Polygon, lineString: LineString) {\n for (const coord of lineString.coordinates) {\n if (booleanPointInPolygon(coord, polygon)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\n/**\n * Is Polygon (geom1) in Polygon (geom2)\n * Only takes into account outer rings\n * See http://stackoverflow.com/a/4833823/1979085\n *\n * @private\n * @param {Geometry|Feature<Polygon>} feature1 Polygon1\n * @param {Geometry|Feature<Polygon>} feature2 Polygon2\n * @returns {boolean} true/false\n */\nfunction isPolyInPoly(feature1: Polygon, feature2: Polygon) {\n for (const coord1 of feature1.coordinates[0]) {\n if (booleanPointInPolygon(coord1, feature2)) {\n return true;\n }\n }\n for (const coord2 of feature2.coordinates[0]) {\n if (booleanPointInPolygon(coord2, feature1)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(\n polygonToLine(feature1),\n polygonToLine(feature2)\n );\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isPointOnLineSegment(\n lineSegmentStart: number[],\n lineSegmentEnd: number[],\n pt: number[]\n) {\n const dxc = pt[0] - lineSegmentStart[0];\n const dyc = pt[1] - lineSegmentStart[1];\n const dxl = lineSegmentEnd[0] - lineSegmentStart[0];\n const dyl = lineSegmentEnd[1] - lineSegmentStart[1];\n const cross = dxc * dyl - dyc * dxl;\n if (cross !== 0) {\n return false;\n }\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n if (dxl > 0) {\n return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];\n } else {\n return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];\n }\n } else if (dyl > 0) {\n return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];\n } else {\n return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];\n }\n}\n\n/**\n * compareCoords\n *\n * @private\n * @param {Position} pair1 point [x,y]\n * @param {Position} pair2 point [x,y]\n * @returns {boolean} true/false if coord pairs match\n */\nfunction compareCoords(pair1: number[], pair2: number[]) {\n return pair1[0] === pair2[0] && pair1[1] === pair2[1];\n}\n\nexport { booleanDisjoint };\nexport default booleanDisjoint;\n"],"mappings":";;;;AACA,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAgB9B,SAAS,gBACP,UACA,UACS;AACT,MAAI,OAAO;AACX,cAAY,UAAU,CAAC,aAAa;AAClC,gBAAY,UAAU,CAAC,aAAa;AAClC,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AACA,aAAO,SAAS,SAAS,UAAU,SAAS,QAAQ;AAAA,IACtD,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAdS;AAwBT,SAAS,SAAS,OAAY,OAAY;AACxC,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iBAAO,CAAC,cAAc,MAAM,aAAa,MAAM,WAAW;AAAA,QAC5D,KAAK;AACH,iBAAO,CAAC,cAAc,OAAO,KAAK;AAAA,QACpC,KAAK;AACH,iBAAO,CAAC,sBAAsB,OAAO,KAAK;AAAA,MAC9C;AAEA;AAAA,IACF,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iBAAO,CAAC,cAAc,OAAO,KAAK;AAAA,QACpC,KAAK;AACH,iBAAO,CAAC,aAAa,OAAO,KAAK;AAAA,QACnC,KAAK;AACH,iBAAO,CAAC,aAAa,OAAO,KAAK;AAAA,MACrC;AAEA;AAAA,IACF,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB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4
|
"description": "turf boolean-disjoint module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -26,48 +26,53 @@
|
|
|
26
26
|
"boolean",
|
|
27
27
|
"de-9im"
|
|
28
28
|
],
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"main": "dist/cjs/index.cjs",
|
|
31
|
+
"module": "dist/esm/index.mjs",
|
|
32
|
+
"types": "dist/cjs/index.d.ts",
|
|
31
33
|
"exports": {
|
|
32
34
|
"./package.json": "./package.json",
|
|
33
35
|
".": {
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./dist/esm/index.d.mts",
|
|
38
|
+
"default": "./dist/esm/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/cjs/index.d.ts",
|
|
42
|
+
"default": "./dist/cjs/index.cjs"
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
45
|
},
|
|
39
|
-
"types": "dist/js/index.d.ts",
|
|
40
46
|
"sideEffects": false,
|
|
41
47
|
"files": [
|
|
42
48
|
"dist"
|
|
43
49
|
],
|
|
44
50
|
"scripts": {
|
|
45
|
-
"bench": "tsx bench.
|
|
46
|
-
"build": "
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test": "npm-run-all test:*",
|
|
51
|
-
"test:tape": "tsx test.js"
|
|
51
|
+
"bench": "tsx bench.ts",
|
|
52
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
53
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
54
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
55
|
+
"test:tape": "tsx test.ts"
|
|
52
56
|
},
|
|
53
57
|
"devDependencies": {
|
|
54
|
-
"@types/
|
|
55
|
-
"
|
|
58
|
+
"@types/benchmark": "^2.1.5",
|
|
59
|
+
"@types/tape": "^4.2.32",
|
|
60
|
+
"benchmark": "^2.1.4",
|
|
56
61
|
"boolean-shapely": "*",
|
|
57
|
-
"load-json-file": "
|
|
58
|
-
"npm-run-all": "
|
|
59
|
-
"tape": "
|
|
60
|
-
"
|
|
61
|
-
"tsx": "
|
|
62
|
-
"typescript": "
|
|
62
|
+
"load-json-file": "^7.0.1",
|
|
63
|
+
"npm-run-all": "^4.1.5",
|
|
64
|
+
"tape": "^5.7.2",
|
|
65
|
+
"tsup": "^8.0.1",
|
|
66
|
+
"tsx": "^4.6.2",
|
|
67
|
+
"typescript": "^5.2.2"
|
|
63
68
|
},
|
|
64
69
|
"dependencies": {
|
|
65
|
-
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.
|
|
66
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
67
|
-
"@turf/line-intersect": "^7.0.0-alpha.
|
|
68
|
-
"@turf/meta": "^7.0.0-alpha.
|
|
69
|
-
"@turf/polygon-to-line": "^7.0.0-alpha.
|
|
70
|
-
"tslib": "^2.
|
|
70
|
+
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.110+1411d63a7",
|
|
71
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
72
|
+
"@turf/line-intersect": "^7.0.0-alpha.110+1411d63a7",
|
|
73
|
+
"@turf/meta": "^7.0.0-alpha.110+1411d63a7",
|
|
74
|
+
"@turf/polygon-to-line": "^7.0.0-alpha.110+1411d63a7",
|
|
75
|
+
"tslib": "^2.6.2"
|
|
71
76
|
},
|
|
72
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
73
78
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
2
|
-
import lineIntersect from "@turf/line-intersect";
|
|
3
|
-
import { flattenEach } from "@turf/meta";
|
|
4
|
-
import polygonToLine from "@turf/polygon-to-line";
|
|
5
|
-
/**
|
|
6
|
-
* Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
|
|
7
|
-
*
|
|
8
|
-
* @name booleanDisjoint
|
|
9
|
-
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
10
|
-
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
11
|
-
* @returns {boolean} true/false
|
|
12
|
-
* @example
|
|
13
|
-
* var point = turf.point([2, 2]);
|
|
14
|
-
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
15
|
-
*
|
|
16
|
-
* turf.booleanDisjoint(line, point);
|
|
17
|
-
* //=true
|
|
18
|
-
*/
|
|
19
|
-
function booleanDisjoint(feature1, feature2) {
|
|
20
|
-
let bool = true;
|
|
21
|
-
flattenEach(feature1, (flatten1) => {
|
|
22
|
-
flattenEach(feature2, (flatten2) => {
|
|
23
|
-
if (bool === false) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
bool = disjoint(flatten1.geometry, flatten2.geometry);
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
return bool;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Disjoint operation for simple Geometries (Point/LineString/Polygon)
|
|
33
|
-
*
|
|
34
|
-
* @private
|
|
35
|
-
* @param {Geometry<any>} geom1 GeoJSON Geometry
|
|
36
|
-
* @param {Geometry<any>} geom2 GeoJSON Geometry
|
|
37
|
-
* @returns {boolean} true/false
|
|
38
|
-
*/
|
|
39
|
-
function disjoint(geom1, geom2) {
|
|
40
|
-
switch (geom1.type) {
|
|
41
|
-
case "Point":
|
|
42
|
-
switch (geom2.type) {
|
|
43
|
-
case "Point":
|
|
44
|
-
return !compareCoords(geom1.coordinates, geom2.coordinates);
|
|
45
|
-
case "LineString":
|
|
46
|
-
return !isPointOnLine(geom2, geom1);
|
|
47
|
-
case "Polygon":
|
|
48
|
-
return !booleanPointInPolygon(geom1, geom2);
|
|
49
|
-
}
|
|
50
|
-
/* istanbul ignore next */
|
|
51
|
-
break;
|
|
52
|
-
case "LineString":
|
|
53
|
-
switch (geom2.type) {
|
|
54
|
-
case "Point":
|
|
55
|
-
return !isPointOnLine(geom1, geom2);
|
|
56
|
-
case "LineString":
|
|
57
|
-
return !isLineOnLine(geom1, geom2);
|
|
58
|
-
case "Polygon":
|
|
59
|
-
return !isLineInPoly(geom2, geom1);
|
|
60
|
-
}
|
|
61
|
-
/* istanbul ignore next */
|
|
62
|
-
break;
|
|
63
|
-
case "Polygon":
|
|
64
|
-
switch (geom2.type) {
|
|
65
|
-
case "Point":
|
|
66
|
-
return !booleanPointInPolygon(geom2, geom1);
|
|
67
|
-
case "LineString":
|
|
68
|
-
return !isLineInPoly(geom1, geom2);
|
|
69
|
-
case "Polygon":
|
|
70
|
-
return !isPolyInPoly(geom2, geom1);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
// http://stackoverflow.com/a/11908158/1979085
|
|
76
|
-
function isPointOnLine(lineString, pt) {
|
|
77
|
-
for (let i = 0; i < lineString.coordinates.length - 1; i++) {
|
|
78
|
-
if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], pt.coordinates)) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
function isLineOnLine(lineString1, lineString2) {
|
|
85
|
-
const doLinesIntersect = lineIntersect(lineString1, lineString2);
|
|
86
|
-
if (doLinesIntersect.features.length > 0) {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
function isLineInPoly(polygon, lineString) {
|
|
92
|
-
for (const coord of lineString.coordinates) {
|
|
93
|
-
if (booleanPointInPolygon(coord, polygon)) {
|
|
94
|
-
return true;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
|
|
98
|
-
if (doLinesIntersect.features.length > 0) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Is Polygon (geom1) in Polygon (geom2)
|
|
105
|
-
* Only takes into account outer rings
|
|
106
|
-
* See http://stackoverflow.com/a/4833823/1979085
|
|
107
|
-
*
|
|
108
|
-
* @private
|
|
109
|
-
* @param {Geometry|Feature<Polygon>} feature1 Polygon1
|
|
110
|
-
* @param {Geometry|Feature<Polygon>} feature2 Polygon2
|
|
111
|
-
* @returns {boolean} true/false
|
|
112
|
-
*/
|
|
113
|
-
function isPolyInPoly(feature1, feature2) {
|
|
114
|
-
for (const coord1 of feature1.coordinates[0]) {
|
|
115
|
-
if (booleanPointInPolygon(coord1, feature2)) {
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
for (const coord2 of feature2.coordinates[0]) {
|
|
120
|
-
if (booleanPointInPolygon(coord2, feature1)) {
|
|
121
|
-
return true;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const doLinesIntersect = lineIntersect(polygonToLine(feature1), polygonToLine(feature2));
|
|
125
|
-
if (doLinesIntersect.features.length > 0) {
|
|
126
|
-
return true;
|
|
127
|
-
}
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
|
|
131
|
-
const dxc = pt[0] - lineSegmentStart[0];
|
|
132
|
-
const dyc = pt[1] - lineSegmentStart[1];
|
|
133
|
-
const dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
134
|
-
const dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
135
|
-
const cross = dxc * dyl - dyc * dxl;
|
|
136
|
-
if (cross !== 0) {
|
|
137
|
-
return false;
|
|
138
|
-
}
|
|
139
|
-
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
140
|
-
if (dxl > 0) {
|
|
141
|
-
return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
else if (dyl > 0) {
|
|
148
|
-
return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];
|
|
149
|
-
}
|
|
150
|
-
else {
|
|
151
|
-
return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* compareCoords
|
|
156
|
-
*
|
|
157
|
-
* @private
|
|
158
|
-
* @param {Position} pair1 point [x,y]
|
|
159
|
-
* @param {Position} pair2 point [x,y]
|
|
160
|
-
* @returns {boolean} true/false if coord pairs match
|
|
161
|
-
*/
|
|
162
|
-
function compareCoords(pair1, pair2) {
|
|
163
|
-
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
164
|
-
}
|
|
165
|
-
export default booleanDisjoint;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const boolean_point_in_polygon_1 = tslib_1.__importDefault(require("@turf/boolean-point-in-polygon"));
|
|
5
|
-
const line_intersect_1 = tslib_1.__importDefault(require("@turf/line-intersect"));
|
|
6
|
-
const meta_1 = require("@turf/meta");
|
|
7
|
-
const polygon_to_line_1 = tslib_1.__importDefault(require("@turf/polygon-to-line"));
|
|
8
|
-
/**
|
|
9
|
-
* Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.
|
|
10
|
-
*
|
|
11
|
-
* @name booleanDisjoint
|
|
12
|
-
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
13
|
-
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
14
|
-
* @returns {boolean} true/false
|
|
15
|
-
* @example
|
|
16
|
-
* var point = turf.point([2, 2]);
|
|
17
|
-
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
18
|
-
*
|
|
19
|
-
* turf.booleanDisjoint(line, point);
|
|
20
|
-
* //=true
|
|
21
|
-
*/
|
|
22
|
-
function booleanDisjoint(feature1, feature2) {
|
|
23
|
-
let bool = true;
|
|
24
|
-
meta_1.flattenEach(feature1, (flatten1) => {
|
|
25
|
-
meta_1.flattenEach(feature2, (flatten2) => {
|
|
26
|
-
if (bool === false) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
bool = disjoint(flatten1.geometry, flatten2.geometry);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
return bool;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Disjoint operation for simple Geometries (Point/LineString/Polygon)
|
|
36
|
-
*
|
|
37
|
-
* @private
|
|
38
|
-
* @param {Geometry<any>} geom1 GeoJSON Geometry
|
|
39
|
-
* @param {Geometry<any>} geom2 GeoJSON Geometry
|
|
40
|
-
* @returns {boolean} true/false
|
|
41
|
-
*/
|
|
42
|
-
function disjoint(geom1, geom2) {
|
|
43
|
-
switch (geom1.type) {
|
|
44
|
-
case "Point":
|
|
45
|
-
switch (geom2.type) {
|
|
46
|
-
case "Point":
|
|
47
|
-
return !compareCoords(geom1.coordinates, geom2.coordinates);
|
|
48
|
-
case "LineString":
|
|
49
|
-
return !isPointOnLine(geom2, geom1);
|
|
50
|
-
case "Polygon":
|
|
51
|
-
return !boolean_point_in_polygon_1.default(geom1, geom2);
|
|
52
|
-
}
|
|
53
|
-
/* istanbul ignore next */
|
|
54
|
-
break;
|
|
55
|
-
case "LineString":
|
|
56
|
-
switch (geom2.type) {
|
|
57
|
-
case "Point":
|
|
58
|
-
return !isPointOnLine(geom1, geom2);
|
|
59
|
-
case "LineString":
|
|
60
|
-
return !isLineOnLine(geom1, geom2);
|
|
61
|
-
case "Polygon":
|
|
62
|
-
return !isLineInPoly(geom2, geom1);
|
|
63
|
-
}
|
|
64
|
-
/* istanbul ignore next */
|
|
65
|
-
break;
|
|
66
|
-
case "Polygon":
|
|
67
|
-
switch (geom2.type) {
|
|
68
|
-
case "Point":
|
|
69
|
-
return !boolean_point_in_polygon_1.default(geom2, geom1);
|
|
70
|
-
case "LineString":
|
|
71
|
-
return !isLineInPoly(geom1, geom2);
|
|
72
|
-
case "Polygon":
|
|
73
|
-
return !isPolyInPoly(geom2, geom1);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
// http://stackoverflow.com/a/11908158/1979085
|
|
79
|
-
function isPointOnLine(lineString, pt) {
|
|
80
|
-
for (let i = 0; i < lineString.coordinates.length - 1; i++) {
|
|
81
|
-
if (isPointOnLineSegment(lineString.coordinates[i], lineString.coordinates[i + 1], pt.coordinates)) {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
function isLineOnLine(lineString1, lineString2) {
|
|
88
|
-
const doLinesIntersect = line_intersect_1.default(lineString1, lineString2);
|
|
89
|
-
if (doLinesIntersect.features.length > 0) {
|
|
90
|
-
return true;
|
|
91
|
-
}
|
|
92
|
-
return false;
|
|
93
|
-
}
|
|
94
|
-
function isLineInPoly(polygon, lineString) {
|
|
95
|
-
for (const coord of lineString.coordinates) {
|
|
96
|
-
if (boolean_point_in_polygon_1.default(coord, polygon)) {
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
const doLinesIntersect = line_intersect_1.default(lineString, polygon_to_line_1.default(polygon));
|
|
101
|
-
if (doLinesIntersect.features.length > 0) {
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Is Polygon (geom1) in Polygon (geom2)
|
|
108
|
-
* Only takes into account outer rings
|
|
109
|
-
* See http://stackoverflow.com/a/4833823/1979085
|
|
110
|
-
*
|
|
111
|
-
* @private
|
|
112
|
-
* @param {Geometry|Feature<Polygon>} feature1 Polygon1
|
|
113
|
-
* @param {Geometry|Feature<Polygon>} feature2 Polygon2
|
|
114
|
-
* @returns {boolean} true/false
|
|
115
|
-
*/
|
|
116
|
-
function isPolyInPoly(feature1, feature2) {
|
|
117
|
-
for (const coord1 of feature1.coordinates[0]) {
|
|
118
|
-
if (boolean_point_in_polygon_1.default(coord1, feature2)) {
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
for (const coord2 of feature2.coordinates[0]) {
|
|
123
|
-
if (boolean_point_in_polygon_1.default(coord2, feature1)) {
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
const doLinesIntersect = line_intersect_1.default(polygon_to_line_1.default(feature1), polygon_to_line_1.default(feature2));
|
|
128
|
-
if (doLinesIntersect.features.length > 0) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
|
|
134
|
-
const dxc = pt[0] - lineSegmentStart[0];
|
|
135
|
-
const dyc = pt[1] - lineSegmentStart[1];
|
|
136
|
-
const dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
137
|
-
const dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
138
|
-
const cross = dxc * dyl - dyc * dxl;
|
|
139
|
-
if (cross !== 0) {
|
|
140
|
-
return false;
|
|
141
|
-
}
|
|
142
|
-
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
143
|
-
if (dxl > 0) {
|
|
144
|
-
return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
else if (dyl > 0) {
|
|
151
|
-
return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* compareCoords
|
|
159
|
-
*
|
|
160
|
-
* @private
|
|
161
|
-
* @param {Position} pair1 point [x,y]
|
|
162
|
-
* @param {Position} pair2 point [x,y]
|
|
163
|
-
* @returns {boolean} true/false if coord pairs match
|
|
164
|
-
*/
|
|
165
|
-
function compareCoords(pair1, pair2) {
|
|
166
|
-
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
167
|
-
}
|
|
168
|
-
exports.default = booleanDisjoint;
|