@turf/boolean-disjoint 7.0.0 → 7.1.0-alpha.70

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
@@ -10,6 +10,9 @@ Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an
10
10
 
11
11
  * `feature1` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry
12
12
  * `feature2` **([Geometry][1] | [Feature][2]\<any>)** GeoJSON Feature or Geometry
13
+ * `options` **[Object][3]** Optional parameters (optional, default `{}`)
14
+
15
+ * `options.ignoreSelfIntersections` **[boolean][4]** ignores self-intersections on input features (optional, default `false`)
13
16
 
14
17
  ### Examples
15
18
 
@@ -21,13 +24,15 @@ turf.booleanDisjoint(line, point);
21
24
  //=true
22
25
  ```
23
26
 
24
- Returns **[boolean][3]** true/false
27
+ Returns **[boolean][4]** true if the intersection is an empty set, false otherwise
25
28
 
26
29
  [1]: https://tools.ietf.org/html/rfc7946#section-3.1
27
30
 
28
31
  [2]: https://tools.ietf.org/html/rfc7946#section-3.2
29
32
 
30
- [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
33
+ [3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
34
+
35
+ [4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
31
36
 
32
37
  <!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. -->
33
38
 
@@ -1,25 +1,27 @@
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
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.ts
5
2
  var _booleanpointinpolygon = require('@turf/boolean-point-in-polygon');
6
3
  var _lineintersect = require('@turf/line-intersect');
7
4
  var _meta = require('@turf/meta');
8
5
  var _polygontoline = require('@turf/polygon-to-line');
9
- function booleanDisjoint(feature1, feature2) {
6
+ function booleanDisjoint(feature1, feature2, options = {}) {
7
+ var _a;
8
+ const ignoreSelfIntersections = (_a = options.ignoreSelfIntersections) != null ? _a : false;
10
9
  let bool = true;
11
10
  _meta.flattenEach.call(void 0, feature1, (flatten1) => {
12
11
  _meta.flattenEach.call(void 0, feature2, (flatten2) => {
13
12
  if (bool === false) {
14
13
  return false;
15
14
  }
16
- bool = disjoint(flatten1.geometry, flatten2.geometry);
15
+ bool = disjoint(
16
+ flatten1.geometry,
17
+ flatten2.geometry,
18
+ ignoreSelfIntersections
19
+ );
17
20
  });
18
21
  });
19
22
  return bool;
20
23
  }
21
- __name(booleanDisjoint, "booleanDisjoint");
22
- function disjoint(geom1, geom2) {
24
+ function disjoint(geom1, geom2, ignoreSelfIntersections) {
23
25
  switch (geom1.type) {
24
26
  case "Point":
25
27
  switch (geom2.type) {
@@ -36,9 +38,9 @@ function disjoint(geom1, geom2) {
36
38
  case "Point":
37
39
  return !isPointOnLine(geom1, geom2);
38
40
  case "LineString":
39
- return !isLineOnLine(geom1, geom2);
41
+ return !isLineOnLine(geom1, geom2, ignoreSelfIntersections);
40
42
  case "Polygon":
41
- return !isLineInPoly(geom2, geom1);
43
+ return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);
42
44
  }
43
45
  break;
44
46
  case "Polygon":
@@ -46,14 +48,13 @@ function disjoint(geom1, geom2) {
46
48
  case "Point":
47
49
  return !_booleanpointinpolygon.booleanPointInPolygon.call(void 0, geom2, geom1);
48
50
  case "LineString":
49
- return !isLineInPoly(geom1, geom2);
51
+ return !isLineInPoly(geom1, geom2, ignoreSelfIntersections);
50
52
  case "Polygon":
51
- return !isPolyInPoly(geom2, geom1);
53
+ return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);
52
54
  }
53
55
  }
54
56
  return false;
55
57
  }
56
- __name(disjoint, "disjoint");
57
58
  function isPointOnLine(lineString, pt) {
58
59
  for (let i = 0; i < lineString.coordinates.length - 1; i++) {
59
60
  if (isPointOnLineSegment(
@@ -66,29 +67,30 @@ function isPointOnLine(lineString, pt) {
66
67
  }
67
68
  return false;
68
69
  }
69
- __name(isPointOnLine, "isPointOnLine");
70
- function isLineOnLine(lineString1, lineString2) {
71
- const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString1, lineString2);
70
+ function isLineOnLine(lineString1, lineString2, ignoreSelfIntersections) {
71
+ const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString1, lineString2, {
72
+ ignoreSelfIntersections
73
+ });
72
74
  if (doLinesIntersect.features.length > 0) {
73
75
  return true;
74
76
  }
75
77
  return false;
76
78
  }
77
- __name(isLineOnLine, "isLineOnLine");
78
- function isLineInPoly(polygon, lineString) {
79
+ function isLineInPoly(polygon, lineString, ignoreSelfIntersections) {
79
80
  for (const coord of lineString.coordinates) {
80
81
  if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord, polygon)) {
81
82
  return true;
82
83
  }
83
84
  }
84
- const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString, _polygontoline.polygonToLine.call(void 0, polygon));
85
+ const doLinesIntersect = _lineintersect.lineIntersect.call(void 0, lineString, _polygontoline.polygonToLine.call(void 0, polygon), {
86
+ ignoreSelfIntersections
87
+ });
85
88
  if (doLinesIntersect.features.length > 0) {
86
89
  return true;
87
90
  }
88
91
  return false;
89
92
  }
90
- __name(isLineInPoly, "isLineInPoly");
91
- function isPolyInPoly(feature1, feature2) {
93
+ function isPolyInPoly(feature1, feature2, ignoreSelfIntersections) {
92
94
  for (const coord1 of feature1.coordinates[0]) {
93
95
  if (_booleanpointinpolygon.booleanPointInPolygon.call(void 0, coord1, feature2)) {
94
96
  return true;
@@ -101,14 +103,14 @@ function isPolyInPoly(feature1, feature2) {
101
103
  }
102
104
  const doLinesIntersect = _lineintersect.lineIntersect.call(void 0,
103
105
  _polygontoline.polygonToLine.call(void 0, feature1),
104
- _polygontoline.polygonToLine.call(void 0, feature2)
106
+ _polygontoline.polygonToLine.call(void 0, feature2),
107
+ { ignoreSelfIntersections }
105
108
  );
106
109
  if (doLinesIntersect.features.length > 0) {
107
110
  return true;
108
111
  }
109
112
  return false;
110
113
  }
111
- __name(isPolyInPoly, "isPolyInPoly");
112
114
  function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
113
115
  const dxc = pt[0] - lineSegmentStart[0];
114
116
  const dyc = pt[1] - lineSegmentStart[1];
@@ -130,11 +132,9 @@ function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
130
132
  return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
131
133
  }
132
134
  }
133
- __name(isPointOnLineSegment, "isPointOnLineSegment");
134
135
  function compareCoords(pair1, pair2) {
135
136
  return pair1[0] === pair2[0] && pair1[1] === pair2[1];
136
137
  }
137
- __name(compareCoords, "compareCoords");
138
138
  var turf_boolean_disjoint_default = booleanDisjoint;
139
139
 
140
140
 
@@ -1 +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;AAdS;AAwBT,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,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C,KAAK,iBAAiB,CAAC;AAAA,EAClE;AACF;AAxBS;AAkCT,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAFS;AAKT,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"]}
1
+ {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAQA,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAkB9B,SAAS,gBACP,UACA,UACA,UAEI,CAAC,GACI;AAnCX;AAoCE,QAAM,2BACJ,aAAQ,4BAAR,YAAmC;AAErC,MAAI,OAAO;AACX,cAAY,UAAU,CAAC,aAAa;AAClC,gBAAY,UAAU,CAAC,aAAa;AAClC,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,SAAS;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH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AC,KAAK,eAAe,CAAC;AAAA,IAClE,OAAO;AACL,aAAO,eAAe,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,iBAAiB,CAAC;AAAA,IAClE;AAAA,EACF,WAAW,MAAM,GAAG;AAClB,WAAO,iBAAiB,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,eAAe,CAAC;AAAA,EAClE,OAAO;AACL,WAAO,eAAe,CAAC,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,iBAAiB,CAAC;AAAA,EAClE;AACF;AAUA,SAAS,cAAc,OAAiB,OAAiB;AACvD,SAAO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAGA,IAAO,gCAAQ","sourcesContent":["import {\n Feature,\n Geometry,\n LineString,\n Point,\n Polygon,\n Position,\n} from \"geojson\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { polygonToLine } from \"@turf/polygon-to-line\";\n\n/**\n * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.\n *\n * @name booleanDisjoint\n * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry\n * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features\n * @returns {boolean} true if the intersection is an empty set, false otherwise\n * @example\n * var point = turf.point([2, 2]);\n * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n *\n * turf.booleanDisjoint(line, point);\n * //=true\n */\nfunction booleanDisjoint(\n feature1: Feature<any> | Geometry,\n feature2: Feature<any> | Geometry,\n options: {\n ignoreSelfIntersections?: boolean;\n } = {}\n): boolean {\n const ignoreSelfIntersections: boolean =\n options.ignoreSelfIntersections ?? false;\n\n let bool = true;\n flattenEach(feature1, (flatten1) => {\n flattenEach(feature2, (flatten2) => {\n if (bool === false) {\n return false;\n }\n bool = disjoint(\n flatten1.geometry,\n flatten2.geometry,\n ignoreSelfIntersections\n );\n });\n });\n return bool;\n}\n\n/**\n * Disjoint operation for simple Geometries (Point/LineString/Polygon)\n *\n * @private\n * @param {Geometry<any>} geom1 GeoJSON Geometry\n * @param {Geometry<any>} geom2 GeoJSON Geometry\n * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if disjoint, false otherwise\n */\nfunction disjoint(geom1: any, geom2: any, ignoreSelfIntersections: boolean) {\n switch (geom1.type) {\n case \"Point\":\n /* eslint-disable @typescript-eslint/no-unused-vars */\n switch (geom2.type) {\n case \"Point\":\n return !compareCoords(geom1.coordinates, geom2.coordinates);\n case \"LineString\":\n return !isPointOnLine(geom2, geom1);\n case \"Polygon\":\n return !booleanPointInPolygon(geom1, geom2);\n }\n /* istanbul ignore next */\n break;\n case \"LineString\":\n switch (geom2.type) {\n case \"Point\":\n return !isPointOnLine(geom1, geom2);\n case \"LineString\":\n return !isLineOnLine(geom1, geom2, ignoreSelfIntersections);\n case \"Polygon\":\n return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);\n }\n /* istanbul ignore next */\n break;\n case \"Polygon\":\n switch (geom2.type) {\n case \"Point\":\n return !booleanPointInPolygon(geom2, geom1);\n case \"LineString\":\n return !isLineInPoly(geom1, geom2, ignoreSelfIntersections);\n case \"Polygon\":\n return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);\n }\n }\n return false;\n}\n\n// http://stackoverflow.com/a/11908158/1979085\nfunction isPointOnLine(lineString: LineString, pt: Point) {\n for (let i = 0; i < lineString.coordinates.length - 1; i++) {\n if (\n isPointOnLineSegment(\n lineString.coordinates[i],\n lineString.coordinates[i + 1],\n pt.coordinates\n )\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isLineOnLine(\n lineString1: LineString,\n lineString2: LineString,\n ignoreSelfIntersections: boolean\n) {\n const doLinesIntersect = lineIntersect(lineString1, lineString2, {\n ignoreSelfIntersections,\n });\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isLineInPoly(\n polygon: Polygon,\n lineString: LineString,\n ignoreSelfIntersections: boolean\n) {\n for (const coord of lineString.coordinates) {\n if (booleanPointInPolygon(coord, polygon)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon), {\n ignoreSelfIntersections,\n });\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\n/**\n * Is Polygon (geom1) in Polygon (geom2)\n * Only takes into account outer rings\n * See http://stackoverflow.com/a/4833823/1979085\n *\n * @private\n * @param {Geometry|Feature<Polygon>} feature1 Polygon1\n * @param {Geometry|Feature<Polygon>} feature2 Polygon2\n * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if geom1 is in geom2, false otherwise\n */\nfunction isPolyInPoly(\n feature1: Polygon,\n feature2: Polygon,\n ignoreSelfIntersections: boolean\n) {\n for (const coord1 of feature1.coordinates[0]) {\n if (booleanPointInPolygon(coord1, feature2)) {\n return true;\n }\n }\n for (const coord2 of feature2.coordinates[0]) {\n if (booleanPointInPolygon(coord2, feature1)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(\n polygonToLine(feature1),\n polygonToLine(feature2),\n { ignoreSelfIntersections }\n );\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isPointOnLineSegment(\n lineSegmentStart: Position,\n lineSegmentEnd: Position,\n pt: Position\n) {\n const dxc = pt[0] - lineSegmentStart[0];\n const dyc = pt[1] - lineSegmentStart[1];\n const dxl = lineSegmentEnd[0] - lineSegmentStart[0];\n const dyl = lineSegmentEnd[1] - lineSegmentStart[1];\n const cross = dxc * dyl - dyc * dxl;\n if (cross !== 0) {\n return false;\n }\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n if (dxl > 0) {\n return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];\n } else {\n return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];\n }\n } else if (dyl > 0) {\n return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];\n } else {\n return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];\n }\n}\n\n/**\n * compareCoords\n *\n * @private\n * @param {Position} pair1 point [x,y]\n * @param {Position} pair2 point [x,y]\n * @returns {boolean} true if coord pairs match, false otherwise\n */\nfunction compareCoords(pair1: Position, pair2: Position) {\n return pair1[0] === pair2[0] && pair1[1] === pair2[1];\n}\n\nexport { booleanDisjoint };\nexport default booleanDisjoint;\n"]}
@@ -6,7 +6,9 @@ import { Feature, Geometry } from 'geojson';
6
6
  * @name booleanDisjoint
7
7
  * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
8
8
  * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
9
- * @returns {boolean} true/false
9
+ * @param {Object} [options={}] Optional parameters
10
+ * @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
11
+ * @returns {boolean} true if the intersection is an empty set, false otherwise
10
12
  * @example
11
13
  * var point = turf.point([2, 2]);
12
14
  * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
@@ -14,6 +16,8 @@ import { Feature, Geometry } from 'geojson';
14
16
  * turf.booleanDisjoint(line, point);
15
17
  * //=true
16
18
  */
17
- declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
19
+ declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry, options?: {
20
+ ignoreSelfIntersections?: boolean;
21
+ }): boolean;
18
22
 
19
23
  export { booleanDisjoint, booleanDisjoint as default };
@@ -6,7 +6,9 @@ import { Feature, Geometry } from 'geojson';
6
6
  * @name booleanDisjoint
7
7
  * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
8
8
  * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
9
- * @returns {boolean} true/false
9
+ * @param {Object} [options={}] Optional parameters
10
+ * @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features
11
+ * @returns {boolean} true if the intersection is an empty set, false otherwise
10
12
  * @example
11
13
  * var point = turf.point([2, 2]);
12
14
  * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);
@@ -14,6 +16,8 @@ import { Feature, Geometry } from 'geojson';
14
16
  * turf.booleanDisjoint(line, point);
15
17
  * //=true
16
18
  */
17
- declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry): boolean;
19
+ declare function booleanDisjoint(feature1: Feature<any> | Geometry, feature2: Feature<any> | Geometry, options?: {
20
+ ignoreSelfIntersections?: boolean;
21
+ }): boolean;
18
22
 
19
23
  export { booleanDisjoint, booleanDisjoint as default };
package/dist/esm/index.js CHANGED
@@ -1,25 +1,27 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
-
4
1
  // index.ts
5
2
  import { booleanPointInPolygon } from "@turf/boolean-point-in-polygon";
6
3
  import { lineIntersect } from "@turf/line-intersect";
7
4
  import { flattenEach } from "@turf/meta";
8
5
  import { polygonToLine } from "@turf/polygon-to-line";
9
- function booleanDisjoint(feature1, feature2) {
6
+ function booleanDisjoint(feature1, feature2, options = {}) {
7
+ var _a;
8
+ const ignoreSelfIntersections = (_a = options.ignoreSelfIntersections) != null ? _a : false;
10
9
  let bool = true;
11
10
  flattenEach(feature1, (flatten1) => {
12
11
  flattenEach(feature2, (flatten2) => {
13
12
  if (bool === false) {
14
13
  return false;
15
14
  }
16
- bool = disjoint(flatten1.geometry, flatten2.geometry);
15
+ bool = disjoint(
16
+ flatten1.geometry,
17
+ flatten2.geometry,
18
+ ignoreSelfIntersections
19
+ );
17
20
  });
18
21
  });
19
22
  return bool;
20
23
  }
21
- __name(booleanDisjoint, "booleanDisjoint");
22
- function disjoint(geom1, geom2) {
24
+ function disjoint(geom1, geom2, ignoreSelfIntersections) {
23
25
  switch (geom1.type) {
24
26
  case "Point":
25
27
  switch (geom2.type) {
@@ -36,9 +38,9 @@ function disjoint(geom1, geom2) {
36
38
  case "Point":
37
39
  return !isPointOnLine(geom1, geom2);
38
40
  case "LineString":
39
- return !isLineOnLine(geom1, geom2);
41
+ return !isLineOnLine(geom1, geom2, ignoreSelfIntersections);
40
42
  case "Polygon":
41
- return !isLineInPoly(geom2, geom1);
43
+ return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);
42
44
  }
43
45
  break;
44
46
  case "Polygon":
@@ -46,14 +48,13 @@ function disjoint(geom1, geom2) {
46
48
  case "Point":
47
49
  return !booleanPointInPolygon(geom2, geom1);
48
50
  case "LineString":
49
- return !isLineInPoly(geom1, geom2);
51
+ return !isLineInPoly(geom1, geom2, ignoreSelfIntersections);
50
52
  case "Polygon":
51
- return !isPolyInPoly(geom2, geom1);
53
+ return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);
52
54
  }
53
55
  }
54
56
  return false;
55
57
  }
56
- __name(disjoint, "disjoint");
57
58
  function isPointOnLine(lineString, pt) {
58
59
  for (let i = 0; i < lineString.coordinates.length - 1; i++) {
59
60
  if (isPointOnLineSegment(
@@ -66,29 +67,30 @@ function isPointOnLine(lineString, pt) {
66
67
  }
67
68
  return false;
68
69
  }
69
- __name(isPointOnLine, "isPointOnLine");
70
- function isLineOnLine(lineString1, lineString2) {
71
- const doLinesIntersect = lineIntersect(lineString1, lineString2);
70
+ function isLineOnLine(lineString1, lineString2, ignoreSelfIntersections) {
71
+ const doLinesIntersect = lineIntersect(lineString1, lineString2, {
72
+ ignoreSelfIntersections
73
+ });
72
74
  if (doLinesIntersect.features.length > 0) {
73
75
  return true;
74
76
  }
75
77
  return false;
76
78
  }
77
- __name(isLineOnLine, "isLineOnLine");
78
- function isLineInPoly(polygon, lineString) {
79
+ function isLineInPoly(polygon, lineString, ignoreSelfIntersections) {
79
80
  for (const coord of lineString.coordinates) {
80
81
  if (booleanPointInPolygon(coord, polygon)) {
81
82
  return true;
82
83
  }
83
84
  }
84
- const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
85
+ const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon), {
86
+ ignoreSelfIntersections
87
+ });
85
88
  if (doLinesIntersect.features.length > 0) {
86
89
  return true;
87
90
  }
88
91
  return false;
89
92
  }
90
- __name(isLineInPoly, "isLineInPoly");
91
- function isPolyInPoly(feature1, feature2) {
93
+ function isPolyInPoly(feature1, feature2, ignoreSelfIntersections) {
92
94
  for (const coord1 of feature1.coordinates[0]) {
93
95
  if (booleanPointInPolygon(coord1, feature2)) {
94
96
  return true;
@@ -101,14 +103,14 @@ function isPolyInPoly(feature1, feature2) {
101
103
  }
102
104
  const doLinesIntersect = lineIntersect(
103
105
  polygonToLine(feature1),
104
- polygonToLine(feature2)
106
+ polygonToLine(feature2),
107
+ { ignoreSelfIntersections }
105
108
  );
106
109
  if (doLinesIntersect.features.length > 0) {
107
110
  return true;
108
111
  }
109
112
  return false;
110
113
  }
111
- __name(isPolyInPoly, "isPolyInPoly");
112
114
  function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
113
115
  const dxc = pt[0] - lineSegmentStart[0];
114
116
  const dyc = pt[1] - lineSegmentStart[1];
@@ -130,11 +132,9 @@ function isPointOnLineSegment(lineSegmentStart, lineSegmentEnd, pt) {
130
132
  return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
131
133
  }
132
134
  }
133
- __name(isPointOnLineSegment, "isPointOnLineSegment");
134
135
  function compareCoords(pair1, pair2) {
135
136
  return pair1[0] === pair2[0] && pair1[1] === pair2[1];
136
137
  }
137
- __name(compareCoords, "compareCoords");
138
138
  var turf_boolean_disjoint_default = booleanDisjoint;
139
139
  export {
140
140
  booleanDisjoint,
@@ -1 +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;AAdS;AAwBT,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;A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AO,MAAM,CAAC,MAAM,MAAM,CAAC,KAAK,MAAM,CAAC,MAAM,MAAM,CAAC;AACtD;AAFS;AAKT,IAAO,gCAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n Feature,\n Geometry,\n LineString,\n Point,\n Polygon,\n Position,\n} from \"geojson\";\nimport { booleanPointInPolygon } from \"@turf/boolean-point-in-polygon\";\nimport { lineIntersect } from \"@turf/line-intersect\";\nimport { flattenEach } from \"@turf/meta\";\nimport { polygonToLine } from \"@turf/polygon-to-line\";\n\n/**\n * Boolean-disjoint returns (TRUE) if the intersection of the two geometries is an empty set.\n *\n * @name booleanDisjoint\n * @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry\n * @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry\n * @param {Object} [options={}] Optional parameters\n * @param {boolean} [options.ignoreSelfIntersections=false] ignores self-intersections on input features\n * @returns {boolean} true if the intersection is an empty set, false otherwise\n * @example\n * var point = turf.point([2, 2]);\n * var line = turf.lineString([[1, 1], [1, 2], [1, 3], [1, 4]]);\n *\n * turf.booleanDisjoint(line, point);\n * //=true\n */\nfunction booleanDisjoint(\n feature1: Feature<any> | Geometry,\n feature2: Feature<any> | Geometry,\n options: {\n ignoreSelfIntersections?: boolean;\n } = {}\n): boolean {\n const ignoreSelfIntersections: boolean =\n options.ignoreSelfIntersections ?? false;\n\n let bool = true;\n flattenEach(feature1, (flatten1) => {\n flattenEach(feature2, (flatten2) => {\n if (bool === false) {\n return false;\n }\n bool = disjoint(\n flatten1.geometry,\n flatten2.geometry,\n ignoreSelfIntersections\n );\n });\n });\n return bool;\n}\n\n/**\n * Disjoint operation for simple Geometries (Point/LineString/Polygon)\n *\n * @private\n * @param {Geometry<any>} geom1 GeoJSON Geometry\n * @param {Geometry<any>} geom2 GeoJSON Geometry\n * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if disjoint, false otherwise\n */\nfunction disjoint(geom1: any, geom2: any, ignoreSelfIntersections: boolean) {\n switch (geom1.type) {\n case \"Point\":\n /* eslint-disable @typescript-eslint/no-unused-vars */\n switch (geom2.type) {\n case \"Point\":\n return !compareCoords(geom1.coordinates, geom2.coordinates);\n case \"LineString\":\n return !isPointOnLine(geom2, geom1);\n case \"Polygon\":\n return !booleanPointInPolygon(geom1, geom2);\n }\n /* istanbul ignore next */\n break;\n case \"LineString\":\n switch (geom2.type) {\n case \"Point\":\n return !isPointOnLine(geom1, geom2);\n case \"LineString\":\n return !isLineOnLine(geom1, geom2, ignoreSelfIntersections);\n case \"Polygon\":\n return !isLineInPoly(geom2, geom1, ignoreSelfIntersections);\n }\n /* istanbul ignore next */\n break;\n case \"Polygon\":\n switch (geom2.type) {\n case \"Point\":\n return !booleanPointInPolygon(geom2, geom1);\n case \"LineString\":\n return !isLineInPoly(geom1, geom2, ignoreSelfIntersections);\n case \"Polygon\":\n return !isPolyInPoly(geom2, geom1, ignoreSelfIntersections);\n }\n }\n return false;\n}\n\n// http://stackoverflow.com/a/11908158/1979085\nfunction isPointOnLine(lineString: LineString, pt: Point) {\n for (let i = 0; i < lineString.coordinates.length - 1; i++) {\n if (\n isPointOnLineSegment(\n lineString.coordinates[i],\n lineString.coordinates[i + 1],\n pt.coordinates\n )\n ) {\n return true;\n }\n }\n return false;\n}\n\nfunction isLineOnLine(\n lineString1: LineString,\n lineString2: LineString,\n ignoreSelfIntersections: boolean\n) {\n const doLinesIntersect = lineIntersect(lineString1, lineString2, {\n ignoreSelfIntersections,\n });\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isLineInPoly(\n polygon: Polygon,\n lineString: LineString,\n ignoreSelfIntersections: boolean\n) {\n for (const coord of lineString.coordinates) {\n if (booleanPointInPolygon(coord, polygon)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon), {\n ignoreSelfIntersections,\n });\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\n/**\n * Is Polygon (geom1) in Polygon (geom2)\n * Only takes into account outer rings\n * See http://stackoverflow.com/a/4833823/1979085\n *\n * @private\n * @param {Geometry|Feature<Polygon>} feature1 Polygon1\n * @param {Geometry|Feature<Polygon>} feature2 Polygon2\n * @param {boolean} ignoreSelfIntersections ignore self-intersections on input features\n * @returns {boolean} true if geom1 is in geom2, false otherwise\n */\nfunction isPolyInPoly(\n feature1: Polygon,\n feature2: Polygon,\n ignoreSelfIntersections: boolean\n) {\n for (const coord1 of feature1.coordinates[0]) {\n if (booleanPointInPolygon(coord1, feature2)) {\n return true;\n }\n }\n for (const coord2 of feature2.coordinates[0]) {\n if (booleanPointInPolygon(coord2, feature1)) {\n return true;\n }\n }\n const doLinesIntersect = lineIntersect(\n polygonToLine(feature1),\n polygonToLine(feature2),\n { ignoreSelfIntersections }\n );\n if (doLinesIntersect.features.length > 0) {\n return true;\n }\n return false;\n}\n\nfunction isPointOnLineSegment(\n lineSegmentStart: Position,\n lineSegmentEnd: Position,\n pt: Position\n) {\n const dxc = pt[0] - lineSegmentStart[0];\n const dyc = pt[1] - lineSegmentStart[1];\n const dxl = lineSegmentEnd[0] - lineSegmentStart[0];\n const dyl = lineSegmentEnd[1] - lineSegmentStart[1];\n const cross = dxc * dyl - dyc * dxl;\n if (cross !== 0) {\n return false;\n }\n if (Math.abs(dxl) >= Math.abs(dyl)) {\n if (dxl > 0) {\n return lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0];\n } else {\n return lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];\n }\n } else if (dyl > 0) {\n return lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1];\n } else {\n return lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];\n }\n}\n\n/**\n * compareCoords\n *\n * @private\n * @param {Position} pair1 point [x,y]\n * @param {Position} pair2 point [x,y]\n * @returns {boolean} true if coord pairs match, false otherwise\n */\nfunction compareCoords(pair1: Position, pair2: Position) {\n return pair1[0] === pair2[0] && pair1[1] === pair2[1];\n}\n\nexport { booleanDisjoint };\nexport default booleanDisjoint;\n"],"mappings":";AAQA,SAAS,6BAA6B;AACtC,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB;AAC5B,SAAS,qBAAqB;AAkB9B,SAAS,gBACP,UACA,UACA,UAEI,CAAC,GACI;AAnCX;AAoCE,QAAM,2BACJ,aAAQ,4BAAR,YAAmC;AAErC,MAAI,OAAO;AACX,cAAY,UAAU,CAAC,aAAa;AAClC,gBAAY,UAAU,CAAC,aAAa;AAClC,UAAI,SAAS,OAAO;AAClB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,QACL,SAAS;AAAA,QACT,SAAS;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACD,SAAO;AACT;AAWA,SAAS,SAAS,OAAY,OAAY,yBAAkC;AAC1E,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AAEH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iBAAO,CAAC,cAAc,MAAM,aAAa,MAAM,WAAW;AAAA,QAC5D,KAAK;AACH,iBAAO,CAAC,cAAc,OAAO,KAAK;AAAA,QACpC,KAAK;AACH,iBAAO,CAAC,sBAAsB,OAAO,KAAK;AAAA,MAC9C;AAEA;AAAA,IACF,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iBAAO,CAAC,cAAc,OAAO,KAAK;AAAA,QACpC,KAAK;AACH,iBAAO,CAAC,aAAa,OAAO,OAAO,uBAAuB;AAAA,QAC5D,KAAK;AACH,iBAAO,CAAC,aAAa,OAAO,OAAO,uBAAuB;AAAA,MAC9D;AAEA;AAAA,IACF,KAAK;AACH,cAAQ,MAAM,MAAM;AAAA,QAClB,KAAK;AACH,iBAAO,CAAC,sBAAsB,OAAO,KAAK;AAAA,QAC5C,KAAK;AACH,iBAAO,CAAC,aAAa,OAAO,OAAO,uBAAuB;AAAA,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xC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAEA,SAAS,qBACP,kBACA,gBACA,IACA;AACA,QAAM,MAAM,GAAG,CAAC,IAAI,iBAAiB,CAAC;AACtC,QAAM,MAAM,GAAG,CAAC,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;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turf/boolean-disjoint",
3
- "version": "7.0.0",
3
+ "version": "7.1.0-alpha.70+948cdafaf",
4
4
  "description": "turf boolean-disjoint module",
5
5
  "author": "Turf Authors",
6
6
  "contributors": [
@@ -67,12 +67,13 @@
67
67
  "typescript": "^5.2.2"
68
68
  },
69
69
  "dependencies": {
70
- "@turf/boolean-point-in-polygon": "^7.0.0",
71
- "@turf/helpers": "^7.0.0",
72
- "@turf/line-intersect": "^7.0.0",
73
- "@turf/meta": "^7.0.0",
74
- "@turf/polygon-to-line": "^7.0.0",
70
+ "@turf/boolean-point-in-polygon": "^7.1.0-alpha.70+948cdafaf",
71
+ "@turf/helpers": "^7.1.0-alpha.70+948cdafaf",
72
+ "@turf/line-intersect": "^7.1.0-alpha.70+948cdafaf",
73
+ "@turf/meta": "^7.1.0-alpha.70+948cdafaf",
74
+ "@turf/polygon-to-line": "^7.1.0-alpha.70+948cdafaf",
75
+ "@types/geojson": "^7946.0.10",
75
76
  "tslib": "^2.6.2"
76
77
  },
77
- "gitHead": "3d3a7917025fbabe191dbddbc89754b86f9c7739"
78
+ "gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067"
78
79
  }