@turf/boolean-within 7.0.0-alpha.2 → 7.1.0-alpha.7

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 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](http://turfjs.org/), an open source
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 Turf module that includes it as a function:
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,190 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
2
+ var _bbox = require('@turf/bbox');
3
+ var _booleanpointonline = require('@turf/boolean-point-on-line');
4
+ var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
5
+ var _invariant = require('@turf/invariant');
6
+ function booleanWithin(feature1, feature2) {
7
+ var geom1 = _invariant.getGeom.call(void 0, feature1);
8
+ var geom2 = _invariant.getGeom.call(void 0, feature2);
9
+ var type1 = geom1.type;
10
+ var type2 = geom2.type;
11
+ switch (type1) {
12
+ case "Point":
13
+ switch (type2) {
14
+ case "MultiPoint":
15
+ return isPointInMultiPoint(geom1, geom2);
16
+ case "LineString":
17
+ return _booleanpointonline.booleanPointOnLine.call(void 0, geom1, geom2, { ignoreEndVertices: true });
18
+ case "Polygon":
19
+ case "MultiPolygon":
20
+ return _booleanpointinpolygon.booleanPointInPolygon.call(void 0, geom1, geom2, { ignoreBoundary: true });
21
+ default:
22
+ throw new Error("feature2 " + type2 + " geometry not supported");
23
+ }
24
+ case "MultiPoint":
25
+ switch (type2) {
26
+ case "MultiPoint":
27
+ return isMultiPointInMultiPoint(geom1, geom2);
28
+ case "LineString":
29
+ return isMultiPointOnLine(geom1, geom2);
30
+ case "Polygon":
31
+ case "MultiPolygon":
32
+ return isMultiPointInPoly(geom1, geom2);
33
+ default:
34
+ throw new Error("feature2 " + type2 + " geometry not supported");
35
+ }
36
+ case "LineString":
37
+ switch (type2) {
38
+ case "LineString":
39
+ return isLineOnLine(geom1, geom2);
40
+ case "Polygon":
41
+ case "MultiPolygon":
42
+ return isLineInPoly(geom1, geom2);
43
+ default:
44
+ throw new Error("feature2 " + type2 + " geometry not supported");
45
+ }
46
+ case "Polygon":
47
+ switch (type2) {
48
+ case "Polygon":
49
+ case "MultiPolygon":
50
+ return isPolyInPoly(geom1, geom2);
51
+ default:
52
+ throw new Error("feature2 " + type2 + " geometry not supported");
53
+ }
54
+ default:
55
+ throw new Error("feature1 " + type1 + " geometry not supported");
56
+ }
57
+ }
58
+ function isPointInMultiPoint(point, multiPoint) {
59
+ var i;
60
+ var output = false;
61
+ for (i = 0; i < multiPoint.coordinates.length; i++) {
62
+ if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
63
+ output = true;
64
+ break;
65
+ }
66
+ }
67
+ return output;
68
+ }
69
+ function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
70
+ for (var i = 0; i < multiPoint1.coordinates.length; i++) {
71
+ var anyMatch = false;
72
+ for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
73
+ if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
74
+ anyMatch = true;
75
+ }
76
+ }
77
+ if (!anyMatch) {
78
+ return false;
79
+ }
80
+ }
81
+ return true;
82
+ }
83
+ function isMultiPointOnLine(multiPoint, lineString) {
84
+ var foundInsidePoint = false;
85
+ for (var i = 0; i < multiPoint.coordinates.length; i++) {
86
+ if (!_booleanpointonline.booleanPointOnLine.call(void 0, multiPoint.coordinates[i], lineString)) {
87
+ return false;
88
+ }
89
+ if (!foundInsidePoint) {
90
+ foundInsidePoint = _booleanpointonline.booleanPointOnLine.call(void 0,
91
+ multiPoint.coordinates[i],
92
+ lineString,
93
+ { ignoreEndVertices: true }
94
+ );
95
+ }
96
+ }
97
+ return foundInsidePoint;
98
+ }
99
+ function isMultiPointInPoly(multiPoint, polygon) {
100
+ var output = true;
101
+ var oneInside = false;
102
+ var isInside = false;
103
+ for (var i = 0; i < multiPoint.coordinates.length; i++) {
104
+ isInside = _booleanpointinpolygon.booleanPointInPolygon.call(void 0, multiPoint.coordinates[i], polygon);
105
+ if (!isInside) {
106
+ output = false;
107
+ break;
108
+ }
109
+ if (!oneInside) {
110
+ isInside = _booleanpointinpolygon.booleanPointInPolygon.call(void 0, multiPoint.coordinates[i], polygon, {
111
+ ignoreBoundary: true
112
+ });
113
+ }
114
+ }
115
+ return output && isInside;
116
+ }
117
+ function isLineOnLine(lineString1, lineString2) {
118
+ for (var i = 0; i < lineString1.coordinates.length; i++) {
119
+ if (!_booleanpointonline.booleanPointOnLine.call(void 0, lineString1.coordinates[i], lineString2)) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ function isLineInPoly(linestring, polygon) {
126
+ var polyBbox = _bbox.bbox.call(void 0, polygon);
127
+ var lineBbox = _bbox.bbox.call(void 0, linestring);
128
+ if (!doBBoxOverlap(polyBbox, lineBbox)) {
129
+ return false;
130
+ }
131
+ var foundInsidePoint = false;
132
+ for (var i = 0; i < linestring.coordinates.length; i++) {
133
+ if (!_booleanpointinpolygon.booleanPointInPolygon.call(void 0, linestring.coordinates[i], polygon)) {
134
+ return false;
135
+ }
136
+ if (!foundInsidePoint) {
137
+ foundInsidePoint = _booleanpointinpolygon.booleanPointInPolygon.call(void 0,
138
+ linestring.coordinates[i],
139
+ polygon,
140
+ { ignoreBoundary: true }
141
+ );
142
+ }
143
+ if (!foundInsidePoint && i < linestring.coordinates.length - 1) {
144
+ var midpoint = getMidpoint(
145
+ linestring.coordinates[i],
146
+ linestring.coordinates[i + 1]
147
+ );
148
+ foundInsidePoint = _booleanpointinpolygon.booleanPointInPolygon.call(void 0, midpoint, polygon, {
149
+ ignoreBoundary: true
150
+ });
151
+ }
152
+ }
153
+ return foundInsidePoint;
154
+ }
155
+ function isPolyInPoly(geometry1, geometry2) {
156
+ var poly1Bbox = _bbox.bbox.call(void 0, geometry1);
157
+ var poly2Bbox = _bbox.bbox.call(void 0, geometry2);
158
+ if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
159
+ return false;
160
+ }
161
+ for (var i = 0; i < geometry1.coordinates[0].length; i++) {
162
+ if (!_booleanpointinpolygon.booleanPointInPolygon.call(void 0, geometry1.coordinates[0][i], geometry2)) {
163
+ return false;
164
+ }
165
+ }
166
+ return true;
167
+ }
168
+ function doBBoxOverlap(bbox1, bbox2) {
169
+ if (bbox1[0] > bbox2[0])
170
+ return false;
171
+ if (bbox1[2] < bbox2[2])
172
+ return false;
173
+ if (bbox1[1] > bbox2[1])
174
+ return false;
175
+ if (bbox1[3] < bbox2[3])
176
+ return false;
177
+ return true;
178
+ }
179
+ function compareCoords(pair1, pair2) {
180
+ return pair1[0] === pair2[0] && pair1[1] === pair2[1];
181
+ }
182
+ function getMidpoint(pair1, pair2) {
183
+ return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
184
+ }
185
+ var turf_boolean_within_default = booleanWithin;
186
+
187
+
188
+
189
+ exports.booleanWithin = booleanWithin; exports.default = turf_boolean_within_default;
190
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAUA,SAAS,QAAQ,gBAAgB;AACjC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,eAAe;AAmBxB,SAAS,cACP,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,oBAAoB,OAAO,KAAK;AAAA,QACzC,KAAK;AACH,iBAAO,mBAAmB,OAAO,OAAO,EAAE,mBAAmB,KAAK,CAAC;AAAA,QACrE,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,sBAAsB,OAAO,OAAO,EAAE,gBAAgB,KAAK,CAAC;AAAA,QACrE;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,yBAAyB,OAAO,KAAK;AAAA,QAC9C,KAAK;AACH,iBAAO,mBAAmB,OAAO,KAAK;AAAA,QACxC,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,mBAAmB,OAAO,KAAK;AAAA,QACxC;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,aAAa,OAAO,KAAK;AAAA,QAClC,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,aAAa,OAAO,KAAK;AAAA,QAClC;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO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AAS,aAAa,WAAoB,WAAmC;AAC3E,MAAI,YAAY,SAAS,SAAS;AAClC,MAAI,YAAY,SAAS,SAAS;AAClC,MAAI,CAAC,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;AAEA,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;AAUA,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAUA,SAAS,YAAY,OAAiB,OAAiB;AACrD,SAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;AAC9D;AAGA,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; 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 && i < linestring.coordinates.length - 1) {\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"]}
@@ -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 };
@@ -1,4 +1,5 @@
1
- import { Feature, Geometry } from "geojson";
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
- export default booleanWithin;
21
+
22
+ export { booleanWithin, booleanWithin as default };
@@ -0,0 +1,190 @@
1
+ // index.ts
2
+ import { bbox as calcBbox } from "@turf/bbox";
3
+ import { booleanPointOnLine } from "@turf/boolean-point-on-line";
4
+ import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
5
+ import { getGeom } from "@turf/invariant";
6
+ function booleanWithin(feature1, feature2) {
7
+ var geom1 = getGeom(feature1);
8
+ var geom2 = getGeom(feature2);
9
+ var type1 = geom1.type;
10
+ var type2 = geom2.type;
11
+ switch (type1) {
12
+ case "Point":
13
+ switch (type2) {
14
+ case "MultiPoint":
15
+ return isPointInMultiPoint(geom1, geom2);
16
+ case "LineString":
17
+ return booleanPointOnLine(geom1, geom2, { ignoreEndVertices: true });
18
+ case "Polygon":
19
+ case "MultiPolygon":
20
+ return booleanPointInPolygon(geom1, geom2, { ignoreBoundary: true });
21
+ default:
22
+ throw new Error("feature2 " + type2 + " geometry not supported");
23
+ }
24
+ case "MultiPoint":
25
+ switch (type2) {
26
+ case "MultiPoint":
27
+ return isMultiPointInMultiPoint(geom1, geom2);
28
+ case "LineString":
29
+ return isMultiPointOnLine(geom1, geom2);
30
+ case "Polygon":
31
+ case "MultiPolygon":
32
+ return isMultiPointInPoly(geom1, geom2);
33
+ default:
34
+ throw new Error("feature2 " + type2 + " geometry not supported");
35
+ }
36
+ case "LineString":
37
+ switch (type2) {
38
+ case "LineString":
39
+ return isLineOnLine(geom1, geom2);
40
+ case "Polygon":
41
+ case "MultiPolygon":
42
+ return isLineInPoly(geom1, geom2);
43
+ default:
44
+ throw new Error("feature2 " + type2 + " geometry not supported");
45
+ }
46
+ case "Polygon":
47
+ switch (type2) {
48
+ case "Polygon":
49
+ case "MultiPolygon":
50
+ return isPolyInPoly(geom1, geom2);
51
+ default:
52
+ throw new Error("feature2 " + type2 + " geometry not supported");
53
+ }
54
+ default:
55
+ throw new Error("feature1 " + type1 + " geometry not supported");
56
+ }
57
+ }
58
+ function isPointInMultiPoint(point, multiPoint) {
59
+ var i;
60
+ var output = false;
61
+ for (i = 0; i < multiPoint.coordinates.length; i++) {
62
+ if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
63
+ output = true;
64
+ break;
65
+ }
66
+ }
67
+ return output;
68
+ }
69
+ function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
70
+ for (var i = 0; i < multiPoint1.coordinates.length; i++) {
71
+ var anyMatch = false;
72
+ for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
73
+ if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
74
+ anyMatch = true;
75
+ }
76
+ }
77
+ if (!anyMatch) {
78
+ return false;
79
+ }
80
+ }
81
+ return true;
82
+ }
83
+ function isMultiPointOnLine(multiPoint, lineString) {
84
+ var foundInsidePoint = false;
85
+ for (var i = 0; i < multiPoint.coordinates.length; i++) {
86
+ if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {
87
+ return false;
88
+ }
89
+ if (!foundInsidePoint) {
90
+ foundInsidePoint = booleanPointOnLine(
91
+ multiPoint.coordinates[i],
92
+ lineString,
93
+ { ignoreEndVertices: true }
94
+ );
95
+ }
96
+ }
97
+ return foundInsidePoint;
98
+ }
99
+ function isMultiPointInPoly(multiPoint, polygon) {
100
+ var output = true;
101
+ var oneInside = false;
102
+ var isInside = false;
103
+ for (var i = 0; i < multiPoint.coordinates.length; i++) {
104
+ isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon);
105
+ if (!isInside) {
106
+ output = false;
107
+ break;
108
+ }
109
+ if (!oneInside) {
110
+ isInside = booleanPointInPolygon(multiPoint.coordinates[i], polygon, {
111
+ ignoreBoundary: true
112
+ });
113
+ }
114
+ }
115
+ return output && isInside;
116
+ }
117
+ function isLineOnLine(lineString1, lineString2) {
118
+ for (var i = 0; i < lineString1.coordinates.length; i++) {
119
+ if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {
120
+ return false;
121
+ }
122
+ }
123
+ return true;
124
+ }
125
+ function isLineInPoly(linestring, polygon) {
126
+ var polyBbox = calcBbox(polygon);
127
+ var lineBbox = calcBbox(linestring);
128
+ if (!doBBoxOverlap(polyBbox, lineBbox)) {
129
+ return false;
130
+ }
131
+ var foundInsidePoint = false;
132
+ for (var i = 0; i < linestring.coordinates.length; i++) {
133
+ if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
134
+ return false;
135
+ }
136
+ if (!foundInsidePoint) {
137
+ foundInsidePoint = booleanPointInPolygon(
138
+ linestring.coordinates[i],
139
+ polygon,
140
+ { ignoreBoundary: true }
141
+ );
142
+ }
143
+ if (!foundInsidePoint && i < linestring.coordinates.length - 1) {
144
+ var midpoint = getMidpoint(
145
+ linestring.coordinates[i],
146
+ linestring.coordinates[i + 1]
147
+ );
148
+ foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {
149
+ ignoreBoundary: true
150
+ });
151
+ }
152
+ }
153
+ return foundInsidePoint;
154
+ }
155
+ function isPolyInPoly(geometry1, geometry2) {
156
+ var poly1Bbox = calcBbox(geometry1);
157
+ var poly2Bbox = calcBbox(geometry2);
158
+ if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
159
+ return false;
160
+ }
161
+ for (var i = 0; i < geometry1.coordinates[0].length; i++) {
162
+ if (!booleanPointInPolygon(geometry1.coordinates[0][i], geometry2)) {
163
+ return false;
164
+ }
165
+ }
166
+ return true;
167
+ }
168
+ function doBBoxOverlap(bbox1, bbox2) {
169
+ if (bbox1[0] > bbox2[0])
170
+ return false;
171
+ if (bbox1[2] < bbox2[2])
172
+ return false;
173
+ if (bbox1[1] > bbox2[1])
174
+ return false;
175
+ if (bbox1[3] < bbox2[3])
176
+ return false;
177
+ return true;
178
+ }
179
+ function compareCoords(pair1, pair2) {
180
+ return pair1[0] === pair2[0] && pair1[1] === pair2[1];
181
+ }
182
+ function getMidpoint(pair1, pair2) {
183
+ return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
184
+ }
185
+ var turf_boolean_within_default = booleanWithin;
186
+ export {
187
+ booleanWithin,
188
+ turf_boolean_within_default as default
189
+ };
190
+ //# sourceMappingURL=index.js.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; 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 && i < linestring.coordinates.length - 1) {\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,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,oBAAoB,OAAO,KAAK;AAAA,QACzC,KAAK;AACH,iBAAO,mBAAmB,OAAO,OAAO,EAAE,mBAAmB,KAAK,CAAC;AAAA,QACrE,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,sBAAsB,OAAO,OAAO,EAAE,gBAAgB,KAAK,CAAC;AAAA,QACrE;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,yBAAyB,OAAO,KAAK;AAAA,QAC9C,KAAK;AACH,iBAAO,mBAAmB,OAAO,KAAK;AAAA,QACxC,KAAK;AAAA,QACL,KAAK;AACH,iBAAO,mBAAmB,OAAO,KAAK;AAAA,QACxC;AACE,gBAAM,IAAI,MAAM,cAAc,QAAQ,yBAAyB;AAAA,MACnE;AAAA,IACF,KAAK;AACH,cAAQ,OAAO;AAAA,QACb,KAAK;AACH,iBAAO,aAAa,OAAO,KAAK;AAAA,QAClC,KAAK;AAAA,QACL,KAA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AAC;AAAA,MAC9B;AACA,yBAAmB,sBAAsB,UAAU,SAAS;AAAA,QAC1D,gBAAgB;AAAA,MAClB,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;AAWA,SAAS,aAAa,WAAoB,WAAmC;AAC3E,MAAI,YAAY,SAAS,SAAS;AAClC,MAAI,YAAY,SAAS,SAAS;AAClC,MAAI,CAAC,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;AAEA,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;AAUA,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAUA,SAAS,YAAY,OAAiB,OAAiB;AACrD,SAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC;AAC9D;AAGA,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.2",
3
+ "version": "7.1.0-alpha.7+0ce6ecca0",
4
4
  "description": "turf boolean-within module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -27,51 +27,56 @@
27
27
  "within",
28
28
  "boolean-within"
29
29
  ],
30
- "main": "dist/js/index.js",
31
- "module": "dist/es/index.js",
30
+ "type": "module",
31
+ "main": "dist/cjs/index.cjs",
32
+ "module": "dist/esm/index.js",
33
+ "types": "dist/esm/index.d.ts",
32
34
  "exports": {
33
35
  "./package.json": "./package.json",
34
36
  ".": {
35
- "types": "./dist/js/index.d.ts",
36
- "import": "./dist/es/index.js",
37
- "require": "./dist/js/index.js"
37
+ "import": {
38
+ "types": "./dist/esm/index.d.ts",
39
+ "default": "./dist/esm/index.js"
40
+ },
41
+ "require": {
42
+ "types": "./dist/cjs/index.d.cts",
43
+ "default": "./dist/cjs/index.cjs"
44
+ }
38
45
  }
39
46
  },
40
- "types": "dist/js/index.d.ts",
41
47
  "sideEffects": false,
42
48
  "files": [
43
49
  "dist"
44
50
  ],
45
51
  "scripts": {
46
- "bench": "tsx bench.js",
47
- "build": "npm-run-all build:*",
48
- "build:es": "tsc --outDir dist/es --module esnext --declaration false && echo '{\"type\":\"module\"}' > dist/es/package.json",
49
- "build:js": "tsc",
50
- "docs": "tsx ../../scripts/generate-readmes",
51
- "test": "npm-run-all test:*",
52
- "test:tape": "tsx test.js",
53
- "test:types": "tsc --esModuleInterop --noEmit --strict types.ts"
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",
57
+ "test:types": "tsc --esModuleInterop --module node16 --moduleResolution node16 --noEmit --strict types.ts"
54
58
  },
55
59
  "devDependencies": {
56
- "@types/tape": "*",
57
- "benchmark": "*",
60
+ "@types/benchmark": "^2.1.5",
61
+ "@types/tape": "^4.2.32",
62
+ "benchmark": "^2.1.4",
58
63
  "boolean-jsts": "*",
59
64
  "boolean-shapely": "*",
60
- "glob": "*",
61
- "load-json-file": "*",
62
- "npm-run-all": "*",
63
- "tape": "*",
64
- "tslint": "*",
65
- "tsx": "*",
66
- "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"
67
72
  },
68
73
  "dependencies": {
69
- "@turf/bbox": "^7.0.0-alpha.2",
70
- "@turf/boolean-point-in-polygon": "^7.0.0-alpha.2",
71
- "@turf/boolean-point-on-line": "^7.0.0-alpha.2",
72
- "@turf/helpers": "^7.0.0-alpha.2",
73
- "@turf/invariant": "^7.0.0-alpha.2",
74
- "tslib": "^2.3.0"
74
+ "@turf/bbox": "^7.1.0-alpha.7+0ce6ecca0",
75
+ "@turf/boolean-point-in-polygon": "^7.1.0-alpha.7+0ce6ecca0",
76
+ "@turf/boolean-point-on-line": "^7.1.0-alpha.7+0ce6ecca0",
77
+ "@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
78
+ "@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0",
79
+ "tslib": "^2.6.2"
75
80
  },
76
- "gitHead": "dd35b52725945b4fa29a98d9a550733e06cc222e"
81
+ "gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
77
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;
@@ -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;