@turf/intersect 7.1.0 → 7.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// index.ts
2
2
  var _helpers = require('@turf/helpers');
3
3
  var _meta = require('@turf/meta');
4
- var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
4
+ var _polyclipts = require('polyclip-ts'); var polyclip = _interopRequireWildcard(_polyclipts);
5
5
  function intersect(features, options = {}) {
6
6
  const geoms = [];
7
7
  _meta.geomEach.call(void 0, features, (geom) => {
@@ -10,19 +10,15 @@ function intersect(features, options = {}) {
10
10
  if (geoms.length < 2) {
11
11
  throw new Error("Must specify at least 2 geometries");
12
12
  }
13
- const intersection = _polygonclipping2.default.intersection(
14
- geoms[0],
15
- ...geoms.slice(1)
16
- );
17
- if (intersection.length === 0)
18
- return null;
19
- if (intersection.length === 1)
20
- return _helpers.polygon.call(void 0, intersection[0], options.properties);
21
- return _helpers.multiPolygon.call(void 0, intersection, options.properties);
13
+ const intersection2 = polyclip.intersection(geoms[0], ...geoms.slice(1));
14
+ if (intersection2.length === 0) return null;
15
+ if (intersection2.length === 1)
16
+ return _helpers.polygon.call(void 0, intersection2[0], options.properties);
17
+ return _helpers.multiPolygon.call(void 0, intersection2, options.properties);
22
18
  }
23
- var turf_intersect_default = intersect;
19
+ var index_default = intersect;
24
20
 
25
21
 
26
22
 
27
- exports.default = turf_intersect_default; exports.intersect = intersect;
23
+ exports.default = index_default; exports.intersect = intersect;
28
24
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AAOA,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AACzB,OAAO,qBAAqB;AAqC5B,SAAS,UACP,UACA,UAEI,CAAC,GACsC;AAC3C,QAAM,QAAgC,CAAC;AAEvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,QAAM,eAAe,gBAAgB;AAAA,IACnC,MAAM,CAAC;AAAA,IACP,GAAG,MAAM,MAAM,CAAC;AAAA,EAClB;AACA,MAAI,aAAa,WAAW;AAAG,WAAO;AACtC,MAAI,aAAa,WAAW;AAC1B,WAAO,QAAQ,aAAa,CAAC,GAAG,QAAQ,UAAU;AACpD,SAAO,aAAa,cAAc,QAAQ,UAAU;AACtD;AAGA,IAAO,yBAAQ","sourcesContent":["import {\n Feature,\n GeoJsonProperties,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport polygonClipping from \"polygon-clipping\";\n\n/**\n * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and\n * finds their polygonal intersection. If they don't intersect, returns null.\n *\n * @name intersect\n * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature\n * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or\n * {@link MultiPolygon}). If they do not share any area, returns `null`.\n * @example\n * var poly1 = turf.polygon([[\n * [-122.801742, 45.48565],\n * [-122.801742, 45.60491],\n * [-122.584762, 45.60491],\n * [-122.584762, 45.48565],\n * [-122.801742, 45.48565]\n * ]]);\n *\n * var poly2 = turf.polygon([[\n * [-122.520217, 45.535693],\n * [-122.64038, 45.553967],\n * [-122.720031, 45.526554],\n * [-122.669906, 45.507309],\n * [-122.723464, 45.446643],\n * [-122.532577, 45.408574],\n * [-122.487258, 45.477466],\n * [-122.520217, 45.535693]\n * ]]);\n *\n * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, intersection];\n */\nfunction intersect<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: {\n properties?: P;\n } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polygonClipping.Geom[] = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must specify at least 2 geometries\");\n }\n const intersection = polygonClipping.intersection(\n geoms[0],\n ...geoms.slice(1)\n );\n if (intersection.length === 0) return null;\n if (intersection.length === 1)\n return polygon(intersection[0], options.properties);\n return multiPolygon(intersection, options.properties);\n}\n\nexport { intersect };\nexport default intersect;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-intersect/dist/cjs/index.cjs","../../index.ts"],"names":["intersection"],"mappings":"AAAA;ACOA,wCAAsC;AACtC,kCAAyB;AACzB,8FAA0B;AAqC1B,SAAS,SAAA,CACP,QAAA,EACA,QAAA,EAEI,CAAC,CAAA,EACsC;AAC3C,EAAA,MAAM,MAAA,EAAyB,CAAC,CAAA;AAEhC,EAAA,4BAAA,QAAS,EAAU,CAAC,IAAA,EAAA,GAAS;AAC3B,IAAA,KAAA,CAAM,IAAA,CAAK,IAAA,CAAK,WAA4B,CAAA;AAAA,EAC9C,CAAC,CAAA;AAED,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,EAAS,CAAA,EAAG;AACpB,IAAA,MAAM,IAAI,KAAA,CAAM,oCAAoC,CAAA;AAAA,EACtD;AACA,EAAA,MAAMA,cAAAA,EAAwB,QAAA,CAAA,YAAA,CAAa,KAAA,CAAM,CAAC,CAAA,EAAG,GAAG,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA;AACtE,EAAA,GAAA,CAAIA,aAAAA,CAAa,OAAA,IAAW,CAAA,EAAG,OAAO,IAAA;AACtC,EAAA,GAAA,CAAIA,aAAAA,CAAa,OAAA,IAAW,CAAA;AAC1B,IAAA,OAAO,8BAAA,aAAQA,CAAa,CAAC,CAAA,EAAG,OAAA,CAAQ,UAAU,CAAA;AACpD,EAAA,OAAO,mCAAA,aAAaA,EAAc,OAAA,CAAQ,UAAU,CAAA;AACtD;AAGA,IAAO,cAAA,EAAQ,SAAA;ADlDf;AACE;AACA;AACF,+DAAC","file":"/home/runner/work/turf/turf/packages/turf-intersect/dist/cjs/index.cjs","sourcesContent":[null,"import {\n Feature,\n GeoJsonProperties,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport * as polyclip from \"polyclip-ts\";\n\n/**\n * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and\n * finds their polygonal intersection. If they don't intersect, returns null.\n *\n * @function\n * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature\n * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or\n * {@link MultiPolygon}). If they do not share any area, returns `null`.\n * @example\n * var poly1 = turf.polygon([[\n * [-122.801742, 45.48565],\n * [-122.801742, 45.60491],\n * [-122.584762, 45.60491],\n * [-122.584762, 45.48565],\n * [-122.801742, 45.48565]\n * ]]);\n *\n * var poly2 = turf.polygon([[\n * [-122.520217, 45.535693],\n * [-122.64038, 45.553967],\n * [-122.720031, 45.526554],\n * [-122.669906, 45.507309],\n * [-122.723464, 45.446643],\n * [-122.532577, 45.408574],\n * [-122.487258, 45.477466],\n * [-122.520217, 45.535693]\n * ]]);\n *\n * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, intersection];\n */\nfunction intersect<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: {\n properties?: P;\n } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polyclip.Geom[] = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polyclip.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must specify at least 2 geometries\");\n }\n const intersection = polyclip.intersection(geoms[0], ...geoms.slice(1));\n if (intersection.length === 0) return null;\n if (intersection.length === 1)\n return polygon(intersection[0], options.properties);\n return multiPolygon(intersection, options.properties);\n}\n\nexport { intersect };\nexport default intersect;\n"]}
@@ -4,7 +4,7 @@ import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature }
4
4
  * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
5
5
  * finds their polygonal intersection. If they don't intersect, returns null.
6
6
  *
7
- * @name intersect
7
+ * @function
8
8
  * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
9
9
  * @param {Object} [options={}] Optional Parameters
10
10
  * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
@@ -4,7 +4,7 @@ import { GeoJsonProperties, FeatureCollection, Polygon, MultiPolygon, Feature }
4
4
  * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and
5
5
  * finds their polygonal intersection. If they don't intersect, returns null.
6
6
  *
7
- * @name intersect
7
+ * @function
8
8
  * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect
9
9
  * @param {Object} [options={}] Optional Parameters
10
10
  * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature
package/dist/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // index.ts
2
2
  import { multiPolygon, polygon } from "@turf/helpers";
3
3
  import { geomEach } from "@turf/meta";
4
- import polygonClipping from "polygon-clipping";
4
+ import * as polyclip from "polyclip-ts";
5
5
  function intersect(features, options = {}) {
6
6
  const geoms = [];
7
7
  geomEach(features, (geom) => {
@@ -10,19 +10,15 @@ function intersect(features, options = {}) {
10
10
  if (geoms.length < 2) {
11
11
  throw new Error("Must specify at least 2 geometries");
12
12
  }
13
- const intersection = polygonClipping.intersection(
14
- geoms[0],
15
- ...geoms.slice(1)
16
- );
17
- if (intersection.length === 0)
18
- return null;
19
- if (intersection.length === 1)
20
- return polygon(intersection[0], options.properties);
21
- return multiPolygon(intersection, options.properties);
13
+ const intersection2 = polyclip.intersection(geoms[0], ...geoms.slice(1));
14
+ if (intersection2.length === 0) return null;
15
+ if (intersection2.length === 1)
16
+ return polygon(intersection2[0], options.properties);
17
+ return multiPolygon(intersection2, options.properties);
22
18
  }
23
- var turf_intersect_default = intersect;
19
+ var index_default = intersect;
24
20
  export {
25
- turf_intersect_default as default,
21
+ index_default as default,
26
22
  intersect
27
23
  };
28
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n Feature,\n GeoJsonProperties,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport polygonClipping from \"polygon-clipping\";\n\n/**\n * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and\n * finds their polygonal intersection. If they don't intersect, returns null.\n *\n * @name intersect\n * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature\n * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or\n * {@link MultiPolygon}). If they do not share any area, returns `null`.\n * @example\n * var poly1 = turf.polygon([[\n * [-122.801742, 45.48565],\n * [-122.801742, 45.60491],\n * [-122.584762, 45.60491],\n * [-122.584762, 45.48565],\n * [-122.801742, 45.48565]\n * ]]);\n *\n * var poly2 = turf.polygon([[\n * [-122.520217, 45.535693],\n * [-122.64038, 45.553967],\n * [-122.720031, 45.526554],\n * [-122.669906, 45.507309],\n * [-122.723464, 45.446643],\n * [-122.532577, 45.408574],\n * [-122.487258, 45.477466],\n * [-122.520217, 45.535693]\n * ]]);\n *\n * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, intersection];\n */\nfunction intersect<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: {\n properties?: P;\n } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polygonClipping.Geom[] = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polygonClipping.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must specify at least 2 geometries\");\n }\n const intersection = polygonClipping.intersection(\n geoms[0],\n ...geoms.slice(1)\n );\n if (intersection.length === 0) return null;\n if (intersection.length === 1)\n return polygon(intersection[0], options.properties);\n return multiPolygon(intersection, options.properties);\n}\n\nexport { intersect };\nexport default intersect;\n"],"mappings":";AAOA,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AACzB,OAAO,qBAAqB;AAqC5B,SAAS,UACP,UACA,UAEI,CAAC,GACsC;AAC3C,QAAM,QAAgC,CAAC;AAEvC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmC;AAAA,EACrD,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,QAAM,eAAe,gBAAgB;AAAA,IACnC,MAAM,CAAC;AAAA,IACP,GAAG,MAAM,MAAM,CAAC;AAAA,EAClB;AACA,MAAI,aAAa,WAAW;AAAG,WAAO;AACtC,MAAI,aAAa,WAAW;AAC1B,WAAO,QAAQ,aAAa,CAAC,GAAG,QAAQ,UAAU;AACpD,SAAO,aAAa,cAAc,QAAQ,UAAU;AACtD;AAGA,IAAO,yBAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import {\n Feature,\n GeoJsonProperties,\n MultiPolygon,\n Polygon,\n FeatureCollection,\n} from \"geojson\";\nimport { multiPolygon, polygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\nimport * as polyclip from \"polyclip-ts\";\n\n/**\n * Takes {@link Polygon|polygon} or {@link MultiPolygon|multi-polygon} geometries and\n * finds their polygonal intersection. If they don't intersect, returns null.\n *\n * @function\n * @param {FeatureCollection<Polygon | MultiPolygon>} features the features to intersect\n * @param {Object} [options={}] Optional Parameters\n * @param {Object} [options.properties={}] Translate GeoJSON Properties to Feature\n * @returns {Feature|null} returns a feature representing the area they share (either a {@link Polygon} or\n * {@link MultiPolygon}). If they do not share any area, returns `null`.\n * @example\n * var poly1 = turf.polygon([[\n * [-122.801742, 45.48565],\n * [-122.801742, 45.60491],\n * [-122.584762, 45.60491],\n * [-122.584762, 45.48565],\n * [-122.801742, 45.48565]\n * ]]);\n *\n * var poly2 = turf.polygon([[\n * [-122.520217, 45.535693],\n * [-122.64038, 45.553967],\n * [-122.720031, 45.526554],\n * [-122.669906, 45.507309],\n * [-122.723464, 45.446643],\n * [-122.532577, 45.408574],\n * [-122.487258, 45.477466],\n * [-122.520217, 45.535693]\n * ]]);\n *\n * var intersection = turf.intersect(turf.featureCollection([poly1, poly2]));\n *\n * //addToMap\n * var addToMap = [poly1, poly2, intersection];\n */\nfunction intersect<P extends GeoJsonProperties = GeoJsonProperties>(\n features: FeatureCollection<Polygon | MultiPolygon>,\n options: {\n properties?: P;\n } = {}\n): Feature<Polygon | MultiPolygon, P> | null {\n const geoms: polyclip.Geom[] = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as polyclip.Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must specify at least 2 geometries\");\n }\n const intersection = polyclip.intersection(geoms[0], ...geoms.slice(1));\n if (intersection.length === 0) return null;\n if (intersection.length === 1)\n return polygon(intersection[0], options.properties);\n return multiPolygon(intersection, options.properties);\n}\n\nexport { intersect };\nexport default intersect;\n"],"mappings":";AAOA,SAAS,cAAc,eAAe;AACtC,SAAS,gBAAgB;AACzB,YAAY,cAAc;AAqC1B,SAAS,UACP,UACA,UAEI,CAAC,GACsC;AAC3C,QAAM,QAAyB,CAAC;AAEhC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAA4B;AAAA,EAC9C,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AACA,QAAMA,gBAAwB,sBAAa,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AACtE,MAAIA,cAAa,WAAW,EAAG,QAAO;AACtC,MAAIA,cAAa,WAAW;AAC1B,WAAO,QAAQA,cAAa,CAAC,GAAG,QAAQ,UAAU;AACpD,SAAO,aAAaA,eAAc,QAAQ,UAAU;AACtD;AAGA,IAAO,gBAAQ;","names":["intersection"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/intersect",
3
- "version": "7.1.0",
4
- "description": "turf intersect module",
3
+ "version": "7.3.0",
4
+ "description": "Finds the shared area between two polygons.",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
7
7
  "bugs": {
@@ -52,23 +52,23 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@types/benchmark": "^2.1.5",
55
- "@types/tape": "^4.2.32",
55
+ "@types/tape": "^5.8.1",
56
56
  "benchmark": "^2.1.4",
57
- "glob": "^10.3.10",
57
+ "glob": "^11.0.2",
58
58
  "load-json-file": "^7.0.1",
59
59
  "npm-run-all": "^4.1.5",
60
- "tape": "^5.7.2",
61
- "tsup": "^8.0.1",
62
- "tsx": "^4.6.2",
63
- "typescript": "^5.2.2",
64
- "write-json-file": "^5.0.0"
60
+ "tape": "^5.9.0",
61
+ "tsup": "^8.4.0",
62
+ "tsx": "^4.19.4",
63
+ "typescript": "^5.8.3",
64
+ "write-json-file": "^6.0.0"
65
65
  },
66
66
  "dependencies": {
67
- "@turf/helpers": "^7.1.0",
68
- "@turf/meta": "^7.1.0",
67
+ "@turf/helpers": "7.3.0",
68
+ "@turf/meta": "7.3.0",
69
69
  "@types/geojson": "^7946.0.10",
70
- "polygon-clipping": "^0.15.3",
71
- "tslib": "^2.6.2"
70
+ "polyclip-ts": "^0.16.8",
71
+ "tslib": "^2.8.1"
72
72
  },
73
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
73
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
74
74
  }