@turf/boolean-disjoint 7.1.0-alpha.7 → 7.1.0
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 +7 -2
- package/dist/cjs/index.cjs +24 -13
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -2
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +24 -13
- package/dist/esm/index.js.map +1 -1
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -10,6 +10,9 @@ Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an
|
|
|
10
10
|
|
|
11
11
|
* `feature1` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry
|
|
12
12
|
* `feature2` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry
|
|
13
|
+
* `options` **[Object][3]** Optional parameters (optional, default `{}`)
|
|
14
|
+
|
|
15
|
+
* `options.ignoreSelfIntersections` **[boolean][4]** ignores self-intersections on input features (optional, default `false`)
|
|
13
16
|
|
|
14
17
|
### Examples
|
|
15
18
|
|
|
@@ -21,13 +24,15 @@ turf.booleanDisjoint(line, point);
|
|
|
21
24
|
//=true
|
|
22
25
|
```
|
|
23
26
|
|
|
24
|
-
Returns **[boolean][
|
|
27
|
+
Returns **[boolean][4]** true if the intersection is an empty set, false otherwise
|
|
25
28
|
|
|
26
29
|
[1]: https://tools.ietf.org/html/rfc7946#section-3.1
|
|
27
30
|
|
|
28
31
|
[2]: https://tools.ietf.org/html/rfc7946#section-3.2
|
|
29
32
|
|
|
30
|
-
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/
|
|
33
|
+
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
|
|
34
|
+
|
|
35
|
+
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
31
36
|
|
|
32
37
|
<!-- 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. -->
|
|
33
38
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -3,19 +3,25 @@ var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
|
|
|
3
3
|
var _lineintersect = require('@turf/line-intersect');
|
|
4
4
|
var _meta = require('@turf/meta');
|
|
5
5
|
var _polygontoline = require('@turf/polygon-to-line');
|
|
6
|
-
function booleanDisjoint(feature1, feature2) {
|
|
6
|
+
function booleanDisjoint(feature1, feature2, options = {}) {
|
|
7
|
+
var _a;
|
|
8
|
+
const ignoreSelfIntersections = (_a = options.ignoreSelfIntersections) != null ? _a : false;
|
|
7
9
|
let bool = true;
|
|
8
10
|
_meta.flattenEach.call(void 0, feature1, (flatten1) => {
|
|
9
11
|
_meta.flattenEach.call(void 0, feature2, (flatten2) => {
|
|
10
12
|
if (bool === false) {
|
|
11
13
|
return false;
|
|
12
14
|
}
|
|
13
|
-
bool = disjoint(
|
|
15
|
+
bool = disjoint(
|
|
16
|
+
flatten1.geometry,
|
|
17
|
+
flatten2.geometry,
|
|
18
|
+
ignoreSelfIntersections
|
|
19
|
+
);
|
|
14
20
|
});
|
|
15
21
|
});
|
|
16
22
|
return bool;
|
|
17
23
|
}
|
|
18
|
-
function disjoint(geom1, geom2) {
|
|
24
|
+
function disjoint(geom1, geom2, ignoreSelfIntersections) {
|
|
19
25
|
switch (geom1.type) {
|
|
20
26
|
case "Point":
|
|
21
27
|
switch (geom2.type) {
|
|
@@ -32,9 +38,9 @@ function disjoint(geom1, geom2) {
|
|
|
32
38
|
case "Point":
|
|
33
39
|
return !isPointOnLine(geom1, geom2);
|
|
34
40
|
case "LineString":
|
|
35
|
-
return !isLineOnLine(geom1, geom2);
|
|
41
|
+
return !isLineOnLine(geom1, geom2, ignoreSelfIntersections);
|
|
36
42
|
case "Polygon":
|
|
37
|
-
return !isLineInPoly(geom2, geom1);
|
|
43
|
+
return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);
|
|
38
44
|
}
|
|
39
45
|
break;
|
|
40
46
|
case "Polygon":
|
|
@@ -42,9 +48,9 @@ function disjoint(geom1, geom2) {
|
|
|
42
48
|
case "Point":
|
|
43
49
|
return !_booleanpointinpolygon.booleanPointInPolygon.call(void 0, geom2, geom1);
|
|
44
50
|
case "LineString":
|
|
45
|
-
return !isLineInPoly(geom1, geom2);
|
|
51
|
+
return !isLineInPoly(geom1, geom2, ignoreSelfIntersections);
|
|
46
52
|
case "Polygon":
|
|
47
|
-
return !isPolyInPoly(geom2, geom1);
|
|
53
|
+
return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
return false;
|
|
@@ -61,26 +67,30 @@ function isPointOnLine(lineString, pt) {
|
|
|
61
67
|
}
|
|
62
68
|
return false;
|
|
63
69
|
}
|
|
64
|
-
function isLineOnLine(lineString1, lineString2) {
|
|
65
|
-
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString1, lineString2
|
|
70
|
+
function isLineOnLine(lineString1, lineString2, ignoreSelfIntersections) {
|
|
71
|
+
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString1, lineString2, {
|
|
72
|
+
ignoreSelfIntersections
|
|
73
|
+
});
|
|
66
74
|
if (doLinesIntersect.features.length > 0) {
|
|
67
75
|
return true;
|
|
68
76
|
}
|
|
69
77
|
return false;
|
|
70
78
|
}
|
|
71
|
-
function isLineInPoly(polygon, lineString) {
|
|
79
|
+
function isLineInPoly(polygon, lineString, ignoreSelfIntersections) {
|
|
72
80
|
for (const coord of lineString.coordinates) {
|
|
73
81
|
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord, polygon)) {
|
|
74
82
|
return true;
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
|
-
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString, _polygontoline.polygonToLine.call(void 0, polygon)
|
|
85
|
+
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString, _polygontoline.polygonToLine.call(void 0, polygon), {
|
|
86
|
+
ignoreSelfIntersections
|
|
87
|
+
});
|
|
78
88
|
if (doLinesIntersect.features.length > 0) {
|
|
79
89
|
return true;
|
|
80
90
|
}
|
|
81
91
|
return false;
|
|
82
92
|
}
|
|
83
|
-
function isPolyInPoly(feature1, feature2) {
|
|
93
|
+
function isPolyInPoly(feature1, feature2, ignoreSelfIntersections) {
|
|
84
94
|
for (const coord1 of feature1.coordinates[0]) {
|
|
85
95
|
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord1, feature2)) {
|
|
86
96
|
return true;
|
|
@@ -93,7 +103,8 @@ function isPolyInPoly(feature1, feature2) {
|
|
|
93
103
|
}
|
|
94
104
|
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0,
|
|
95
105
|
_polygontoline.polygonToLine.call(void 0, feature1),
|
|
96
|
-
_polygontoline.polygonToLine.call(void 0, feature2)
|
|
106
|
+
_polygontoline.polygonToLine.call(void 0, feature2),
|
|
107
|
+
{ ignoreSelfIntersections }
|
|
97
108
|
);
|
|
98
109
|
if (doLinesIntersect.features.length > 0) {
|
|
99
110
|
return true;
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAQA,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAkB9B,SAAS,gBACP,UACA,UACA,UAEI,CAAC,GACI;AAnCX;AAoCE,QAAM,2BACJ,aAAQ,4BAAR,YAAmC;AAErC,MAAI,OAAO;AACX,cAAY,UAAU,CAAC,aAAa;AAClC,gBAAY,UAAU,CAAC,aAAa;AAClC,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,S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aAAO,iBAAiB,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,eAAe,CAAC;AAAA,IAClE,OAAO;AACL,aAAO,eAAe,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,iBAAiB,CAAC;AAAA,IAClE;AAAA,EACF,WAAW,MAAM,GAAG;AAClB,WAAO,iBAAiB,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,eAAe,CAAC;AAAA,EAClE,OAAO;AACL,WAAO,eAAe,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,iBAAiB,CAAC;AAAA,EAClE;AACF;AAUA,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAGA,IAAO,gCAAQ","sourcesContent":["import {\n Feature,\n Geometry,\n LineString,\n Point,\n Polygon,\n Position,\n} 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 * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features\n * @returns {boolean} true if the intersection is an empty set, false otherwise\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 options: {\n ignoreSelfIntersections?: boolean;\n } = {}\n): boolean {\n const ignoreSelfIntersections: boolean =\n options.ignoreSelfIntersections ?? false;\n\n let bool = true;\n flattenEach(feature1, (flatten1) => {\n flattenEach(feature2, (flatten2) => {\n if (bool === false) {\n return false;\n }\n bool = disjoint(\n flatten1.geometry,\n flatten2.geometry,\n ignoreSelfIntersections\n );\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 * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if disjoint, false otherwise\n */\nfunction disjoint(geom1: any, geom2: any, ignoreSelfIntersections: boolean) {\n switch (geom1.type) {\n case \"Point\":\n /* eslint-disable @typescript-eslint/no-unused-vars */\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, ignoreSelfIntersections);\n case \"Polygon\":\n return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);\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, ignoreSelfIntersections);\n case \"Polygon\":\n return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);\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(\n lineString1: LineString,\n lineString2: LineString,\n ignoreSelfIntersections: boolean\n) {\n const doLinesIntersect = lineIntersect(lineString1, lineString2, {\n ignoreSelfIntersections,\n });\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isLineInPoly(\n polygon: Polygon,\n lineString: LineString,\n ignoreSelfIntersections: boolean\n) {\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 ignoreSelfIntersections,\n });\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 * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if geom1 is in geom2, false otherwise\n */\nfunction isPolyInPoly(\n feature1: Polygon,\n feature2: Polygon,\n ignoreSelfIntersections: boolean\n) {\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 { ignoreSelfIntersections }\n );\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isPointOnLineSegment(\n lineSegmentStart: Position,\n lineSegmentEnd: Position,\n pt: Position\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 if coord pairs match, false otherwise\n */\nfunction compareCoords(pair1: Position, pair2: Position) {\n return pair1[0] === pair2[0] && pair1[1] === pair2[1];\n}\n\nexport { booleanDisjoint };\nexport default booleanDisjoint;\n"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -6,7 +6,9 @@ import { Feature, Geometry } from 'geojson';
|
|
|
6
6
|
* @name booleanDisjoint
|
|
7
7
|
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
8
8
|
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
9
|
-
* @
|
|
9
|
+
* @param {Object} [options={}] Optional parameters
|
|
10
|
+
* @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
|
|
11
|
+
* @returns {boolean} true if the intersection is an empty set, false otherwise
|
|
10
12
|
* @example
|
|
11
13
|
* var point = turf.point([2, 2]);
|
|
12
14
|
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
@@ -14,6 +16,8 @@ import { Feature, Geometry } from 'geojson';
|
|
|
14
16
|
* turf.booleanDisjoint(line, point);
|
|
15
17
|
* //=true
|
|
16
18
|
*/
|
|
17
|
-
declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry
|
|
19
|
+
declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry, options?: {
|
|
20
|
+
ignoreSelfIntersections?: boolean;
|
|
21
|
+
}): boolean;
|
|
18
22
|
|
|
19
23
|
export { booleanDisjoint, booleanDisjoint as default };
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -6,7 +6,9 @@ import { Feature, Geometry } from 'geojson';
|
|
|
6
6
|
* @name booleanDisjoint
|
|
7
7
|
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
8
8
|
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
9
|
-
* @
|
|
9
|
+
* @param {Object} [options={}] Optional parameters
|
|
10
|
+
* @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
|
|
11
|
+
* @returns {boolean} true if the intersection is an empty set, false otherwise
|
|
10
12
|
* @example
|
|
11
13
|
* var point = turf.point([2, 2]);
|
|
12
14
|
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
@@ -14,6 +16,8 @@ import { Feature, Geometry } from 'geojson';
|
|
|
14
16
|
* turf.booleanDisjoint(line, point);
|
|
15
17
|
* //=true
|
|
16
18
|
*/
|
|
17
|
-
declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry
|
|
19
|
+
declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry, options?: {
|
|
20
|
+
ignoreSelfIntersections?: boolean;
|
|
21
|
+
}): boolean;
|
|
18
22
|
|
|
19
23
|
export { booleanDisjoint, booleanDisjoint as default };
|
package/dist/esm/index.js
CHANGED
|
@@ -3,19 +3,25 @@ import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
|
|
|
3
3
|
import { lineIntersect } from "@turf/line-intersect";
|
|
4
4
|
import { flattenEach } from "@turf/meta";
|
|
5
5
|
import { polygonToLine } from "@turf/polygon-to-line";
|
|
6
|
-
function booleanDisjoint(feature1, feature2) {
|
|
6
|
+
function booleanDisjoint(feature1, feature2, options = {}) {
|
|
7
|
+
var _a;
|
|
8
|
+
const ignoreSelfIntersections = (_a = options.ignoreSelfIntersections) != null ? _a : false;
|
|
7
9
|
let bool = true;
|
|
8
10
|
flattenEach(feature1, (flatten1) => {
|
|
9
11
|
flattenEach(feature2, (flatten2) => {
|
|
10
12
|
if (bool === false) {
|
|
11
13
|
return false;
|
|
12
14
|
}
|
|
13
|
-
bool = disjoint(
|
|
15
|
+
bool = disjoint(
|
|
16
|
+
flatten1.geometry,
|
|
17
|
+
flatten2.geometry,
|
|
18
|
+
ignoreSelfIntersections
|
|
19
|
+
);
|
|
14
20
|
});
|
|
15
21
|
});
|
|
16
22
|
return bool;
|
|
17
23
|
}
|
|
18
|
-
function disjoint(geom1, geom2) {
|
|
24
|
+
function disjoint(geom1, geom2, ignoreSelfIntersections) {
|
|
19
25
|
switch (geom1.type) {
|
|
20
26
|
case "Point":
|
|
21
27
|
switch (geom2.type) {
|
|
@@ -32,9 +38,9 @@ function disjoint(geom1, geom2) {
|
|
|
32
38
|
case "Point":
|
|
33
39
|
return !isPointOnLine(geom1, geom2);
|
|
34
40
|
case "LineString":
|
|
35
|
-
return !isLineOnLine(geom1, geom2);
|
|
41
|
+
return !isLineOnLine(geom1, geom2, ignoreSelfIntersections);
|
|
36
42
|
case "Polygon":
|
|
37
|
-
return !isLineInPoly(geom2, geom1);
|
|
43
|
+
return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);
|
|
38
44
|
}
|
|
39
45
|
break;
|
|
40
46
|
case "Polygon":
|
|
@@ -42,9 +48,9 @@ function disjoint(geom1, geom2) {
|
|
|
42
48
|
case "Point":
|
|
43
49
|
return !booleanPointInPolygon(geom2, geom1);
|
|
44
50
|
case "LineString":
|
|
45
|
-
return !isLineInPoly(geom1, geom2);
|
|
51
|
+
return !isLineInPoly(geom1, geom2, ignoreSelfIntersections);
|
|
46
52
|
case "Polygon":
|
|
47
|
-
return !isPolyInPoly(geom2, geom1);
|
|
53
|
+
return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);
|
|
48
54
|
}
|
|
49
55
|
}
|
|
50
56
|
return false;
|
|
@@ -61,26 +67,30 @@ function isPointOnLine(lineString, pt) {
|
|
|
61
67
|
}
|
|
62
68
|
return false;
|
|
63
69
|
}
|
|
64
|
-
function isLineOnLine(lineString1, lineString2) {
|
|
65
|
-
const doLinesIntersect = lineIntersect(lineString1, lineString2
|
|
70
|
+
function isLineOnLine(lineString1, lineString2, ignoreSelfIntersections) {
|
|
71
|
+
const doLinesIntersect = lineIntersect(lineString1, lineString2, {
|
|
72
|
+
ignoreSelfIntersections
|
|
73
|
+
});
|
|
66
74
|
if (doLinesIntersect.features.length > 0) {
|
|
67
75
|
return true;
|
|
68
76
|
}
|
|
69
77
|
return false;
|
|
70
78
|
}
|
|
71
|
-
function isLineInPoly(polygon, lineString) {
|
|
79
|
+
function isLineInPoly(polygon, lineString, ignoreSelfIntersections) {
|
|
72
80
|
for (const coord of lineString.coordinates) {
|
|
73
81
|
if (booleanPointInPolygon(coord, polygon)) {
|
|
74
82
|
return true;
|
|
75
83
|
}
|
|
76
84
|
}
|
|
77
|
-
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon)
|
|
85
|
+
const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon), {
|
|
86
|
+
ignoreSelfIntersections
|
|
87
|
+
});
|
|
78
88
|
if (doLinesIntersect.features.length > 0) {
|
|
79
89
|
return true;
|
|
80
90
|
}
|
|
81
91
|
return false;
|
|
82
92
|
}
|
|
83
|
-
function isPolyInPoly(feature1, feature2) {
|
|
93
|
+
function isPolyInPoly(feature1, feature2, ignoreSelfIntersections) {
|
|
84
94
|
for (const coord1 of feature1.coordinates[0]) {
|
|
85
95
|
if (booleanPointInPolygon(coord1, feature2)) {
|
|
86
96
|
return true;
|
|
@@ -93,7 +103,8 @@ function isPolyInPoly(feature1, feature2) {
|
|
|
93
103
|
}
|
|
94
104
|
const doLinesIntersect = lineIntersect(
|
|
95
105
|
polygonToLine(feature1),
|
|
96
|
-
polygonToLine(feature2)
|
|
106
|
+
polygonToLine(feature2),
|
|
107
|
+
{ ignoreSelfIntersections }
|
|
97
108
|
);
|
|
98
109
|
if (doLinesIntersect.features.length > 0) {
|
|
99
110
|
return true;
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n Feature,\n Geometry,\n LineString,\n Point,\n Polygon,\n Position,\n} 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 * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features\n * @returns {boolean} true if the intersection is an empty set, false otherwise\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 options: {\n ignoreSelfIntersections?: boolean;\n } = {}\n): boolean {\n const ignoreSelfIntersections: boolean =\n options.ignoreSelfIntersections ?? false;\n\n let bool = true;\n flattenEach(feature1, (flatten1) => {\n flattenEach(feature2, (flatten2) => {\n if (bool === false) {\n return false;\n }\n bool = disjoint(\n flatten1.geometry,\n flatten2.geometry,\n ignoreSelfIntersections\n );\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 * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if disjoint, false otherwise\n */\nfunction disjoint(geom1: any, geom2: any, ignoreSelfIntersections: boolean) {\n switch (geom1.type) {\n case \"Point\":\n /* eslint-disable @typescript-eslint/no-unused-vars */\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, ignoreSelfIntersections);\n case \"Polygon\":\n return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);\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, ignoreSelfIntersections);\n case \"Polygon\":\n return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);\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(\n lineString1: LineString,\n lineString2: LineString,\n ignoreSelfIntersections: boolean\n) {\n const doLinesIntersect = lineIntersect(lineString1, lineString2, {\n ignoreSelfIntersections,\n });\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isLineInPoly(\n polygon: Polygon,\n lineString: LineString,\n ignoreSelfIntersections: boolean\n) {\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 ignoreSelfIntersections,\n });\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 * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if geom1 is in geom2, false otherwise\n */\nfunction isPolyInPoly(\n feature1: Polygon,\n feature2: Polygon,\n ignoreSelfIntersections: boolean\n) {\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 { ignoreSelfIntersections }\n );\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isPointOnLineSegment(\n lineSegmentStart: Position,\n lineSegmentEnd: Position,\n pt: Position\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 if coord pairs match, false otherwise\n */\nfunction compareCoords(pair1: Position, pair2: Position) {\n return pair1[0] === pair2[0] && pair1[1] === pair2[1];\n}\n\nexport { booleanDisjoint };\nexport default booleanDisjoint;\n"],"mappings":";AAQA,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAkB9B,SAAS,gBACP,UACA,UACA,UAEI,CAAC,GACI;AAnCX;AAoCE,QAAM,2BACJ,aAAQ,4BAAR,YAAmC;AAErC,MAAI,OAAO;AACX,cAAY,UAAU,CAAC,aAAa;AAClC,gBAAY,UAAU,CAAC,aAAa;AAClC,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,SAAS;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAWA,SAAS,SAAS,OAAY,OAAY,yBAAkC;AAC1E,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AAEH,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,OAAO,uBAAuB;AAAA,QAC5D,KAAK;AACH,iBAAO,CAAC,aAAa,OAAO,OAAO,uBAAuB;AAAA,MAC9D;AAEA;AAAA,IACF,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iB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0",
|
|
4
4
|
"description": "turf boolean-disjoint module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -67,12 +67,13 @@
|
|
|
67
67
|
"typescript": "^5.2.2"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@turf/boolean-point-in-polygon": "^7.1.0
|
|
71
|
-
"@turf/helpers": "^7.1.0
|
|
72
|
-
"@turf/line-intersect": "^7.1.0
|
|
73
|
-
"@turf/meta": "^7.1.0
|
|
74
|
-
"@turf/polygon-to-line": "^7.1.0
|
|
70
|
+
"@turf/boolean-point-in-polygon": "^7.1.0",
|
|
71
|
+
"@turf/helpers": "^7.1.0",
|
|
72
|
+
"@turf/line-intersect": "^7.1.0",
|
|
73
|
+
"@turf/meta": "^7.1.0",
|
|
74
|
+
"@turf/polygon-to-line": "^7.1.0",
|
|
75
|
+
"@types/geojson": "^7946.0.10",
|
|
75
76
|
"tslib": "^2.6.2"
|
|
76
77
|
},
|
|
77
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
|
|
78
79
|
}
|