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