@turf/boolean-within 7.0.0-alpha.0 → 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 +204 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{js → cjs}/index.d.ts +4 -2
- package/dist/esm/index.d.mts +22 -0
- package/dist/esm/index.mjs +204 -0
- package/dist/esm/index.mjs.map +1 -0
- package/package.json +35 -29
- package/dist/es/index.js +0 -215
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -218
package/README.md
CHANGED
|
@@ -32,26 +32,21 @@ Returns **[boolean][3]** true/false
|
|
|
32
32
|
|
|
33
33
|
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
|
|
34
34
|
|
|
35
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
36
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
37
|
-
./scripts/generate-readmes in the turf project. -->
|
|
35
|
+
<!-- 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. -->
|
|
38
36
|
|
|
39
37
|
---
|
|
40
38
|
|
|
41
|
-
This module is part of the [Turfjs project](
|
|
42
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
43
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
44
|
-
PRs and issues.
|
|
39
|
+
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.
|
|
45
40
|
|
|
46
41
|
### Installation
|
|
47
42
|
|
|
48
|
-
Install this module individually:
|
|
43
|
+
Install this single module individually:
|
|
49
44
|
|
|
50
45
|
```sh
|
|
51
46
|
$ npm install @turf/boolean-within
|
|
52
47
|
```
|
|
53
48
|
|
|
54
|
-
Or install the
|
|
49
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
55
50
|
|
|
56
51
|
```sh
|
|
57
52
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,204 @@
|
|
|
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 _bbox = require('@turf/bbox');
|
|
6
|
+
var _booleanpointonline = require('@turf/boolean-point-on-line');
|
|
7
|
+
var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
|
|
8
|
+
var _invariant = require('@turf/invariant');
|
|
9
|
+
function booleanWithin(feature1, feature2) {
|
|
10
|
+
var geom1 = _invariant.getGeom.call(void 0, feature1);
|
|
11
|
+
var geom2 = _invariant.getGeom.call(void 0, feature2);
|
|
12
|
+
var type1 = geom1.type;
|
|
13
|
+
var type2 = geom2.type;
|
|
14
|
+
switch (type1) {
|
|
15
|
+
case "Point":
|
|
16
|
+
switch (type2) {
|
|
17
|
+
case "MultiPoint":
|
|
18
|
+
return isPointInMultiPoint(geom1, geom2);
|
|
19
|
+
case "LineString":
|
|
20
|
+
return _booleanpointonline.booleanPointOnLine.call(void 0, geom1, geom2, { ignoreEndVertices: true });
|
|
21
|
+
case "Polygon":
|
|
22
|
+
case "MultiPolygon":
|
|
23
|
+
return _booleanpointinpolygon.booleanPointInPolygon.call(void 0, geom1, geom2, { ignoreBoundary: true });
|
|
24
|
+
default:
|
|
25
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
26
|
+
}
|
|
27
|
+
case "MultiPoint":
|
|
28
|
+
switch (type2) {
|
|
29
|
+
case "MultiPoint":
|
|
30
|
+
return isMultiPointInMultiPoint(geom1, geom2);
|
|
31
|
+
case "LineString":
|
|
32
|
+
return isMultiPointOnLine(geom1, geom2);
|
|
33
|
+
case "Polygon":
|
|
34
|
+
case "MultiPolygon":
|
|
35
|
+
return isMultiPointInPoly(geom1, geom2);
|
|
36
|
+
default:
|
|
37
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
38
|
+
}
|
|
39
|
+
case "LineString":
|
|
40
|
+
switch (type2) {
|
|
41
|
+
case "LineString":
|
|
42
|
+
return isLineOnLine(geom1, geom2);
|
|
43
|
+
case "Polygon":
|
|
44
|
+
case "MultiPolygon":
|
|
45
|
+
return isLineInPoly(geom1, geom2);
|
|
46
|
+
default:
|
|
47
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
48
|
+
}
|
|
49
|
+
case "Polygon":
|
|
50
|
+
switch (type2) {
|
|
51
|
+
case "Polygon":
|
|
52
|
+
case "MultiPolygon":
|
|
53
|
+
return isPolyInPoly(geom1, geom2);
|
|
54
|
+
default:
|
|
55
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
__name(booleanWithin, "booleanWithin");
|
|
62
|
+
function isPointInMultiPoint(point, multiPoint) {
|
|
63
|
+
var i;
|
|
64
|
+
var output = false;
|
|
65
|
+
for (i = 0; i < multiPoint.coordinates.length; i++) {
|
|
66
|
+
if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
|
|
67
|
+
output = true;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return output;
|
|
72
|
+
}
|
|
73
|
+
__name(isPointInMultiPoint, "isPointInMultiPoint");
|
|
74
|
+
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
|
|
75
|
+
for (var i = 0; i < multiPoint1.coordinates.length; i++) {
|
|
76
|
+
var anyMatch = false;
|
|
77
|
+
for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
|
|
78
|
+
if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
|
|
79
|
+
anyMatch = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!anyMatch) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
__name(isMultiPointInMultiPoint, "isMultiPointInMultiPoint");
|
|
89
|
+
function isMultiPointOnLine(multiPoint, lineString) {
|
|
90
|
+
var foundInsidePoint = false;
|
|
91
|
+
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
92
|
+
if (!_booleanpointonline.booleanPointOnLine.call(void 0, multiPoint.coordinates[i], lineString)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (!foundInsidePoint) {
|
|
96
|
+
foundInsidePoint = _booleanpointonline.booleanPointOnLine.call(void 0,
|
|
97
|
+
multiPoint.coordinates[i],
|
|
98
|
+
lineString,
|
|
99
|
+
{ ignoreEndVertices: true }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return foundInsidePoint;
|
|
104
|
+
}
|
|
105
|
+
__name(isMultiPointOnLine, "isMultiPointOnLine");
|
|
106
|
+
function isMultiPointInPoly(multiPoint, polygon) {
|
|
107
|
+
var output = true;
|
|
108
|
+
var oneInside = false;
|
|
109
|
+
var isInside = false;
|
|
110
|
+
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
111
|
+
isInside = _booleanpointinpolygon.booleanPointInPolygon.call(void 0, multiPoint.coordinates[i], polygon);
|
|
112
|
+
if (!isInside) {
|
|
113
|
+
output = false;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (!oneInside) {
|
|
117
|
+
isInside = _booleanpointinpolygon.booleanPointInPolygon.call(void 0, multiPoint.coordinates[i], polygon, {
|
|
118
|
+
ignoreBoundary: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return output && isInside;
|
|
123
|
+
}
|
|
124
|
+
__name(isMultiPointInPoly, "isMultiPointInPoly");
|
|
125
|
+
function isLineOnLine(lineString1, lineString2) {
|
|
126
|
+
for (var i = 0; i < lineString1.coordinates.length; i++) {
|
|
127
|
+
if (!_booleanpointonline.booleanPointOnLine.call(void 0, lineString1.coordinates[i], lineString2)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
__name(isLineOnLine, "isLineOnLine");
|
|
134
|
+
function isLineInPoly(linestring, polygon) {
|
|
135
|
+
var polyBbox = _bbox.bbox.call(void 0, polygon);
|
|
136
|
+
var lineBbox = _bbox.bbox.call(void 0, linestring);
|
|
137
|
+
if (!doBBoxOverlap(polyBbox, lineBbox)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
var foundInsidePoint = false;
|
|
141
|
+
for (var i = 0; i < linestring.coordinates.length - 1; i++) {
|
|
142
|
+
if (!_booleanpointinpolygon.booleanPointInPolygon.call(void 0, linestring.coordinates[i], polygon)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
if (!foundInsidePoint) {
|
|
146
|
+
foundInsidePoint = _booleanpointinpolygon.booleanPointInPolygon.call(void 0,
|
|
147
|
+
linestring.coordinates[i],
|
|
148
|
+
polygon,
|
|
149
|
+
{ ignoreBoundary: true }
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (!foundInsidePoint) {
|
|
153
|
+
var midpoint = getMidpoint(
|
|
154
|
+
linestring.coordinates[i],
|
|
155
|
+
linestring.coordinates[i + 1]
|
|
156
|
+
);
|
|
157
|
+
foundInsidePoint = _booleanpointinpolygon.booleanPointInPolygon.call(void 0, midpoint, polygon, {
|
|
158
|
+
ignoreBoundary: true
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return foundInsidePoint;
|
|
163
|
+
}
|
|
164
|
+
__name(isLineInPoly, "isLineInPoly");
|
|
165
|
+
function isPolyInPoly(geometry1, geometry2) {
|
|
166
|
+
var poly1Bbox = _bbox.bbox.call(void 0, geometry1);
|
|
167
|
+
var poly2Bbox = _bbox.bbox.call(void 0, geometry2);
|
|
168
|
+
if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
for (var i = 0; i < geometry1.coordinates[0].length; i++) {
|
|
172
|
+
if (!_booleanpointinpolygon.booleanPointInPolygon.call(void 0, geometry1.coordinates[0][i], geometry2)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
__name(isPolyInPoly, "isPolyInPoly");
|
|
179
|
+
function doBBoxOverlap(bbox1, bbox2) {
|
|
180
|
+
if (bbox1[0] > bbox2[0])
|
|
181
|
+
return false;
|
|
182
|
+
if (bbox1[2] < bbox2[2])
|
|
183
|
+
return false;
|
|
184
|
+
if (bbox1[1] > bbox2[1])
|
|
185
|
+
return false;
|
|
186
|
+
if (bbox1[3] < bbox2[3])
|
|
187
|
+
return false;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
__name(doBBoxOverlap, "doBBoxOverlap");
|
|
191
|
+
function compareCoords(pair1, pair2) {
|
|
192
|
+
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
193
|
+
}
|
|
194
|
+
__name(compareCoords, "compareCoords");
|
|
195
|
+
function getMidpoint(pair1, pair2) {
|
|
196
|
+
return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
|
|
197
|
+
}
|
|
198
|
+
__name(getMidpoint, "getMidpoint");
|
|
199
|
+
var turf_boolean_within_default = booleanWithin;
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
exports.booleanWithin = booleanWithin; exports.default = turf_boolean_within_default;
|
|
204
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";;;;A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,cAAc,WAAW,SAAS,GAAG;AACxC,WAAO;AAAA,EACT;AACA,WAAS,IAAI,GAAG,IAAI,UAAU,YAAY,CAAC,EAAE,QAAQ,KAAK;AACxD,QAAI,CAAC,sBAAsB,UAAU,YAAY,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG;AAClE,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAZS;AAcT,SAAS,cAAc,OAAa,OAAa;AAC/C,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,SAAO;AACT;AANS;AAgBT,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAFS;AAYT,SAAS,YAAY,OAAiB,OAAiB;AACrD,SAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;AAC9D;AAFS;AAKT,IAAO,8BAAQ","sourcesContent":["import {\n BBox,\n Feature,\n Geometry,\n LineString,\n MultiPoint,\n MultiPolygon,\n Point,\n Polygon,\n} from \"geojson\";\nimport { bbox as calcBbox } from \"@turf/bbox\";\nimport { booleanPointOnLine } from \"@turf/boolean-point-on-line\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { getGeom } from \"@turf/invariant\";\n\n/**\n * Boolean-within returns true if the first geometry is completely within the second geometry.\n * The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)\n * must not intersect the exterior of the secondary (geometry b).\n * Boolean-within returns the exact opposite result of the `@turf/boolean-contains`.\n *\n * @name booleanWithin\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 line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n * var point = turf.point([1, 2]);\n *\n * turf.booleanWithin(point, line);\n * //=true\n */\nfunction booleanWithin(\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 \"Point\":\n switch (type2) {\n case \"MultiPoint\":\n return isPointInMultiPoint(geom1, geom2);\n case \"LineString\":\n return booleanPointOnLine(geom1, geom2, { ignoreEndVertices: true });\n case \"Polygon\":\n case \"MultiPolygon\":\n return booleanPointInPolygon(geom1, geom2, { ignoreBoundary: true });\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"MultiPoint\":\n switch (type2) {\n case \"MultiPoint\":\n return isMultiPointInMultiPoint(geom1, geom2);\n case \"LineString\":\n return isMultiPointOnLine(geom1, geom2);\n case \"Polygon\":\n case \"MultiPolygon\":\n return isMultiPointInPoly(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"LineString\":\n switch (type2) {\n case \"LineString\":\n return isLineOnLine(geom1, geom2);\n case \"Polygon\":\n case \"MultiPolygon\":\n return isLineInPoly(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"Polygon\":\n switch (type2) {\n case \"Polygon\":\n case \"MultiPolygon\":\n return isPolyInPoly(geom1, geom2);\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 isPointInMultiPoint(point: Point, multiPoint: MultiPoint) {\n var i;\n var output = false;\n for (i = 0; i < multiPoint.coordinates.length; i++) {\n if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {\n output = true;\n break;\n }\n }\n return output;\n}\n\nfunction isMultiPointInMultiPoint(\n multiPoint1: MultiPoint,\n multiPoint2: MultiPoint\n) {\n for (var i = 0; i < multiPoint1.coordinates.length; i++) {\n var anyMatch = false;\n for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {\n if (\n compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])\n ) {\n anyMatch = true;\n }\n }\n if (!anyMatch) {\n return false;\n }\n }\n return true;\n}\n\nfunction isMultiPointOnLine(multiPoint: MultiPoint, lineString: LineString) {\n var foundInsidePoint = false;\n\n for (var i = 0; i < multiPoint.coordinates.length; i++) {\n if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {\n return false;\n }\n if (!foundInsidePoint) {\n foundInsidePoint = booleanPointOnLine(\n multiPoint.coordinates[i],\n lineString,\n { ignoreEndVertices: true }\n );\n }\n }\n return foundInsidePoint;\n}\n\nfunction isMultiPointInPoly(multiPoint: MultiPoint, polygon: Polygon) {\n var output = true;\n var oneInside = false;\n var isInside = false;\n for (var i = 0; i < multiPoint.coordinates.length; i++) {\n isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon);\n if (!isInside) {\n output = false;\n break;\n }\n if (!oneInside) {\n isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon, {\n ignoreBoundary: true,\n });\n }\n }\n return output && isInside;\n}\n\nfunction isLineOnLine(lineString1: LineString, lineString2: LineString) {\n for (var i = 0; i < lineString1.coordinates.length; i++) {\n if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {\n return false;\n }\n }\n return true;\n}\n\nfunction isLineInPoly(linestring: LineString, polygon: Polygon) {\n var polyBbox = calcBbox(polygon);\n var lineBbox = calcBbox(linestring);\n if (!doBBoxOverlap(polyBbox, lineBbox)) {\n return false;\n }\n var foundInsidePoint = false;\n\n for (var i = 0; i < linestring.coordinates.length - 1; i++) {\n if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {\n return false;\n }\n if (!foundInsidePoint) {\n foundInsidePoint = booleanPointInPolygon(\n linestring.coordinates[i],\n polygon,\n { ignoreBoundary: true }\n );\n }\n if (!foundInsidePoint) {\n var midpoint = getMidpoint(\n linestring.coordinates[i],\n linestring.coordinates[i + 1]\n );\n foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {\n ignoreBoundary: true,\n });\n }\n }\n return foundInsidePoint;\n}\n\n/**\n * Is Polygon2 in Polygon1\n * Only takes into account outer rings\n *\n * @private\n * @param {Polygon} geometry1\n * @param {Polygon|MultiPolygon} geometry2\n * @returns {boolean} true/false\n */\nfunction isPolyInPoly(geometry1: Polygon, geometry2: Polygon | MultiPolygon) {\n var poly1Bbox = calcBbox(geometry1);\n var poly2Bbox = calcBbox(geometry2);\n if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {\n return false;\n }\n for (var i = 0; i < geometry1.coordinates[0].length; i++) {\n if (!booleanPointInPolygon(geometry1.coordinates[0][i], geometry2)) {\n return false;\n }\n }\n return true;\n}\n\nfunction doBBoxOverlap(bbox1: BBox, bbox2: BBox) {\n if (bbox1[0] > bbox2[0]) return false;\n if (bbox1[2] < bbox2[2]) return false;\n if (bbox1[1] > bbox2[1]) return false;\n if (bbox1[3] < bbox2[3]) return false;\n return true;\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\n/**\n * getMidpoint\n *\n * @private\n * @param {Position} pair1 point [x,y]\n * @param {Position} pair2 point [x,y]\n * @returns {Position} midpoint of pair1 and pair2\n */\nfunction getMidpoint(pair1: number[], pair2: number[]) {\n return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];\n}\n\nexport { booleanWithin };\nexport default booleanWithin;\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Feature, Geometry } from
|
|
1
|
+
import { Feature, Geometry } from 'geojson';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Boolean-within returns true if the first geometry is completely within the second geometry.
|
|
4
5
|
* The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)
|
|
@@ -17,4 +18,5 @@ import { Feature, Geometry } from "geojson";
|
|
|
17
18
|
* //=true
|
|
18
19
|
*/
|
|
19
20
|
declare function booleanWithin(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
export { booleanWithin, booleanWithin as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Feature, Geometry } from 'geojson';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Boolean-within returns true if the first geometry is completely within the second geometry.
|
|
5
|
+
* The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)
|
|
6
|
+
* must not intersect the exterior of the secondary (geometry b).
|
|
7
|
+
* Boolean-within returns the exact opposite result of the `@turf/boolean-contains`.
|
|
8
|
+
*
|
|
9
|
+
* @name booleanWithin
|
|
10
|
+
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
11
|
+
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
12
|
+
* @returns {boolean} true/false
|
|
13
|
+
* @example
|
|
14
|
+
* var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
15
|
+
* var point = turf.point([1, 2]);
|
|
16
|
+
*
|
|
17
|
+
* turf.booleanWithin(point, line);
|
|
18
|
+
* //=true
|
|
19
|
+
*/
|
|
20
|
+
declare function booleanWithin(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
|
|
21
|
+
|
|
22
|
+
export { booleanWithin, booleanWithin as default };
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// index.ts
|
|
5
|
+
import { bbox as calcBbox } from "@turf/bbox";
|
|
6
|
+
import { booleanPointOnLine } from "@turf/boolean-point-on-line";
|
|
7
|
+
import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
|
|
8
|
+
import { getGeom } from "@turf/invariant";
|
|
9
|
+
function booleanWithin(feature1, feature2) {
|
|
10
|
+
var geom1 = getGeom(feature1);
|
|
11
|
+
var geom2 = getGeom(feature2);
|
|
12
|
+
var type1 = geom1.type;
|
|
13
|
+
var type2 = geom2.type;
|
|
14
|
+
switch (type1) {
|
|
15
|
+
case "Point":
|
|
16
|
+
switch (type2) {
|
|
17
|
+
case "MultiPoint":
|
|
18
|
+
return isPointInMultiPoint(geom1, geom2);
|
|
19
|
+
case "LineString":
|
|
20
|
+
return booleanPointOnLine(geom1, geom2, { ignoreEndVertices: true });
|
|
21
|
+
case "Polygon":
|
|
22
|
+
case "MultiPolygon":
|
|
23
|
+
return booleanPointInPolygon(geom1, geom2, { ignoreBoundary: true });
|
|
24
|
+
default:
|
|
25
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
26
|
+
}
|
|
27
|
+
case "MultiPoint":
|
|
28
|
+
switch (type2) {
|
|
29
|
+
case "MultiPoint":
|
|
30
|
+
return isMultiPointInMultiPoint(geom1, geom2);
|
|
31
|
+
case "LineString":
|
|
32
|
+
return isMultiPointOnLine(geom1, geom2);
|
|
33
|
+
case "Polygon":
|
|
34
|
+
case "MultiPolygon":
|
|
35
|
+
return isMultiPointInPoly(geom1, geom2);
|
|
36
|
+
default:
|
|
37
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
38
|
+
}
|
|
39
|
+
case "LineString":
|
|
40
|
+
switch (type2) {
|
|
41
|
+
case "LineString":
|
|
42
|
+
return isLineOnLine(geom1, geom2);
|
|
43
|
+
case "Polygon":
|
|
44
|
+
case "MultiPolygon":
|
|
45
|
+
return isLineInPoly(geom1, geom2);
|
|
46
|
+
default:
|
|
47
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
48
|
+
}
|
|
49
|
+
case "Polygon":
|
|
50
|
+
switch (type2) {
|
|
51
|
+
case "Polygon":
|
|
52
|
+
case "MultiPolygon":
|
|
53
|
+
return isPolyInPoly(geom1, geom2);
|
|
54
|
+
default:
|
|
55
|
+
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
__name(booleanWithin, "booleanWithin");
|
|
62
|
+
function isPointInMultiPoint(point, multiPoint) {
|
|
63
|
+
var i;
|
|
64
|
+
var output = false;
|
|
65
|
+
for (i = 0; i < multiPoint.coordinates.length; i++) {
|
|
66
|
+
if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
|
|
67
|
+
output = true;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return output;
|
|
72
|
+
}
|
|
73
|
+
__name(isPointInMultiPoint, "isPointInMultiPoint");
|
|
74
|
+
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
|
|
75
|
+
for (var i = 0; i < multiPoint1.coordinates.length; i++) {
|
|
76
|
+
var anyMatch = false;
|
|
77
|
+
for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
|
|
78
|
+
if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
|
|
79
|
+
anyMatch = true;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!anyMatch) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
__name(isMultiPointInMultiPoint, "isMultiPointInMultiPoint");
|
|
89
|
+
function isMultiPointOnLine(multiPoint, lineString) {
|
|
90
|
+
var foundInsidePoint = false;
|
|
91
|
+
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
92
|
+
if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (!foundInsidePoint) {
|
|
96
|
+
foundInsidePoint = booleanPointOnLine(
|
|
97
|
+
multiPoint.coordinates[i],
|
|
98
|
+
lineString,
|
|
99
|
+
{ ignoreEndVertices: true }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return foundInsidePoint;
|
|
104
|
+
}
|
|
105
|
+
__name(isMultiPointOnLine, "isMultiPointOnLine");
|
|
106
|
+
function isMultiPointInPoly(multiPoint, polygon) {
|
|
107
|
+
var output = true;
|
|
108
|
+
var oneInside = false;
|
|
109
|
+
var isInside = false;
|
|
110
|
+
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
111
|
+
isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon);
|
|
112
|
+
if (!isInside) {
|
|
113
|
+
output = false;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (!oneInside) {
|
|
117
|
+
isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon, {
|
|
118
|
+
ignoreBoundary: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return output && isInside;
|
|
123
|
+
}
|
|
124
|
+
__name(isMultiPointInPoly, "isMultiPointInPoly");
|
|
125
|
+
function isLineOnLine(lineString1, lineString2) {
|
|
126
|
+
for (var i = 0; i < lineString1.coordinates.length; i++) {
|
|
127
|
+
if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
__name(isLineOnLine, "isLineOnLine");
|
|
134
|
+
function isLineInPoly(linestring, polygon) {
|
|
135
|
+
var polyBbox = calcBbox(polygon);
|
|
136
|
+
var lineBbox = calcBbox(linestring);
|
|
137
|
+
if (!doBBoxOverlap(polyBbox, lineBbox)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
var foundInsidePoint = false;
|
|
141
|
+
for (var i = 0; i < linestring.coordinates.length - 1; i++) {
|
|
142
|
+
if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
if (!foundInsidePoint) {
|
|
146
|
+
foundInsidePoint = booleanPointInPolygon(
|
|
147
|
+
linestring.coordinates[i],
|
|
148
|
+
polygon,
|
|
149
|
+
{ ignoreBoundary: true }
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (!foundInsidePoint) {
|
|
153
|
+
var midpoint = getMidpoint(
|
|
154
|
+
linestring.coordinates[i],
|
|
155
|
+
linestring.coordinates[i + 1]
|
|
156
|
+
);
|
|
157
|
+
foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {
|
|
158
|
+
ignoreBoundary: true
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return foundInsidePoint;
|
|
163
|
+
}
|
|
164
|
+
__name(isLineInPoly, "isLineInPoly");
|
|
165
|
+
function isPolyInPoly(geometry1, geometry2) {
|
|
166
|
+
var poly1Bbox = calcBbox(geometry1);
|
|
167
|
+
var poly2Bbox = calcBbox(geometry2);
|
|
168
|
+
if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
for (var i = 0; i < geometry1.coordinates[0].length; i++) {
|
|
172
|
+
if (!booleanPointInPolygon(geometry1.coordinates[0][i], geometry2)) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
__name(isPolyInPoly, "isPolyInPoly");
|
|
179
|
+
function doBBoxOverlap(bbox1, bbox2) {
|
|
180
|
+
if (bbox1[0] > bbox2[0])
|
|
181
|
+
return false;
|
|
182
|
+
if (bbox1[2] < bbox2[2])
|
|
183
|
+
return false;
|
|
184
|
+
if (bbox1[1] > bbox2[1])
|
|
185
|
+
return false;
|
|
186
|
+
if (bbox1[3] < bbox2[3])
|
|
187
|
+
return false;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
__name(doBBoxOverlap, "doBBoxOverlap");
|
|
191
|
+
function compareCoords(pair1, pair2) {
|
|
192
|
+
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
193
|
+
}
|
|
194
|
+
__name(compareCoords, "compareCoords");
|
|
195
|
+
function getMidpoint(pair1, pair2) {
|
|
196
|
+
return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
|
|
197
|
+
}
|
|
198
|
+
__name(getMidpoint, "getMidpoint");
|
|
199
|
+
var turf_boolean_within_default = booleanWithin;
|
|
200
|
+
export {
|
|
201
|
+
booleanWithin,
|
|
202
|
+
turf_boolean_within_default as default
|
|
203
|
+
};
|
|
204
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n BBox,\n Feature,\n Geometry,\n LineString,\n MultiPoint,\n MultiPolygon,\n Point,\n Polygon,\n} from \"geojson\";\nimport { bbox as calcBbox } from \"@turf/bbox\";\nimport { booleanPointOnLine } from \"@turf/boolean-point-on-line\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { getGeom } from \"@turf/invariant\";\n\n/**\n * Boolean-within returns true if the first geometry is completely within the second geometry.\n * The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)\n * must not intersect the exterior of the secondary (geometry b).\n * Boolean-within returns the exact opposite result of the `@turf/boolean-contains`.\n *\n * @name booleanWithin\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 line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n * var point = turf.point([1, 2]);\n *\n * turf.booleanWithin(point, line);\n * //=true\n */\nfunction booleanWithin(\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 \"Point\":\n switch (type2) {\n case \"MultiPoint\":\n return isPointInMultiPoint(geom1, geom2);\n case \"LineString\":\n return booleanPointOnLine(geom1, geom2, { ignoreEndVertices: true });\n case \"Polygon\":\n case \"MultiPolygon\":\n return booleanPointInPolygon(geom1, geom2, { ignoreBoundary: true });\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"MultiPoint\":\n switch (type2) {\n case \"MultiPoint\":\n return isMultiPointInMultiPoint(geom1, geom2);\n case \"LineString\":\n return isMultiPointOnLine(geom1, geom2);\n case \"Polygon\":\n case \"MultiPolygon\":\n return isMultiPointInPoly(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"LineString\":\n switch (type2) {\n case \"LineString\":\n return isLineOnLine(geom1, geom2);\n case \"Polygon\":\n case \"MultiPolygon\":\n return isLineInPoly(geom1, geom2);\n default:\n throw new Error(\"feature2 \" + type2 + \" geometry not supported\");\n }\n case \"Polygon\":\n switch (type2) {\n case \"Polygon\":\n case \"MultiPolygon\":\n return isPolyInPoly(geom1, geom2);\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 isPointInMultiPoint(point: Point, multiPoint: MultiPoint) {\n var i;\n var output = false;\n for (i = 0; i < multiPoint.coordinates.length; i++) {\n if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {\n output = true;\n break;\n }\n }\n return output;\n}\n\nfunction isMultiPointInMultiPoint(\n multiPoint1: MultiPoint,\n multiPoint2: MultiPoint\n) {\n for (var i = 0; i < multiPoint1.coordinates.length; i++) {\n var anyMatch = false;\n for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {\n if (\n compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])\n ) {\n anyMatch = true;\n }\n }\n if (!anyMatch) {\n return false;\n }\n }\n return true;\n}\n\nfunction isMultiPointOnLine(multiPoint: MultiPoint, lineString: LineString) {\n var foundInsidePoint = false;\n\n for (var i = 0; i < multiPoint.coordinates.length; i++) {\n if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {\n return false;\n }\n if (!foundInsidePoint) {\n foundInsidePoint = booleanPointOnLine(\n multiPoint.coordinates[i],\n lineString,\n { ignoreEndVertices: true }\n );\n }\n }\n return foundInsidePoint;\n}\n\nfunction isMultiPointInPoly(multiPoint: MultiPoint, polygon: Polygon) {\n var output = true;\n var oneInside = false;\n var isInside = false;\n for (var i = 0; i < multiPoint.coordinates.length; i++) {\n isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon);\n if (!isInside) {\n output = false;\n break;\n }\n if (!oneInside) {\n isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon, {\n ignoreBoundary: true,\n });\n }\n }\n return output && isInside;\n}\n\nfunction isLineOnLine(lineString1: LineString, lineString2: LineString) {\n for (var i = 0; i < lineString1.coordinates.length; i++) {\n if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {\n return false;\n }\n }\n return true;\n}\n\nfunction isLineInPoly(linestring: LineString, polygon: Polygon) {\n var polyBbox = calcBbox(polygon);\n var lineBbox = calcBbox(linestring);\n if (!doBBoxOverlap(polyBbox, lineBbox)) {\n return false;\n }\n var foundInsidePoint = false;\n\n for (var i = 0; i < linestring.coordinates.length - 1; i++) {\n if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {\n return false;\n }\n if (!foundInsidePoint) {\n foundInsidePoint = booleanPointInPolygon(\n linestring.coordinates[i],\n polygon,\n { ignoreBoundary: true }\n );\n }\n if (!foundInsidePoint) {\n var midpoint = getMidpoint(\n linestring.coordinates[i],\n linestring.coordinates[i + 1]\n );\n foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {\n ignoreBoundary: true,\n });\n }\n }\n return foundInsidePoint;\n}\n\n/**\n * Is Polygon2 in Polygon1\n * Only takes into account outer rings\n *\n * @private\n * @param {Polygon} geometry1\n * @param {Polygon|MultiPolygon} geometry2\n * @returns {boolean} true/false\n */\nfunction isPolyInPoly(geometry1: Polygon, geometry2: Polygon | MultiPolygon) {\n var poly1Bbox = calcBbox(geometry1);\n var poly2Bbox = calcBbox(geometry2);\n if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {\n return false;\n }\n for (var i = 0; i < geometry1.coordinates[0].length; i++) {\n if (!booleanPointInPolygon(geometry1.coordinates[0][i], geometry2)) {\n return false;\n }\n }\n return true;\n}\n\nfunction doBBoxOverlap(bbox1: BBox, bbox2: BBox) {\n if (bbox1[0] > bbox2[0]) return false;\n if (bbox1[2] < bbox2[2]) return false;\n if (bbox1[1] > bbox2[1]) return false;\n if (bbox1[3] < bbox2[3]) return false;\n return true;\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\n/**\n * getMidpoint\n *\n * @private\n * @param {Position} pair1 point [x,y]\n * @param {Position} pair2 point [x,y]\n * @returns {Position} midpoint of pair1 and pair2\n */\nfunction getMidpoint(pair1: number[], pair2: number[]) {\n return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];\n}\n\nexport { booleanWithin };\nexport default booleanWithin;\n"],"mappings":";;;;AAUA,SAAS,QAAQ,gBAAgB;AACjC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,eAAe;AAmBxB,SAAS,cACP,UACA,UACS;AACT,MAAI,QAAQ,QAAQ,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,UAAU,YAAY,CAAC,EAAE,CAAC,GAAG,SAAS,GAAG;AAClE,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAZS;AAcT,SAAS,cAAc,OAAa,OAAa;AAC/C,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,MAAI,MAAM,CAAC,IAAI,MAAM,CAAC;AAAG,WAAO;AAChC,SAAO;AACT;AANS;AAgBT,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAFS;AAYT,SAAS,YAAY,OAAiB,OAAiB;AACrD,SAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;AAC9D;AAFS;AAKT,IAAO,8BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/boolean-within",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.110+1411d63a7",
|
|
4
4
|
"description": "turf boolean-within module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"contributors": [
|
|
@@ -27,50 +27,56 @@
|
|
|
27
27
|
"within",
|
|
28
28
|
"boolean-within"
|
|
29
29
|
],
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"type": "commonjs",
|
|
31
|
+
"main": "dist/cjs/index.cjs",
|
|
32
|
+
"module": "dist/esm/index.mjs",
|
|
33
|
+
"types": "dist/cjs/index.d.ts",
|
|
32
34
|
"exports": {
|
|
33
35
|
"./package.json": "./package.json",
|
|
34
36
|
".": {
|
|
35
|
-
"import":
|
|
36
|
-
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/esm/index.d.mts",
|
|
39
|
+
"default": "./dist/esm/index.mjs"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/cjs/index.d.ts",
|
|
43
|
+
"default": "./dist/cjs/index.cjs"
|
|
44
|
+
}
|
|
37
45
|
}
|
|
38
46
|
},
|
|
39
|
-
"types": "dist/js/index.d.ts",
|
|
40
47
|
"sideEffects": false,
|
|
41
48
|
"files": [
|
|
42
49
|
"dist"
|
|
43
50
|
],
|
|
44
51
|
"scripts": {
|
|
45
|
-
"bench": "
|
|
46
|
-
"build": "
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"test": "npm-run-all test:*",
|
|
51
|
-
"test:tape": "ts-node -r esm test.js",
|
|
52
|
+
"bench": "tsx bench.ts",
|
|
53
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
54
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
55
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
56
|
+
"test:tape": "tsx test.ts",
|
|
52
57
|
"test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
|
|
53
58
|
},
|
|
54
59
|
"devDependencies": {
|
|
55
|
-
"@types/
|
|
56
|
-
"
|
|
60
|
+
"@types/benchmark": "^2.1.5",
|
|
61
|
+
"@types/tape": "^4.2.32",
|
|
62
|
+
"benchmark": "^2.1.4",
|
|
57
63
|
"boolean-jsts": "*",
|
|
58
64
|
"boolean-shapely": "*",
|
|
59
|
-
"glob": "
|
|
60
|
-
"load-json-file": "
|
|
61
|
-
"npm-run-all": "
|
|
62
|
-
"tape": "
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"typescript": "
|
|
65
|
+
"glob": "^10.3.10",
|
|
66
|
+
"load-json-file": "^7.0.1",
|
|
67
|
+
"npm-run-all": "^4.1.5",
|
|
68
|
+
"tape": "^5.7.2",
|
|
69
|
+
"tsup": "^8.0.1",
|
|
70
|
+
"tsx": "^4.6.2",
|
|
71
|
+
"typescript": "^5.2.2"
|
|
66
72
|
},
|
|
67
73
|
"dependencies": {
|
|
68
|
-
"@turf/bbox": "^7.0.0-alpha.
|
|
69
|
-
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.
|
|
70
|
-
"@turf/boolean-point-on-line": "^7.0.0-alpha.
|
|
71
|
-
"@turf/helpers": "^7.0.0-alpha.
|
|
72
|
-
"@turf/invariant": "^7.0.0-alpha.
|
|
73
|
-
"tslib": "^2.
|
|
74
|
+
"@turf/bbox": "^7.0.0-alpha.110+1411d63a7",
|
|
75
|
+
"@turf/boolean-point-in-polygon": "^7.0.0-alpha.110+1411d63a7",
|
|
76
|
+
"@turf/boolean-point-on-line": "^7.0.0-alpha.110+1411d63a7",
|
|
77
|
+
"@turf/helpers": "^7.0.0-alpha.110+1411d63a7",
|
|
78
|
+
"@turf/invariant": "^7.0.0-alpha.110+1411d63a7",
|
|
79
|
+
"tslib": "^2.6.2"
|
|
74
80
|
},
|
|
75
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "1411d63a74c275c9216fe48e9d3cb2d48a359068"
|
|
76
82
|
}
|
package/dist/es/index.js
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import calcBbox from "@turf/bbox";
|
|
2
|
-
import booleanPointOnLine from "@turf/boolean-point-on-line";
|
|
3
|
-
import booleanPointInPolygon from "@turf/boolean-point-in-polygon";
|
|
4
|
-
import { getGeom } from "@turf/invariant";
|
|
5
|
-
/**
|
|
6
|
-
* Boolean-within returns true if the first geometry is completely within the second geometry.
|
|
7
|
-
* The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)
|
|
8
|
-
* must not intersect the exterior of the secondary (geometry b).
|
|
9
|
-
* Boolean-within returns the exact opposite result of the `@turf/boolean-contains`.
|
|
10
|
-
*
|
|
11
|
-
* @name booleanWithin
|
|
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 line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
17
|
-
* var point = turf.point([1, 2]);
|
|
18
|
-
*
|
|
19
|
-
* turf.booleanWithin(point, line);
|
|
20
|
-
* //=true
|
|
21
|
-
*/
|
|
22
|
-
function booleanWithin(feature1, feature2) {
|
|
23
|
-
var geom1 = getGeom(feature1);
|
|
24
|
-
var geom2 = getGeom(feature2);
|
|
25
|
-
var type1 = geom1.type;
|
|
26
|
-
var type2 = geom2.type;
|
|
27
|
-
switch (type1) {
|
|
28
|
-
case "Point":
|
|
29
|
-
switch (type2) {
|
|
30
|
-
case "MultiPoint":
|
|
31
|
-
return isPointInMultiPoint(geom1, geom2);
|
|
32
|
-
case "LineString":
|
|
33
|
-
return booleanPointOnLine(geom1, geom2, { ignoreEndVertices: true });
|
|
34
|
-
case "Polygon":
|
|
35
|
-
case "MultiPolygon":
|
|
36
|
-
return booleanPointInPolygon(geom1, geom2, { ignoreBoundary: true });
|
|
37
|
-
default:
|
|
38
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
39
|
-
}
|
|
40
|
-
case "MultiPoint":
|
|
41
|
-
switch (type2) {
|
|
42
|
-
case "MultiPoint":
|
|
43
|
-
return isMultiPointInMultiPoint(geom1, geom2);
|
|
44
|
-
case "LineString":
|
|
45
|
-
return isMultiPointOnLine(geom1, geom2);
|
|
46
|
-
case "Polygon":
|
|
47
|
-
case "MultiPolygon":
|
|
48
|
-
return isMultiPointInPoly(geom1, geom2);
|
|
49
|
-
default:
|
|
50
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
51
|
-
}
|
|
52
|
-
case "LineString":
|
|
53
|
-
switch (type2) {
|
|
54
|
-
case "LineString":
|
|
55
|
-
return isLineOnLine(geom1, geom2);
|
|
56
|
-
case "Polygon":
|
|
57
|
-
case "MultiPolygon":
|
|
58
|
-
return isLineInPoly(geom1, geom2);
|
|
59
|
-
default:
|
|
60
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
61
|
-
}
|
|
62
|
-
case "Polygon":
|
|
63
|
-
switch (type2) {
|
|
64
|
-
case "Polygon":
|
|
65
|
-
case "MultiPolygon":
|
|
66
|
-
return isPolyInPoly(geom1, geom2);
|
|
67
|
-
default:
|
|
68
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
69
|
-
}
|
|
70
|
-
default:
|
|
71
|
-
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function isPointInMultiPoint(point, multiPoint) {
|
|
75
|
-
var i;
|
|
76
|
-
var output = false;
|
|
77
|
-
for (i = 0; i < multiPoint.coordinates.length; i++) {
|
|
78
|
-
if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
|
|
79
|
-
output = true;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return output;
|
|
84
|
-
}
|
|
85
|
-
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
|
|
86
|
-
for (var i = 0; i < multiPoint1.coordinates.length; i++) {
|
|
87
|
-
var anyMatch = false;
|
|
88
|
-
for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
|
|
89
|
-
if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
|
|
90
|
-
anyMatch = true;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (!anyMatch) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return true;
|
|
98
|
-
}
|
|
99
|
-
function isMultiPointOnLine(multiPoint, lineString) {
|
|
100
|
-
var foundInsidePoint = false;
|
|
101
|
-
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
102
|
-
if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
if (!foundInsidePoint) {
|
|
106
|
-
foundInsidePoint = booleanPointOnLine(multiPoint.coordinates[i], lineString, { ignoreEndVertices: true });
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return foundInsidePoint;
|
|
110
|
-
}
|
|
111
|
-
function isMultiPointInPoly(multiPoint, polygon) {
|
|
112
|
-
var output = true;
|
|
113
|
-
var oneInside = false;
|
|
114
|
-
var isInside = false;
|
|
115
|
-
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
116
|
-
isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon);
|
|
117
|
-
if (!isInside) {
|
|
118
|
-
output = false;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
if (!oneInside) {
|
|
122
|
-
isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon, {
|
|
123
|
-
ignoreBoundary: true,
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return output && isInside;
|
|
128
|
-
}
|
|
129
|
-
function isLineOnLine(lineString1, lineString2) {
|
|
130
|
-
for (var i = 0; i < lineString1.coordinates.length; i++) {
|
|
131
|
-
if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return true;
|
|
136
|
-
}
|
|
137
|
-
function isLineInPoly(linestring, polygon) {
|
|
138
|
-
var polyBbox = calcBbox(polygon);
|
|
139
|
-
var lineBbox = calcBbox(linestring);
|
|
140
|
-
if (!doBBoxOverlap(polyBbox, lineBbox)) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
var foundInsidePoint = false;
|
|
144
|
-
for (var i = 0; i < linestring.coordinates.length - 1; i++) {
|
|
145
|
-
if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
if (!foundInsidePoint) {
|
|
149
|
-
foundInsidePoint = booleanPointInPolygon(linestring.coordinates[i], polygon, { ignoreBoundary: true });
|
|
150
|
-
}
|
|
151
|
-
if (!foundInsidePoint) {
|
|
152
|
-
var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
|
|
153
|
-
foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {
|
|
154
|
-
ignoreBoundary: true,
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return foundInsidePoint;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Is Polygon2 in Polygon1
|
|
162
|
-
* Only takes into account outer rings
|
|
163
|
-
*
|
|
164
|
-
* @private
|
|
165
|
-
* @param {Polygon} geometry1
|
|
166
|
-
* @param {Polygon|MultiPolygon} geometry2
|
|
167
|
-
* @returns {boolean} true/false
|
|
168
|
-
*/
|
|
169
|
-
function isPolyInPoly(geometry1, geometry2) {
|
|
170
|
-
var poly1Bbox = calcBbox(geometry1);
|
|
171
|
-
var poly2Bbox = calcBbox(geometry2);
|
|
172
|
-
if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
for (var i = 0; i < geometry1.coordinates[0].length; i++) {
|
|
176
|
-
if (!booleanPointInPolygon(geometry1.coordinates[0][i], geometry2)) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return true;
|
|
181
|
-
}
|
|
182
|
-
function doBBoxOverlap(bbox1, bbox2) {
|
|
183
|
-
if (bbox1[0] > bbox2[0])
|
|
184
|
-
return false;
|
|
185
|
-
if (bbox1[2] < bbox2[2])
|
|
186
|
-
return false;
|
|
187
|
-
if (bbox1[1] > bbox2[1])
|
|
188
|
-
return false;
|
|
189
|
-
if (bbox1[3] < bbox2[3])
|
|
190
|
-
return false;
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* compareCoords
|
|
195
|
-
*
|
|
196
|
-
* @private
|
|
197
|
-
* @param {Position} pair1 point [x,y]
|
|
198
|
-
* @param {Position} pair2 point [x,y]
|
|
199
|
-
* @returns {boolean} true/false if coord pairs match
|
|
200
|
-
*/
|
|
201
|
-
function compareCoords(pair1, pair2) {
|
|
202
|
-
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* getMidpoint
|
|
206
|
-
*
|
|
207
|
-
* @private
|
|
208
|
-
* @param {Position} pair1 point [x,y]
|
|
209
|
-
* @param {Position} pair2 point [x,y]
|
|
210
|
-
* @returns {Position} midpoint of pair1 and pair2
|
|
211
|
-
*/
|
|
212
|
-
function getMidpoint(pair1, pair2) {
|
|
213
|
-
return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
|
|
214
|
-
}
|
|
215
|
-
export default booleanWithin;
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const bbox_1 = tslib_1.__importDefault(require("@turf/bbox"));
|
|
5
|
-
const boolean_point_on_line_1 = tslib_1.__importDefault(require("@turf/boolean-point-on-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
|
-
/**
|
|
9
|
-
* Boolean-within returns true if the first geometry is completely within the second geometry.
|
|
10
|
-
* The interiors of both geometries must intersect and, the interior and boundary of the primary (geometry a)
|
|
11
|
-
* must not intersect the exterior of the secondary (geometry b).
|
|
12
|
-
* Boolean-within returns the exact opposite result of the `@turf/boolean-contains`.
|
|
13
|
-
*
|
|
14
|
-
* @name booleanWithin
|
|
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 line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
|
|
20
|
-
* var point = turf.point([1, 2]);
|
|
21
|
-
*
|
|
22
|
-
* turf.booleanWithin(point, line);
|
|
23
|
-
* //=true
|
|
24
|
-
*/
|
|
25
|
-
function booleanWithin(feature1, feature2) {
|
|
26
|
-
var geom1 = invariant_1.getGeom(feature1);
|
|
27
|
-
var geom2 = invariant_1.getGeom(feature2);
|
|
28
|
-
var type1 = geom1.type;
|
|
29
|
-
var type2 = geom2.type;
|
|
30
|
-
switch (type1) {
|
|
31
|
-
case "Point":
|
|
32
|
-
switch (type2) {
|
|
33
|
-
case "MultiPoint":
|
|
34
|
-
return isPointInMultiPoint(geom1, geom2);
|
|
35
|
-
case "LineString":
|
|
36
|
-
return boolean_point_on_line_1.default(geom1, geom2, { ignoreEndVertices: true });
|
|
37
|
-
case "Polygon":
|
|
38
|
-
case "MultiPolygon":
|
|
39
|
-
return boolean_point_in_polygon_1.default(geom1, geom2, { ignoreBoundary: true });
|
|
40
|
-
default:
|
|
41
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
42
|
-
}
|
|
43
|
-
case "MultiPoint":
|
|
44
|
-
switch (type2) {
|
|
45
|
-
case "MultiPoint":
|
|
46
|
-
return isMultiPointInMultiPoint(geom1, geom2);
|
|
47
|
-
case "LineString":
|
|
48
|
-
return isMultiPointOnLine(geom1, geom2);
|
|
49
|
-
case "Polygon":
|
|
50
|
-
case "MultiPolygon":
|
|
51
|
-
return isMultiPointInPoly(geom1, geom2);
|
|
52
|
-
default:
|
|
53
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
54
|
-
}
|
|
55
|
-
case "LineString":
|
|
56
|
-
switch (type2) {
|
|
57
|
-
case "LineString":
|
|
58
|
-
return isLineOnLine(geom1, geom2);
|
|
59
|
-
case "Polygon":
|
|
60
|
-
case "MultiPolygon":
|
|
61
|
-
return isLineInPoly(geom1, geom2);
|
|
62
|
-
default:
|
|
63
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
64
|
-
}
|
|
65
|
-
case "Polygon":
|
|
66
|
-
switch (type2) {
|
|
67
|
-
case "Polygon":
|
|
68
|
-
case "MultiPolygon":
|
|
69
|
-
return isPolyInPoly(geom1, geom2);
|
|
70
|
-
default:
|
|
71
|
-
throw new Error("feature2 " + type2 + " geometry not supported");
|
|
72
|
-
}
|
|
73
|
-
default:
|
|
74
|
-
throw new Error("feature1 " + type1 + " geometry not supported");
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
function isPointInMultiPoint(point, multiPoint) {
|
|
78
|
-
var i;
|
|
79
|
-
var output = false;
|
|
80
|
-
for (i = 0; i < multiPoint.coordinates.length; i++) {
|
|
81
|
-
if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
|
|
82
|
-
output = true;
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return output;
|
|
87
|
-
}
|
|
88
|
-
function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
|
|
89
|
-
for (var i = 0; i < multiPoint1.coordinates.length; i++) {
|
|
90
|
-
var anyMatch = false;
|
|
91
|
-
for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
|
|
92
|
-
if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
|
|
93
|
-
anyMatch = true;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (!anyMatch) {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
function isMultiPointOnLine(multiPoint, lineString) {
|
|
103
|
-
var foundInsidePoint = false;
|
|
104
|
-
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
105
|
-
if (!boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString)) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
if (!foundInsidePoint) {
|
|
109
|
-
foundInsidePoint = boolean_point_on_line_1.default(multiPoint.coordinates[i], lineString, { ignoreEndVertices: true });
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return foundInsidePoint;
|
|
113
|
-
}
|
|
114
|
-
function isMultiPointInPoly(multiPoint, polygon) {
|
|
115
|
-
var output = true;
|
|
116
|
-
var oneInside = false;
|
|
117
|
-
var isInside = false;
|
|
118
|
-
for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
|
119
|
-
isInside = boolean_point_in_polygon_1.default(multiPoint.coordinates[i], polygon);
|
|
120
|
-
if (!isInside) {
|
|
121
|
-
output = false;
|
|
122
|
-
break;
|
|
123
|
-
}
|
|
124
|
-
if (!oneInside) {
|
|
125
|
-
isInside = boolean_point_in_polygon_1.default(multiPoint.coordinates[i], polygon, {
|
|
126
|
-
ignoreBoundary: true,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return output && isInside;
|
|
131
|
-
}
|
|
132
|
-
function isLineOnLine(lineString1, lineString2) {
|
|
133
|
-
for (var i = 0; i < lineString1.coordinates.length; i++) {
|
|
134
|
-
if (!boolean_point_on_line_1.default(lineString1.coordinates[i], lineString2)) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
function isLineInPoly(linestring, polygon) {
|
|
141
|
-
var polyBbox = bbox_1.default(polygon);
|
|
142
|
-
var lineBbox = bbox_1.default(linestring);
|
|
143
|
-
if (!doBBoxOverlap(polyBbox, lineBbox)) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
var foundInsidePoint = false;
|
|
147
|
-
for (var i = 0; i < linestring.coordinates.length - 1; i++) {
|
|
148
|
-
if (!boolean_point_in_polygon_1.default(linestring.coordinates[i], polygon)) {
|
|
149
|
-
return false;
|
|
150
|
-
}
|
|
151
|
-
if (!foundInsidePoint) {
|
|
152
|
-
foundInsidePoint = boolean_point_in_polygon_1.default(linestring.coordinates[i], polygon, { ignoreBoundary: true });
|
|
153
|
-
}
|
|
154
|
-
if (!foundInsidePoint) {
|
|
155
|
-
var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
|
|
156
|
-
foundInsidePoint = boolean_point_in_polygon_1.default(midpoint, polygon, {
|
|
157
|
-
ignoreBoundary: true,
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return foundInsidePoint;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Is Polygon2 in Polygon1
|
|
165
|
-
* Only takes into account outer rings
|
|
166
|
-
*
|
|
167
|
-
* @private
|
|
168
|
-
* @param {Polygon} geometry1
|
|
169
|
-
* @param {Polygon|MultiPolygon} geometry2
|
|
170
|
-
* @returns {boolean} true/false
|
|
171
|
-
*/
|
|
172
|
-
function isPolyInPoly(geometry1, geometry2) {
|
|
173
|
-
var poly1Bbox = bbox_1.default(geometry1);
|
|
174
|
-
var poly2Bbox = bbox_1.default(geometry2);
|
|
175
|
-
if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
for (var i = 0; i < geometry1.coordinates[0].length; i++) {
|
|
179
|
-
if (!boolean_point_in_polygon_1.default(geometry1.coordinates[0][i], geometry2)) {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return true;
|
|
184
|
-
}
|
|
185
|
-
function doBBoxOverlap(bbox1, bbox2) {
|
|
186
|
-
if (bbox1[0] > bbox2[0])
|
|
187
|
-
return false;
|
|
188
|
-
if (bbox1[2] < bbox2[2])
|
|
189
|
-
return false;
|
|
190
|
-
if (bbox1[1] > bbox2[1])
|
|
191
|
-
return false;
|
|
192
|
-
if (bbox1[3] < bbox2[3])
|
|
193
|
-
return false;
|
|
194
|
-
return true;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* compareCoords
|
|
198
|
-
*
|
|
199
|
-
* @private
|
|
200
|
-
* @param {Position} pair1 point [x,y]
|
|
201
|
-
* @param {Position} pair2 point [x,y]
|
|
202
|
-
* @returns {boolean} true/false if coord pairs match
|
|
203
|
-
*/
|
|
204
|
-
function compareCoords(pair1, pair2) {
|
|
205
|
-
return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* getMidpoint
|
|
209
|
-
*
|
|
210
|
-
* @private
|
|
211
|
-
* @param {Position} pair1 point [x,y]
|
|
212
|
-
* @param {Position} pair2 point [x,y]
|
|
213
|
-
* @returns {Position} midpoint of pair1 and pair2
|
|
214
|
-
*/
|
|
215
|
-
function getMidpoint(pair1, pair2) {
|
|
216
|
-
return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
|
|
217
|
-
}
|
|
218
|
-
exports.default = booleanWithin;
|