@turf/boolean-crosses 7.0.0-alpha.2 → 7.0.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 +4 -9
- package/dist/cjs/index.cjs +150 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +24 -0
- package/dist/{js → esm}/index.d.ts +4 -2
- package/dist/esm/index.js +150 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +35 -30
- package/dist/es/index.js +0 -167
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -170
package/README.md
CHANGED
|
@@ -34,26 +34,21 @@ Returns **[boolean][3]** true/false
|
|
|
34
34
|
|
|
35
35
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
36
36
|
|
|
37
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
38
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
39
|
-
./scripts/generate-readmes in the turf project. -->
|
|
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. -->
|
|
40
38
|
|
|
41
39
|
---
|
|
42
40
|
|
|
43
|
-
This module is part of the [Turfjs project](
|
|
44
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
45
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
46
|
-
PRs and issues.
|
|
41
|
+
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.
|
|
47
42
|
|
|
48
43
|
### Installation
|
|
49
44
|
|
|
50
|
-
Install this module individually:
|
|
45
|
+
Install this single module individually:
|
|
51
46
|
|
|
52
47
|
```sh
|
|
53
48
|
$ npm install @turf/boolean-crosses
|
|
54
49
|
```
|
|
55
50
|
|
|
56
|
-
Or install the
|
|
51
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
57
52
|
|
|
58
53
|
```sh
|
|
59
54
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,150 @@
|
|
|
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 _lineintersect = require('@turf/line-intersect');
|
|
6
|
+
var _polygontoline = require('@turf/polygon-to-line');
|
|
7
|
+
var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
|
|
8
|
+
var _invariant = require('@turf/invariant');
|
|
9
|
+
var _helpers = require('@turf/helpers');
|
|
10
|
+
function booleanCrosses(feature1, feature2) {
|
|
11
|
+
var geom1 = _invariant.getGeom.call(void 0, feature1);
|
|
12
|
+
var geom2 = _invariant.getGeom.call(void 0, feature2);
|
|
13
|
+
var type1 = geom1.type;
|
|
14
|
+
var type2 = geom2.type;
|
|
15
|
+
switch (type1) {
|
|
16
|
+
case "MultiPoint":
|
|
17
|
+
switch (type2) {
|
|
18
|
+
case "LineString":
|
|
19
|
+
return doMultiPointAndLineStringCross(geom1, geom2);
|
|
20
|
+
case "Polygon":
|
|
21
|
+
return doesMultiPointCrossPoly(geom1, geom2);
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
24
|
+
}
|
|
25
|
+
case "LineString":
|
|
26
|
+
switch (type2) {
|
|
27
|
+
case "MultiPoint":
|
|
28
|
+
return doMultiPointAndLineStringCross(geom2, geom1);
|
|
29
|
+
case "LineString":
|
|
30
|
+
return doLineStringsCross(geom1, geom2);
|
|
31
|
+
case "Polygon":
|
|
32
|
+
return doLineStringAndPolygonCross(geom1, geom2);
|
|
33
|
+
default:
|
|
34
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
35
|
+
}
|
|
36
|
+
case "Polygon":
|
|
37
|
+
switch (type2) {
|
|
38
|
+
case "MultiPoint":
|
|
39
|
+
return doesMultiPointCrossPoly(geom2, geom1);
|
|
40
|
+
case "LineString":
|
|
41
|
+
return doLineStringAndPolygonCross(geom2, geom1);
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
44
|
+
}
|
|
45
|
+
default:
|
|
46
|
+
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
__name(booleanCrosses, "booleanCrosses");
|
|
50
|
+
function doMultiPointAndLineStringCross(multiPoint, lineString) {
|
|
51
|
+
var foundIntPoint = false;
|
|
52
|
+
var foundExtPoint = false;
|
|
53
|
+
var pointLength = multiPoint.coordinates.length;
|
|
54
|
+
var i = 0;
|
|
55
|
+
while (i < pointLength && !foundIntPoint && !foundExtPoint) {
|
|
56
|
+
for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) {
|
|
57
|
+
var incEndVertices = true;
|
|
58
|
+
if (i2 === 0 || i2 === lineString.coordinates.length - 2) {
|
|
59
|
+
incEndVertices = false;
|
|
60
|
+
}
|
|
61
|
+
if (isPointOnLineSegment(
|
|
62
|
+
lineString.coordinates[i2],
|
|
63
|
+
lineString.coordinates[i2 + 1],
|
|
64
|
+
multiPoint.coordinates[i],
|
|
65
|
+
incEndVertices
|
|
66
|
+
)) {
|
|
67
|
+
foundIntPoint = true;
|
|
68
|
+
} else {
|
|
69
|
+
foundExtPoint = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
return foundIntPoint && foundExtPoint;
|
|
75
|
+
}
|
|
76
|
+
__name(doMultiPointAndLineStringCross, "doMultiPointAndLineStringCross");
|
|
77
|
+
function doLineStringsCross(lineString1, lineString2) {
|
|
78
|
+
var doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString1, lineString2);
|
|
79
|
+
if (doLinesIntersect.features.length > 0) {
|
|
80
|
+
for (var i = 0; i < lineString1.coordinates.length - 1; i++) {
|
|
81
|
+
for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {
|
|
82
|
+
var incEndVertices = true;
|
|
83
|
+
if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {
|
|
84
|
+
incEndVertices = false;
|
|
85
|
+
}
|
|
86
|
+
if (isPointOnLineSegment(
|
|
87
|
+
lineString1.coordinates[i],
|
|
88
|
+
lineString1.coordinates[i + 1],
|
|
89
|
+
lineString2.coordinates[i2],
|
|
90
|
+
incEndVertices
|
|
91
|
+
)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
__name(doLineStringsCross, "doLineStringsCross");
|
|
100
|
+
function doLineStringAndPolygonCross(lineString, polygon) {
|
|
101
|
+
const line = _polygontoline.polygonToLine.call(void 0, polygon);
|
|
102
|
+
const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString, line);
|
|
103
|
+
if (doLinesIntersect.features.length > 0) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
__name(doLineStringAndPolygonCross, "doLineStringAndPolygonCross");
|
|
109
|
+
function doesMultiPointCrossPoly(multiPoint, polygon) {
|
|
110
|
+
var foundIntPoint = false;
|
|
111
|
+
var foundExtPoint = false;
|
|
112
|
+
var pointLength = multiPoint.coordinates.length;
|
|
113
|
+
for (let i = 0; i < pointLength && (!foundIntPoint || !foundExtPoint); i++) {
|
|
114
|
+
if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, _helpers.point.call(void 0, multiPoint.coordinates[i]), polygon)) {
|
|
115
|
+
foundIntPoint = true;
|
|
116
|
+
} else {
|
|
117
|
+
foundExtPoint = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return foundExtPoint && foundIntPoint;
|
|
121
|
+
}
|
|
122
|
+
__name(doesMultiPointCrossPoly, "doesMultiPointCrossPoly");
|
|
123
|
+
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt, incEnd) {
|
|
124
|
+
var dxc = pt[0] - lineSegmentStart[0];
|
|
125
|
+
var dyc = pt[1] - lineSegmentStart[1];
|
|
126
|
+
var dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
127
|
+
var dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
128
|
+
var cross = dxc * dyl - dyc * dxl;
|
|
129
|
+
if (cross !== 0) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (incEnd) {
|
|
133
|
+
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
134
|
+
return dxl > 0 ? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0] : lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
135
|
+
}
|
|
136
|
+
return dyl > 0 ? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1] : lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
137
|
+
} else {
|
|
138
|
+
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
139
|
+
return dxl > 0 ? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0] : lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];
|
|
140
|
+
}
|
|
141
|
+
return dyl > 0 ? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1] : lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
__name(isPointOnLineSegment, "isPointOnLineSegment");
|
|
145
|
+
var turf_boolean_crosses_default = booleanCrosses;
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
exports.booleanCrosses = booleanCrosses; exports.default = turf_boolean_crosses_default;
|
|
150
|
+
//# sourceMappingURL=index.cj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C,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,iBAAiB,CAAC;AAAA,IAC7D;AACA,WAAO,MAAM,IACT,iBAAiB,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,eAAe,CAAC,IACvD,eAAe,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,iBAAiB,CAAC;AAAA,EAC7D;AACF;AAjCS;AAoCT,IAAO,+BAAQ","sourcesContent":["import { Feature, Geometry, Polygon, LineString, MultiPoint } from \"geojson\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { polygonToLine } from \"@turf/polygon-to-line\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { getGeom } from \"@turf/invariant\";\nimport { point } from \"@turf/helpers\";\n\n/**\n * Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than\n * the maximum dimension of the two source geometries and the intersection set is interior to\n * both source geometries.\n *\n * Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.\n * Other comparisons are not supported as they are outside the OpenGIS Simple Features spec and may give unexpected results.\n *\n * @name booleanCrosses\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 line1 = turf.lineString([[-2, 2], [4, 2]]);\n * var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n *\n * var cross = turf.booleanCrosses(line1, line2);\n * //=true\n */\nfunction booleanCrosses(\n feature1: Feature<any> | Geometry,\n feature2: Feature<any> | Geometry\n): boolean {\n var geom1 = getGeom(feature1);\n var geom2 = getGeom(feature2);\n var type1 = geom1.type;\n var type2 = geom2.type;\n\n switch (type1) {\n case \"MultiPoint\":\n switch (type2) {\n case \"LineString\":\n return doMultiPointAndLineStringCross(geom1, geom2);\n case \"Polygon\":\n return doesMultiPointCrossPoly(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"LineString\":\n switch (type2) {\n case \"MultiPoint\": // An inverse operation\n return doMultiPointAndLineStringCross(geom2, geom1);\n case \"LineString\":\n return doLineStringsCross(geom1, geom2);\n case \"Polygon\":\n return doLineStringAndPolygonCross(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"Polygon\":\n switch (type2) {\n case \"MultiPoint\": // An inverse operation\n return doesMultiPointCrossPoly(geom2, geom1);\n case \"LineString\": // An inverse operation\n return doLineStringAndPolygonCross(geom2, geom1);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n default:\n throw new Error(\"feature1 \" + type1 + \" geometry not supported\");\n }\n}\n\nfunction doMultiPointAndLineStringCross(\n multiPoint: MultiPoint,\n lineString: LineString\n) {\n var foundIntPoint = false;\n var foundExtPoint = false;\n var pointLength = multiPoint.coordinates.length;\n var i = 0;\n while (i < pointLength && !foundIntPoint && !foundExtPoint) {\n for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) {\n var incEndVertices = true;\n if (i2 === 0 || i2 === lineString.coordinates.length - 2) {\n incEndVertices = false;\n }\n if (\n isPointOnLineSegment(\n lineString.coordinates[i2],\n lineString.coordinates[i2 + 1],\n multiPoint.coordinates[i],\n incEndVertices\n )\n ) {\n foundIntPoint = true;\n } else {\n foundExtPoint = true;\n }\n }\n i++;\n }\n return foundIntPoint && foundExtPoint;\n}\n\nfunction doLineStringsCross(lineString1: LineString, lineString2: LineString) {\n var doLinesIntersect = lineIntersect(lineString1, lineString2);\n if (doLinesIntersect.features.length > 0) {\n for (var i = 0; i < lineString1.coordinates.length - 1; i++) {\n for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {\n var incEndVertices = true;\n if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {\n incEndVertices = false;\n }\n if (\n isPointOnLineSegment(\n lineString1.coordinates[i],\n lineString1.coordinates[i + 1],\n lineString2.coordinates[i2],\n incEndVertices\n )\n ) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\nfunction doLineStringAndPolygonCross(lineString: LineString, polygon: Polygon) {\n const line: any = polygonToLine(polygon);\n const doLinesIntersect = lineIntersect(lineString, line);\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction doesMultiPointCrossPoly(multiPoint: MultiPoint, polygon: Polygon) {\n var foundIntPoint = false;\n var foundExtPoint = false;\n var pointLength = multiPoint.coordinates.length;\n for (let i = 0; i < pointLength && (!foundIntPoint || !foundExtPoint); i++) {\n if (booleanPointInPolygon(point(multiPoint.coordinates[i]), polygon)) {\n foundIntPoint = true;\n } else {\n foundExtPoint = true;\n }\n }\n\n return foundExtPoint && foundIntPoint;\n}\n\n/**\n * Is a point on a line segment\n * Only takes into account outer rings\n * See http://stackoverflow.com/a/4833823/1979085\n *\n * @private\n * @param {number[]} lineSegmentStart coord pair of start of line\n * @param {number[]} lineSegmentEnd coord pair of end of line\n * @param {number[]} pt coord pair of point to check\n * @param {boolean} incEnd whether the point is allowed to fall on the line ends\n * @returns {boolean} true/false\n */\nfunction isPointOnLineSegment(\n lineSegmentStart: number[],\n lineSegmentEnd: number[],\n pt: number[],\n incEnd: boolean\n) {\n var dxc = pt[0] - lineSegmentStart[0];\n var dyc = pt[1] - lineSegmentStart[1];\n var dxl = lineSegmentEnd[0] - lineSegmentStart[0];\n var dyl = lineSegmentEnd[1] - lineSegmentStart[1];\n var cross = dxc * dyl - dyc * dxl;\n if (cross !== 0) {\n return false;\n }\n if (incEnd) {\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n return dxl > 0\n ? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]\n : lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];\n }\n return dyl > 0\n ? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]\n : lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];\n } else {\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n return dxl > 0\n ? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0]\n : lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];\n }\n return dyl > 0\n ? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1]\n : lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];\n }\n}\n\nexport { booleanCrosses };\nexport default booleanCrosses;\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Feature, Geometry } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than
|
|
5
|
+
* the maximum dimension of the two source geometries and the intersection set is interior to
|
|
6
|
+
* both source geometries.
|
|
7
|
+
*
|
|
8
|
+
* Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.
|
|
9
|
+
* Other comparisons are not supported as they are outside the OpenGIS Simple Features spec and may give unexpected results.
|
|
10
|
+
*
|
|
11
|
+
* @name booleanCrosses
|
|
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 line1 = turf.lineString([[-2, 2], [4, 2]]);
|
|
17
|
+
* var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
18
|
+
*
|
|
19
|
+
* var cross = turf.booleanCrosses(line1, line2);
|
|
20
|
+
* //=true
|
|
21
|
+
*/
|
|
22
|
+
declare function booleanCrosses(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
|
|
23
|
+
|
|
24
|
+
export { booleanCrosses, booleanCrosses as default };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feature, Geometry } from
|
|
1
|
+
import { Feature, Geometry } from 'geojson';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than
|
|
4
5
|
* the maximum dimension of the two source geometries and the intersection set is interior to
|
|
@@ -19,4 +20,5 @@ import { Feature, Geometry } from "geojson";
|
|
|
19
20
|
* //=true
|
|
20
21
|
*/
|
|
21
22
|
declare function booleanCrosses(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
|
|
22
|
-
|
|
23
|
+
|
|
24
|
+
export { booleanCrosses, booleanCrosses as default };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { lineIntersect } from "@turf/line-intersect";
|
|
6
|
+
import { polygonToLine } from "@turf/polygon-to-line";
|
|
7
|
+
import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
|
|
8
|
+
import { getGeom } from "@turf/invariant";
|
|
9
|
+
import { point } from "@turf/helpers";
|
|
10
|
+
function booleanCrosses(feature1, feature2) {
|
|
11
|
+
var geom1 = getGeom(feature1);
|
|
12
|
+
var geom2 = getGeom(feature2);
|
|
13
|
+
var type1 = geom1.type;
|
|
14
|
+
var type2 = geom2.type;
|
|
15
|
+
switch (type1) {
|
|
16
|
+
case "MultiPoint":
|
|
17
|
+
switch (type2) {
|
|
18
|
+
case "LineString":
|
|
19
|
+
return doMultiPointAndLineStringCross(geom1, geom2);
|
|
20
|
+
case "Polygon":
|
|
21
|
+
return doesMultiPointCrossPoly(geom1, geom2);
|
|
22
|
+
default:
|
|
23
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
24
|
+
}
|
|
25
|
+
case "LineString":
|
|
26
|
+
switch (type2) {
|
|
27
|
+
case "MultiPoint":
|
|
28
|
+
return doMultiPointAndLineStringCross(geom2, geom1);
|
|
29
|
+
case "LineString":
|
|
30
|
+
return doLineStringsCross(geom1, geom2);
|
|
31
|
+
case "Polygon":
|
|
32
|
+
return doLineStringAndPolygonCross(geom1, geom2);
|
|
33
|
+
default:
|
|
34
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
35
|
+
}
|
|
36
|
+
case "Polygon":
|
|
37
|
+
switch (type2) {
|
|
38
|
+
case "MultiPoint":
|
|
39
|
+
return doesMultiPointCrossPoly(geom2, geom1);
|
|
40
|
+
case "LineString":
|
|
41
|
+
return doLineStringAndPolygonCross(geom2, geom1);
|
|
42
|
+
default:
|
|
43
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
44
|
+
}
|
|
45
|
+
default:
|
|
46
|
+
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
__name(booleanCrosses, "booleanCrosses");
|
|
50
|
+
function doMultiPointAndLineStringCross(multiPoint, lineString) {
|
|
51
|
+
var foundIntPoint = false;
|
|
52
|
+
var foundExtPoint = false;
|
|
53
|
+
var pointLength = multiPoint.coordinates.length;
|
|
54
|
+
var i = 0;
|
|
55
|
+
while (i < pointLength && !foundIntPoint && !foundExtPoint) {
|
|
56
|
+
for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) {
|
|
57
|
+
var incEndVertices = true;
|
|
58
|
+
if (i2 === 0 || i2 === lineString.coordinates.length - 2) {
|
|
59
|
+
incEndVertices = false;
|
|
60
|
+
}
|
|
61
|
+
if (isPointOnLineSegment(
|
|
62
|
+
lineString.coordinates[i2],
|
|
63
|
+
lineString.coordinates[i2 + 1],
|
|
64
|
+
multiPoint.coordinates[i],
|
|
65
|
+
incEndVertices
|
|
66
|
+
)) {
|
|
67
|
+
foundIntPoint = true;
|
|
68
|
+
} else {
|
|
69
|
+
foundExtPoint = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
i++;
|
|
73
|
+
}
|
|
74
|
+
return foundIntPoint && foundExtPoint;
|
|
75
|
+
}
|
|
76
|
+
__name(doMultiPointAndLineStringCross, "doMultiPointAndLineStringCross");
|
|
77
|
+
function doLineStringsCross(lineString1, lineString2) {
|
|
78
|
+
var doLinesIntersect = lineIntersect(lineString1, lineString2);
|
|
79
|
+
if (doLinesIntersect.features.length > 0) {
|
|
80
|
+
for (var i = 0; i < lineString1.coordinates.length - 1; i++) {
|
|
81
|
+
for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {
|
|
82
|
+
var incEndVertices = true;
|
|
83
|
+
if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {
|
|
84
|
+
incEndVertices = false;
|
|
85
|
+
}
|
|
86
|
+
if (isPointOnLineSegment(
|
|
87
|
+
lineString1.coordinates[i],
|
|
88
|
+
lineString1.coordinates[i + 1],
|
|
89
|
+
lineString2.coordinates[i2],
|
|
90
|
+
incEndVertices
|
|
91
|
+
)) {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
__name(doLineStringsCross, "doLineStringsCross");
|
|
100
|
+
function doLineStringAndPolygonCross(lineString, polygon) {
|
|
101
|
+
const line = polygonToLine(polygon);
|
|
102
|
+
const doLinesIntersect = lineIntersect(lineString, line);
|
|
103
|
+
if (doLinesIntersect.features.length > 0) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
__name(doLineStringAndPolygonCross, "doLineStringAndPolygonCross");
|
|
109
|
+
function doesMultiPointCrossPoly(multiPoint, polygon) {
|
|
110
|
+
var foundIntPoint = false;
|
|
111
|
+
var foundExtPoint = false;
|
|
112
|
+
var pointLength = multiPoint.coordinates.length;
|
|
113
|
+
for (let i = 0; i < pointLength && (!foundIntPoint || !foundExtPoint); i++) {
|
|
114
|
+
if (booleanPointInPolygon(point(multiPoint.coordinates[i]), polygon)) {
|
|
115
|
+
foundIntPoint = true;
|
|
116
|
+
} else {
|
|
117
|
+
foundExtPoint = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return foundExtPoint && foundIntPoint;
|
|
121
|
+
}
|
|
122
|
+
__name(doesMultiPointCrossPoly, "doesMultiPointCrossPoly");
|
|
123
|
+
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt, incEnd) {
|
|
124
|
+
var dxc = pt[0] - lineSegmentStart[0];
|
|
125
|
+
var dyc = pt[1] - lineSegmentStart[1];
|
|
126
|
+
var dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
127
|
+
var dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
128
|
+
var cross = dxc * dyl - dyc * dxl;
|
|
129
|
+
if (cross !== 0) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (incEnd) {
|
|
133
|
+
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
134
|
+
return dxl > 0 ? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0] : lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
135
|
+
}
|
|
136
|
+
return dyl > 0 ? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1] : lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
137
|
+
} else {
|
|
138
|
+
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
139
|
+
return dxl > 0 ? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0] : lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];
|
|
140
|
+
}
|
|
141
|
+
return dyl > 0 ? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1] : lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
__name(isPointOnLineSegment, "isPointOnLineSegment");
|
|
145
|
+
var turf_boolean_crosses_default = booleanCrosses;
|
|
146
|
+
export {
|
|
147
|
+
booleanCrosses,
|
|
148
|
+
turf_boolean_crosses_default as default
|
|
149
|
+
};
|
|
150
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, Geometry, Polygon, LineString, MultiPoint } from \"geojson\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { polygonToLine } from \"@turf/polygon-to-line\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { getGeom } from \"@turf/invariant\";\nimport { point } from \"@turf/helpers\";\n\n/**\n * Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than\n * the maximum dimension of the two source geometries and the intersection set is interior to\n * both source geometries.\n *\n * Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.\n * Other comparisons are not supported as they are outside the OpenGIS Simple Features spec and may give unexpected results.\n *\n * @name booleanCrosses\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 line1 = turf.lineString([[-2, 2], [4, 2]]);\n * var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n *\n * var cross = turf.booleanCrosses(line1, line2);\n * //=true\n */\nfunction booleanCrosses(\n feature1: Feature<any> | Geometry,\n feature2: Feature<any> | Geometry\n): boolean {\n var geom1 = getGeom(feature1);\n var geom2 = getGeom(feature2);\n var type1 = geom1.type;\n var type2 = geom2.type;\n\n switch (type1) {\n case \"MultiPoint\":\n switch (type2) {\n case \"LineString\":\n return doMultiPointAndLineStringCross(geom1, geom2);\n case \"Polygon\":\n return doesMultiPointCrossPoly(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"LineString\":\n switch (type2) {\n case \"MultiPoint\": // An inverse operation\n return doMultiPointAndLineStringCross(geom2, geom1);\n case \"LineString\":\n return doLineStringsCross(geom1, geom2);\n case \"Polygon\":\n return doLineStringAndPolygonCross(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"Polygon\":\n switch (type2) {\n case \"MultiPoint\": // An inverse operation\n return doesMultiPointCrossPoly(geom2, geom1);\n case \"LineString\": // An inverse operation\n return doLineStringAndPolygonCross(geom2, geom1);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n default:\n throw new Error(\"feature1 \" + type1 + \" geometry not supported\");\n }\n}\n\nfunction doMultiPointAndLineStringCross(\n multiPoint: MultiPoint,\n lineString: LineString\n) {\n var foundIntPoint = false;\n var foundExtPoint = false;\n var pointLength = multiPoint.coordinates.length;\n var i = 0;\n while (i < pointLength && !foundIntPoint && !foundExtPoint) {\n for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) {\n var incEndVertices = true;\n if (i2 === 0 || i2 === lineString.coordinates.length - 2) {\n incEndVertices = false;\n }\n if (\n isPointOnLineSegment(\n lineString.coordinates[i2],\n lineString.coordinates[i2 + 1],\n multiPoint.coordinates[i],\n incEndVertices\n )\n ) {\n foundIntPoint = true;\n } else {\n foundExtPoint = true;\n }\n }\n i++;\n }\n return foundIntPoint && foundExtPoint;\n}\n\nfunction doLineStringsCross(lineString1: LineString, lineString2: LineString) {\n var doLinesIntersect = lineIntersect(lineString1, lineString2);\n if (doLinesIntersect.features.length > 0) {\n for (var i = 0; i < lineString1.coordinates.length - 1; i++) {\n for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {\n var incEndVertices = true;\n if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {\n incEndVertices = false;\n }\n if (\n isPointOnLineSegment(\n lineString1.coordinates[i],\n lineString1.coordinates[i + 1],\n lineString2.coordinates[i2],\n incEndVertices\n )\n ) {\n return true;\n }\n }\n }\n }\n return false;\n}\n\nfunction doLineStringAndPolygonCross(lineString: LineString, polygon: Polygon) {\n const line: any = polygonToLine(polygon);\n const doLinesIntersect = lineIntersect(lineString, line);\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction doesMultiPointCrossPoly(multiPoint: MultiPoint, polygon: Polygon) {\n var foundIntPoint = false;\n var foundExtPoint = false;\n var pointLength = multiPoint.coordinates.length;\n for (let i = 0; i < pointLength && (!foundIntPoint || !foundExtPoint); i++) {\n if (booleanPointInPolygon(point(multiPoint.coordinates[i]), polygon)) {\n foundIntPoint = true;\n } else {\n foundExtPoint = true;\n }\n }\n\n return foundExtPoint && foundIntPoint;\n}\n\n/**\n * Is a point on a line segment\n * Only takes into account outer rings\n * See http://stackoverflow.com/a/4833823/1979085\n *\n * @private\n * @param {number[]} lineSegmentStart coord pair of start of line\n * @param {number[]} lineSegmentEnd coord pair of end of line\n * @param {number[]} pt coord pair of point to check\n * @param {boolean} incEnd whether the point is allowed to fall on the line ends\n * @returns {boolean} true/false\n */\nfunction isPointOnLineSegment(\n lineSegmentStart: number[],\n lineSegmentEnd: number[],\n pt: number[],\n incEnd: boolean\n) {\n var dxc = pt[0] - lineSegmentStart[0];\n var dyc = pt[1] - lineSegmentStart[1];\n var dxl = lineSegmentEnd[0] - lineSegmentStart[0];\n var dyl = lineSegmentEnd[1] - lineSegmentStart[1];\n var cross = dxc * dyl - dyc * dxl;\n if (cross !== 0) {\n return false;\n }\n if (incEnd) {\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n return dxl > 0\n ? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]\n : lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];\n }\n return dyl > 0\n ? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]\n : lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];\n } else {\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n return dxl > 0\n ? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0]\n : lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];\n }\n return dyl > 0\n ? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1]\n : lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];\n }\n}\n\nexport { booleanCrosses };\nexport default booleanCrosses;\n"],"mappings":";;;;AACA,SAAS,qBAAqB;AAC9B,SAAS,qBAAqB;AAC9B,SAAS,6BAA6B;AACtC,SAAS,eAAe;AACxB,SAAS,aAAa;AAqBtB,SAAS,eACP,UACA,UACS;AACT,MAAI,QAAQ,QAAQ,QAAQ;AAC5B,MAAI,QAAQ,QAAQ,QAAQ;AAC5B,MAAI,QAAQ,MAAM;AAClB,MAAI,QAAQ,MAAM;AAElB,UAAQ,OAAO;AAAA,IACb,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,+BAA+B,OAAO,KAAK;AAAA,QACpD,KAAK;AACH,iBAAO,wBAAwB,OAAO,KAAK;AAAA,QAC7C;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,+BAA+B,OAAO,KAAK;AAAA,QACpD,KAAK;AACH,iBAAO,mBAAmB,OAAO,KAAK;AAAA,QACxC,KAAK;AACH,iBAAO,4BAA4B,OAAO,KAAK;AAAA,QACjD;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,wBAAwB,OAAO,KAAK;AAAA,QAC7C,KAAK;AACH,iBAAO,4BAA4B,OAAO,KAAK;AAAA,QACjD;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF;AACE,YAAM,IAAI,MAAM,c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AAA,EAC/D,OAAO;AACL,QAAI,KAAK,IAAI,GAAG,KAAK,KAAK,IAAI,GAAG,GAAG;AAClC,aAAO,MAAM,IACT,iBAAiB,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,eAAe,CAAC,IACvD,eAAe,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,iBAAiB,CAAC;AAAA,IAC7D;AACA,WAAO,MAAM,IACT,iBAAiB,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,eAAe,CAAC,IACvD,eAAe,CAAC,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,IAAI,iBAAiB,CAAC;AAAA,EAC7D;AACF;AAjCS;AAoCT,IAAO,+BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/boolean-crosses",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "turf boolean-crosses module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -26,49 +26,54 @@
|
|
|
26
26
|
"boolean",
|
|
27
27
|
"de-9im"
|
|
28
28
|
],
|
|
29
|
-
"
|
|
30
|
-
"
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "dist/cjs/index.cjs",
|
|
31
|
+
"module": "dist/esm/index.js",
|
|
32
|
+
"types": "dist/esm/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.ts",
|
|
38
|
+
"default": "./dist/esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"require": {
|
|
41
|
+
"types": "./dist/cjs/index.d.cts",
|
|
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
|
-
"glob": "
|
|
58
|
-
"load-json-file": "
|
|
59
|
-
"npm-run-all": "
|
|
60
|
-
"tape": "
|
|
61
|
-
"
|
|
62
|
-
"tsx": "
|
|
63
|
-
"typescript": "
|
|
62
|
+
"glob": "^10.3.10",
|
|
63
|
+
"load-json-file": "^7.0.1",
|
|
64
|
+
"npm-run-all": "^4.1.5",
|
|
65
|
+
"tape": "^5.7.2",
|
|
66
|
+
"tsup": "^8.0.1",
|
|
67
|
+
"tsx": "^4.6.2",
|
|
68
|
+
"typescript": "^5.2.2"
|
|
64
69
|
},
|
|
65
70
|
"dependencies": {
|
|
66
|
-
"@turf/boolean-point-in-polygon": "^7.0.0
|
|
67
|
-
"@turf/helpers": "^7.0.0
|
|
68
|
-
"@turf/invariant": "^7.0.0
|
|
69
|
-
"@turf/line-intersect": "^7.0.0
|
|
70
|
-
"@turf/polygon-to-line": "^7.0.0
|
|
71
|
-
"tslib": "^2.
|
|
71
|
+
"@turf/boolean-point-in-polygon": "^7.0.0",
|
|
72
|
+
"@turf/helpers": "^7.0.0",
|
|
73
|
+
"@turf/invariant": "^7.0.0",
|
|
74
|
+
"@turf/line-intersect": "^7.0.0",
|
|
75
|
+
"@turf/polygon-to-line": "^7.0.0",
|
|
76
|
+
"tslib": "^2.6.2"
|
|
72
77
|
},
|
|
73
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
|
|
74
79
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import lineIntersect from "@turf/line-intersect";
|
|
2
|
-
import { polygonToLine } from "@turf/polygon-to-line";
|
|
3
|
-
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
4
|
-
import { getGeom } from "@turf/invariant";
|
|
5
|
-
import { point } from "@turf/helpers";
|
|
6
|
-
/**
|
|
7
|
-
* Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than
|
|
8
|
-
* the maximum dimension of the two source geometries and the intersection set is interior to
|
|
9
|
-
* both source geometries.
|
|
10
|
-
*
|
|
11
|
-
* Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.
|
|
12
|
-
* Other comparisons are not supported as they are outside the OpenGIS Simple Features spec and may give unexpected results.
|
|
13
|
-
*
|
|
14
|
-
* @name booleanCrosses
|
|
15
|
-
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
16
|
-
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
17
|
-
* @returns {boolean} true/false
|
|
18
|
-
* @example
|
|
19
|
-
* var line1 = turf.lineString([[-2, 2], [4, 2]]);
|
|
20
|
-
* var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
21
|
-
*
|
|
22
|
-
* var cross = turf.booleanCrosses(line1, line2);
|
|
23
|
-
* //=true
|
|
24
|
-
*/
|
|
25
|
-
function booleanCrosses(feature1, feature2) {
|
|
26
|
-
var geom1 = getGeom(feature1);
|
|
27
|
-
var geom2 = getGeom(feature2);
|
|
28
|
-
var type1 = geom1.type;
|
|
29
|
-
var type2 = geom2.type;
|
|
30
|
-
switch (type1) {
|
|
31
|
-
case "MultiPoint":
|
|
32
|
-
switch (type2) {
|
|
33
|
-
case "LineString":
|
|
34
|
-
return doMultiPointAndLineStringCross(geom1, geom2);
|
|
35
|
-
case "Polygon":
|
|
36
|
-
return doesMultiPointCrossPoly(geom1, geom2);
|
|
37
|
-
default:
|
|
38
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
39
|
-
}
|
|
40
|
-
case "LineString":
|
|
41
|
-
switch (type2) {
|
|
42
|
-
case "MultiPoint": // An inverse operation
|
|
43
|
-
return doMultiPointAndLineStringCross(geom2, geom1);
|
|
44
|
-
case "LineString":
|
|
45
|
-
return doLineStringsCross(geom1, geom2);
|
|
46
|
-
case "Polygon":
|
|
47
|
-
return doLineStringAndPolygonCross(geom1, geom2);
|
|
48
|
-
default:
|
|
49
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
50
|
-
}
|
|
51
|
-
case "Polygon":
|
|
52
|
-
switch (type2) {
|
|
53
|
-
case "MultiPoint": // An inverse operation
|
|
54
|
-
return doesMultiPointCrossPoly(geom2, geom1);
|
|
55
|
-
case "LineString": // An inverse operation
|
|
56
|
-
return doLineStringAndPolygonCross(geom2, geom1);
|
|
57
|
-
default:
|
|
58
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
59
|
-
}
|
|
60
|
-
default:
|
|
61
|
-
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
function doMultiPointAndLineStringCross(multiPoint, lineString) {
|
|
65
|
-
var foundIntPoint = false;
|
|
66
|
-
var foundExtPoint = false;
|
|
67
|
-
var pointLength = multiPoint.coordinates.length;
|
|
68
|
-
var i = 0;
|
|
69
|
-
while (i < pointLength && !foundIntPoint && !foundExtPoint) {
|
|
70
|
-
for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) {
|
|
71
|
-
var incEndVertices = true;
|
|
72
|
-
if (i2 === 0 || i2 === lineString.coordinates.length - 2) {
|
|
73
|
-
incEndVertices = false;
|
|
74
|
-
}
|
|
75
|
-
if (isPointOnLineSegment(lineString.coordinates[i2], lineString.coordinates[i2 + 1], multiPoint.coordinates[i], incEndVertices)) {
|
|
76
|
-
foundIntPoint = true;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
foundExtPoint = true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
i++;
|
|
83
|
-
}
|
|
84
|
-
return foundIntPoint && foundExtPoint;
|
|
85
|
-
}
|
|
86
|
-
function doLineStringsCross(lineString1, lineString2) {
|
|
87
|
-
var doLinesIntersect = lineIntersect(lineString1, lineString2);
|
|
88
|
-
if (doLinesIntersect.features.length > 0) {
|
|
89
|
-
for (var i = 0; i < lineString1.coordinates.length - 1; i++) {
|
|
90
|
-
for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {
|
|
91
|
-
var incEndVertices = true;
|
|
92
|
-
if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {
|
|
93
|
-
incEndVertices = false;
|
|
94
|
-
}
|
|
95
|
-
if (isPointOnLineSegment(lineString1.coordinates[i], lineString1.coordinates[i + 1], lineString2.coordinates[i2], incEndVertices)) {
|
|
96
|
-
return true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
}
|
|
103
|
-
function doLineStringAndPolygonCross(lineString, polygon) {
|
|
104
|
-
const line = polygonToLine(polygon);
|
|
105
|
-
const doLinesIntersect = lineIntersect(lineString, line);
|
|
106
|
-
if (doLinesIntersect.features.length > 0) {
|
|
107
|
-
return true;
|
|
108
|
-
}
|
|
109
|
-
return false;
|
|
110
|
-
}
|
|
111
|
-
function doesMultiPointCrossPoly(multiPoint, polygon) {
|
|
112
|
-
var foundIntPoint = false;
|
|
113
|
-
var foundExtPoint = false;
|
|
114
|
-
var pointLength = multiPoint.coordinates.length;
|
|
115
|
-
for (let i = 0; i < pointLength && (!foundIntPoint || !foundExtPoint); i++) {
|
|
116
|
-
if (booleanPointInPolygon(point(multiPoint.coordinates[i]), polygon)) {
|
|
117
|
-
foundIntPoint = true;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
foundExtPoint = true;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return foundExtPoint && foundIntPoint;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Is a point on a line segment
|
|
127
|
-
* Only takes into account outer rings
|
|
128
|
-
* See http://stackoverflow.com/a/4833823/1979085
|
|
129
|
-
*
|
|
130
|
-
* @private
|
|
131
|
-
* @param {number[]} lineSegmentStart coord pair of start of line
|
|
132
|
-
* @param {number[]} lineSegmentEnd coord pair of end of line
|
|
133
|
-
* @param {number[]} pt coord pair of point to check
|
|
134
|
-
* @param {boolean} incEnd whether the point is allowed to fall on the line ends
|
|
135
|
-
* @returns {boolean} true/false
|
|
136
|
-
*/
|
|
137
|
-
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt, incEnd) {
|
|
138
|
-
var dxc = pt[0] - lineSegmentStart[0];
|
|
139
|
-
var dyc = pt[1] - lineSegmentStart[1];
|
|
140
|
-
var dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
141
|
-
var dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
142
|
-
var cross = dxc * dyl - dyc * dxl;
|
|
143
|
-
if (cross !== 0) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
if (incEnd) {
|
|
147
|
-
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
148
|
-
return dxl > 0
|
|
149
|
-
? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]
|
|
150
|
-
: lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
151
|
-
}
|
|
152
|
-
return dyl > 0
|
|
153
|
-
? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]
|
|
154
|
-
: lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
158
|
-
return dxl > 0
|
|
159
|
-
? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0]
|
|
160
|
-
: lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];
|
|
161
|
-
}
|
|
162
|
-
return dyl > 0
|
|
163
|
-
? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1]
|
|
164
|
-
: lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
export default booleanCrosses;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const line_intersect_1 = tslib_1.__importDefault(require("@turf/line-intersect"));
|
|
5
|
-
const polygon_to_line_1 = require("@turf/polygon-to-line");
|
|
6
|
-
const boolean_point_in_polygon_1 = tslib_1.__importDefault(require("@turf/boolean-point-in-polygon"));
|
|
7
|
-
const invariant_1 = require("@turf/invariant");
|
|
8
|
-
const helpers_1 = require("@turf/helpers");
|
|
9
|
-
/**
|
|
10
|
-
* Boolean-Crosses returns True if the intersection results in a geometry whose dimension is one less than
|
|
11
|
-
* the maximum dimension of the two source geometries and the intersection set is interior to
|
|
12
|
-
* both source geometries.
|
|
13
|
-
*
|
|
14
|
-
* Boolean-Crosses returns t (TRUE) for only multipoint/polygon, multipoint/linestring, linestring/linestring, linestring/polygon, and linestring/multipolygon comparisons.
|
|
15
|
-
* Other comparisons are not supported as they are outside the OpenGIS Simple Features spec and may give unexpected results.
|
|
16
|
-
*
|
|
17
|
-
* @name booleanCrosses
|
|
18
|
-
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
19
|
-
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
20
|
-
* @returns {boolean} true/false
|
|
21
|
-
* @example
|
|
22
|
-
* var line1 = turf.lineString([[-2, 2], [4, 2]]);
|
|
23
|
-
* var line2 = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
24
|
-
*
|
|
25
|
-
* var cross = turf.booleanCrosses(line1, line2);
|
|
26
|
-
* //=true
|
|
27
|
-
*/
|
|
28
|
-
function booleanCrosses(feature1, feature2) {
|
|
29
|
-
var geom1 = invariant_1.getGeom(feature1);
|
|
30
|
-
var geom2 = invariant_1.getGeom(feature2);
|
|
31
|
-
var type1 = geom1.type;
|
|
32
|
-
var type2 = geom2.type;
|
|
33
|
-
switch (type1) {
|
|
34
|
-
case "MultiPoint":
|
|
35
|
-
switch (type2) {
|
|
36
|
-
case "LineString":
|
|
37
|
-
return doMultiPointAndLineStringCross(geom1, geom2);
|
|
38
|
-
case "Polygon":
|
|
39
|
-
return doesMultiPointCrossPoly(geom1, geom2);
|
|
40
|
-
default:
|
|
41
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
42
|
-
}
|
|
43
|
-
case "LineString":
|
|
44
|
-
switch (type2) {
|
|
45
|
-
case "MultiPoint": // An inverse operation
|
|
46
|
-
return doMultiPointAndLineStringCross(geom2, geom1);
|
|
47
|
-
case "LineString":
|
|
48
|
-
return doLineStringsCross(geom1, geom2);
|
|
49
|
-
case "Polygon":
|
|
50
|
-
return doLineStringAndPolygonCross(geom1, geom2);
|
|
51
|
-
default:
|
|
52
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
53
|
-
}
|
|
54
|
-
case "Polygon":
|
|
55
|
-
switch (type2) {
|
|
56
|
-
case "MultiPoint": // An inverse operation
|
|
57
|
-
return doesMultiPointCrossPoly(geom2, geom1);
|
|
58
|
-
case "LineString": // An inverse operation
|
|
59
|
-
return doLineStringAndPolygonCross(geom2, geom1);
|
|
60
|
-
default:
|
|
61
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
62
|
-
}
|
|
63
|
-
default:
|
|
64
|
-
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
function doMultiPointAndLineStringCross(multiPoint, lineString) {
|
|
68
|
-
var foundIntPoint = false;
|
|
69
|
-
var foundExtPoint = false;
|
|
70
|
-
var pointLength = multiPoint.coordinates.length;
|
|
71
|
-
var i = 0;
|
|
72
|
-
while (i < pointLength && !foundIntPoint && !foundExtPoint) {
|
|
73
|
-
for (var i2 = 0; i2 < lineString.coordinates.length - 1; i2++) {
|
|
74
|
-
var incEndVertices = true;
|
|
75
|
-
if (i2 === 0 || i2 === lineString.coordinates.length - 2) {
|
|
76
|
-
incEndVertices = false;
|
|
77
|
-
}
|
|
78
|
-
if (isPointOnLineSegment(lineString.coordinates[i2], lineString.coordinates[i2 + 1], multiPoint.coordinates[i], incEndVertices)) {
|
|
79
|
-
foundIntPoint = true;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
foundExtPoint = true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
i++;
|
|
86
|
-
}
|
|
87
|
-
return foundIntPoint && foundExtPoint;
|
|
88
|
-
}
|
|
89
|
-
function doLineStringsCross(lineString1, lineString2) {
|
|
90
|
-
var doLinesIntersect = line_intersect_1.default(lineString1, lineString2);
|
|
91
|
-
if (doLinesIntersect.features.length > 0) {
|
|
92
|
-
for (var i = 0; i < lineString1.coordinates.length - 1; i++) {
|
|
93
|
-
for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {
|
|
94
|
-
var incEndVertices = true;
|
|
95
|
-
if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {
|
|
96
|
-
incEndVertices = false;
|
|
97
|
-
}
|
|
98
|
-
if (isPointOnLineSegment(lineString1.coordinates[i], lineString1.coordinates[i + 1], lineString2.coordinates[i2], incEndVertices)) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
function doLineStringAndPolygonCross(lineString, polygon) {
|
|
107
|
-
const line = polygon_to_line_1.polygonToLine(polygon);
|
|
108
|
-
const doLinesIntersect = line_intersect_1.default(lineString, line);
|
|
109
|
-
if (doLinesIntersect.features.length > 0) {
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
function doesMultiPointCrossPoly(multiPoint, polygon) {
|
|
115
|
-
var foundIntPoint = false;
|
|
116
|
-
var foundExtPoint = false;
|
|
117
|
-
var pointLength = multiPoint.coordinates.length;
|
|
118
|
-
for (let i = 0; i < pointLength && (!foundIntPoint || !foundExtPoint); i++) {
|
|
119
|
-
if (boolean_point_in_polygon_1.default(helpers_1.point(multiPoint.coordinates[i]), polygon)) {
|
|
120
|
-
foundIntPoint = true;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
foundExtPoint = true;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return foundExtPoint && foundIntPoint;
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Is a point on a line segment
|
|
130
|
-
* Only takes into account outer rings
|
|
131
|
-
* See http://stackoverflow.com/a/4833823/1979085
|
|
132
|
-
*
|
|
133
|
-
* @private
|
|
134
|
-
* @param {number[]} lineSegmentStart coord pair of start of line
|
|
135
|
-
* @param {number[]} lineSegmentEnd coord pair of end of line
|
|
136
|
-
* @param {number[]} pt coord pair of point to check
|
|
137
|
-
* @param {boolean} incEnd whether the point is allowed to fall on the line ends
|
|
138
|
-
* @returns {boolean} true/false
|
|
139
|
-
*/
|
|
140
|
-
function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt, incEnd) {
|
|
141
|
-
var dxc = pt[0] - lineSegmentStart[0];
|
|
142
|
-
var dyc = pt[1] - lineSegmentStart[1];
|
|
143
|
-
var dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
|
144
|
-
var dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
|
145
|
-
var cross = dxc * dyl - dyc * dxl;
|
|
146
|
-
if (cross !== 0) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
if (incEnd) {
|
|
150
|
-
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
151
|
-
return dxl > 0
|
|
152
|
-
? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0]
|
|
153
|
-
: lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
|
154
|
-
}
|
|
155
|
-
return dyl > 0
|
|
156
|
-
? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1]
|
|
157
|
-
: lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
if (Math.abs(dxl) >= Math.abs(dyl)) {
|
|
161
|
-
return dxl > 0
|
|
162
|
-
? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0]
|
|
163
|
-
: lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];
|
|
164
|
-
}
|
|
165
|
-
return dyl > 0
|
|
166
|
-
? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1]
|
|
167
|
-
: lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.default = booleanCrosses;
|