@turf/difference 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,8 +1,8 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
2
- var _polygonclipping = require('polygon-clipping'); var _polygonclipping2 = _interopRequireDefault(_polygonclipping);
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
+ var _polyclipts = require('polyclip-ts'); var polyclip = _interopRequireWildcard(_polyclipts);
3
3
  var _helpers = require('@turf/helpers');
4
4
  var _meta = require('@turf/meta');
5
- function difference(features) {
5
+ function difference2(features) {
6
6
  const geoms = [];
7
7
  _meta.geomEach.call(void 0, features, (geom) => {
8
8
  geoms.push(geom.coordinates);
@@ -11,16 +11,14 @@ function difference(features) {
11
11
  throw new Error("Must have at least two features");
12
12
  }
13
13
  const properties = features.features[0].properties || {};
14
- const differenced = _polygonclipping2.default.difference(geoms[0], ...geoms.slice(1));
15
- if (differenced.length === 0)
16
- return null;
17
- if (differenced.length === 1)
18
- return _helpers.polygon.call(void 0, differenced[0], properties);
14
+ const differenced = polyclip.difference(geoms[0], ...geoms.slice(1));
15
+ if (differenced.length === 0) return null;
16
+ if (differenced.length === 1) return _helpers.polygon.call(void 0, differenced[0], properties);
19
17
  return _helpers.multiPolygon.call(void 0, differenced, properties);
20
18
  }
21
- var turf_difference_default = difference;
19
+ var index_default = difference2;
22
20
 
23
21
 
24
22
 
25
- exports.default = turf_difference_default; exports.difference = difference;
23
+ exports.default = index_default; exports.difference = difference2;
26
24
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,OAAO,qBAA+B;AACtC,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AAmCzB,SAAS,WACP,UACwC;AACxC,QAAM,QAAqB,CAAC;AAE5B,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmB;AAAA,EACrC,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,aAAa,SAAS,SAAS,CAAC,EAAE,cAAc,CAAC;AAEvD,QAAM,cAAc,gBAAgB,WAAW,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AAC1E,MAAI,YAAY,WAAW;AAAG,WAAO;AACrC,MAAI,YAAY,WAAW;AAAG,WAAO,QAAQ,YAAY,CAAC,GAAG,UAAU;AACvE,SAAO,aAAa,aAAa,UAAU;AAC7C;AAGA,IAAO,0BAAQ","sourcesContent":["import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport polygonClipping, { Geom } from \"polygon-clipping\";\nimport { polygon, multiPolygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\n\n/**\n * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.\n *\n * @name difference\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features\n * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(\n features: FeatureCollection<Polygon | MultiPolygon>\n): Feature<Polygon | MultiPolygon> | null {\n const geoms: Array<Geom> = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least two features\");\n }\n\n const properties = features.features[0].properties || {};\n\n const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));\n if (differenced.length === 0) return null;\n if (differenced.length === 1) return polygon(differenced[0], properties);\n return multiPolygon(differenced, properties);\n}\n\nexport { difference };\nexport default difference;\n"]}
1
+ {"version":3,"sources":["/home/runner/work/turf/turf/packages/turf-difference/dist/cjs/index.cjs","../../index.ts"],"names":["difference"],"mappings":"AAAA;ACCA,8FAA0B;AAC1B,wCAAsC;AACtC,kCAAyB;AAmCzB,SAASA,WAAAA,CACP,QAAA,EACwC;AACxC,EAAA,MAAM,MAAA,EAA8B,CAAC,CAAA;AAErC,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,iCAAiC,CAAA;AAAA,EACnD;AAEA,EAAA,MAAM,WAAA,EAAa,QAAA,CAAS,QAAA,CAAS,CAAC,CAAA,CAAE,WAAA,GAAc,CAAC,CAAA;AAEvD,EAAA,MAAM,YAAA,EAAuB,QAAA,CAAA,UAAA,CAAW,KAAA,CAAM,CAAC,CAAA,EAAG,GAAG,KAAA,CAAM,KAAA,CAAM,CAAC,CAAC,CAAA;AACnE,EAAA,GAAA,CAAI,WAAA,CAAY,OAAA,IAAW,CAAA,EAAG,OAAO,IAAA;AACrC,EAAA,GAAA,CAAI,WAAA,CAAY,OAAA,IAAW,CAAA,EAAG,OAAO,8BAAA,WAAQ,CAAY,CAAC,CAAA,EAAG,UAAU,CAAA;AACvE,EAAA,OAAO,mCAAA,WAAa,EAAa,UAAU,CAAA;AAC7C;AAGA,IAAO,cAAA,EAAQA,WAAAA;ADzCf;AACE;AACA;AACF,kEAAC","file":"/home/runner/work/turf/turf/packages/turf-difference/dist/cjs/index.cjs","sourcesContent":[null,"import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport * as polyclip from \"polyclip-ts\";\nimport { polygon, multiPolygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\n\n/**\n * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.\n *\n * @function\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features\n * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(\n features: FeatureCollection<Polygon | MultiPolygon>\n): Feature<Polygon | MultiPolygon> | null {\n const geoms: Array<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 have at least two features\");\n }\n\n const properties = features.features[0].properties || {};\n\n const differenced = polyclip.difference(geoms[0], ...geoms.slice(1));\n if (differenced.length === 0) return null;\n if (differenced.length === 1) return polygon(differenced[0], properties);\n return multiPolygon(differenced, properties);\n}\n\nexport { difference };\nexport default difference;\n"]}
@@ -3,7 +3,7 @@ import { FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
3
3
  /**
4
4
  * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.
5
5
  *
6
- * @name difference
6
+ * @function
7
7
  * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features
8
8
  * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
9
9
  * @example
@@ -3,7 +3,7 @@ import { FeatureCollection, Polygon, MultiPolygon, Feature } from 'geojson';
3
3
  /**
4
4
  * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.
5
5
  *
6
- * @name difference
6
+ * @function
7
7
  * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features
8
8
  * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)
9
9
  * @example
package/dist/esm/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // index.ts
2
- import polygonClipping from "polygon-clipping";
2
+ import * as polyclip from "polyclip-ts";
3
3
  import { polygon, multiPolygon } from "@turf/helpers";
4
4
  import { geomEach } from "@turf/meta";
5
- function difference(features) {
5
+ function difference2(features) {
6
6
  const geoms = [];
7
7
  geomEach(features, (geom) => {
8
8
  geoms.push(geom.coordinates);
@@ -11,16 +11,14 @@ function difference(features) {
11
11
  throw new Error("Must have at least two features");
12
12
  }
13
13
  const properties = features.features[0].properties || {};
14
- const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));
15
- if (differenced.length === 0)
16
- return null;
17
- if (differenced.length === 1)
18
- return polygon(differenced[0], properties);
14
+ const differenced = polyclip.difference(geoms[0], ...geoms.slice(1));
15
+ if (differenced.length === 0) return null;
16
+ if (differenced.length === 1) return polygon(differenced[0], properties);
19
17
  return multiPolygon(differenced, properties);
20
18
  }
21
- var turf_difference_default = difference;
19
+ var index_default = difference2;
22
20
  export {
23
- turf_difference_default as default,
24
- difference
21
+ index_default as default,
22
+ difference2 as difference
25
23
  };
26
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport polygonClipping, { Geom } from \"polygon-clipping\";\nimport { polygon, multiPolygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\n\n/**\n * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.\n *\n * @name difference\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features\n * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(\n features: FeatureCollection<Polygon | MultiPolygon>\n): Feature<Polygon | MultiPolygon> | null {\n const geoms: Array<Geom> = [];\n\n geomEach(features, (geom) => {\n geoms.push(geom.coordinates as Geom);\n });\n\n if (geoms.length < 2) {\n throw new Error(\"Must have at least two features\");\n }\n\n const properties = features.features[0].properties || {};\n\n const differenced = polygonClipping.difference(geoms[0], ...geoms.slice(1));\n if (differenced.length === 0) return null;\n if (differenced.length === 1) return polygon(differenced[0], properties);\n return multiPolygon(differenced, properties);\n}\n\nexport { difference };\nexport default difference;\n"],"mappings":";AACA,OAAO,qBAA+B;AACtC,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AAmCzB,SAAS,WACP,UACwC;AACxC,QAAM,QAAqB,CAAC;AAE5B,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAAmB;AAAA,EACrC,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,aAAa,SAAS,SAAS,CAAC,EAAE,cAAc,CAAC;AAEvD,QAAM,cAAc,gBAAgB,WAAW,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AAC1E,MAAI,YAAY,WAAW;AAAG,WAAO;AACrC,MAAI,YAAY,WAAW;AAAG,WAAO,QAAQ,YAAY,CAAC,GAAG,UAAU;AACvE,SAAO,aAAa,aAAa,UAAU;AAC7C;AAGA,IAAO,0BAAQ;","names":[]}
1
+ {"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport * as polyclip from \"polyclip-ts\";\nimport { polygon, multiPolygon } from \"@turf/helpers\";\nimport { geomEach } from \"@turf/meta\";\n\n/**\n * Finds the difference between multiple {@link Polygon|polygons} by clipping the subsequent polygon from the first.\n *\n * @function\n * @param {FeatureCollection<Polygon|MultiPolygon>} features input Polygon features\n * @returns {Feature<Polygon|MultiPolygon>|null} a Polygon or MultiPolygon feature showing the area of `polygon1` excluding the area of `polygon2` (if empty returns `null`)\n * @example\n * var polygon1 = turf.polygon([[\n * [128, -26],\n * [141, -26],\n * [141, -21],\n * [128, -21],\n * [128, -26]\n * ]], {\n * \"fill\": \"#F00\",\n * \"fill-opacity\": 0.1\n * });\n * var polygon2 = turf.polygon([[\n * [126, -28],\n * [140, -28],\n * [140, -20],\n * [126, -20],\n * [126, -28]\n * ]], {\n * \"fill\": \"#00F\",\n * \"fill-opacity\": 0.1\n * });\n *\n * var difference = turf.difference(turf.featureCollection([polygon1, polygon2]));\n *\n * //addToMap\n * var addToMap = [polygon1, polygon2, difference];\n */\nfunction difference(\n features: FeatureCollection<Polygon | MultiPolygon>\n): Feature<Polygon | MultiPolygon> | null {\n const geoms: Array<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 have at least two features\");\n }\n\n const properties = features.features[0].properties || {};\n\n const differenced = polyclip.difference(geoms[0], ...geoms.slice(1));\n if (differenced.length === 0) return null;\n if (differenced.length === 1) return polygon(differenced[0], properties);\n return multiPolygon(differenced, properties);\n}\n\nexport { difference };\nexport default difference;\n"],"mappings":";AACA,YAAY,cAAc;AAC1B,SAAS,SAAS,oBAAoB;AACtC,SAAS,gBAAgB;AAmCzB,SAASA,YACP,UACwC;AACxC,QAAM,QAA8B,CAAC;AAErC,WAAS,UAAU,CAAC,SAAS;AAC3B,UAAM,KAAK,KAAK,WAA4B;AAAA,EAC9C,CAAC;AAED,MAAI,MAAM,SAAS,GAAG;AACpB,UAAM,IAAI,MAAM,iCAAiC;AAAA,EACnD;AAEA,QAAM,aAAa,SAAS,SAAS,CAAC,EAAE,cAAc,CAAC;AAEvD,QAAM,cAAuB,oBAAW,MAAM,CAAC,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;AACnE,MAAI,YAAY,WAAW,EAAG,QAAO;AACrC,MAAI,YAAY,WAAW,EAAG,QAAO,QAAQ,YAAY,CAAC,GAAG,UAAU;AACvE,SAAO,aAAa,aAAa,UAAU;AAC7C;AAGA,IAAO,gBAAQC;","names":["difference","difference"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@turf/difference",
3
- "version": "7.1.0",
4
- "description": "turf difference module",
3
+ "version": "7.3.0",
4
+ "description": "Finds the difference between multiple polygons by clipping the subsequent polygon from the first.",
5
5
  "author": "Turf Authors",
6
6
  "license": "MIT",
7
7
  "bugs": {
@@ -50,23 +50,23 @@
50
50
  },
51
51
  "devDependencies": {
52
52
  "@types/benchmark": "^2.1.5",
53
- "@types/tape": "^4.2.32",
53
+ "@types/tape": "^5.8.1",
54
54
  "benchmark": "^2.1.4",
55
- "glob": "^10.3.10",
55
+ "glob": "^11.0.2",
56
56
  "load-json-file": "^7.0.1",
57
57
  "npm-run-all": "^4.1.5",
58
- "tape": "^5.7.2",
59
- "tsup": "^8.0.1",
60
- "tsx": "^4.6.2",
61
- "typescript": "^5.2.2",
62
- "write-json-file": "^5.0.0"
58
+ "tape": "^5.9.0",
59
+ "tsup": "^8.4.0",
60
+ "tsx": "^4.19.4",
61
+ "typescript": "^5.8.3",
62
+ "write-json-file": "^6.0.0"
63
63
  },
64
64
  "dependencies": {
65
- "@turf/helpers": "^7.1.0",
66
- "@turf/meta": "^7.1.0",
65
+ "@turf/helpers": "7.3.0",
66
+ "@turf/meta": "7.3.0",
67
67
  "@types/geojson": "^7946.0.10",
68
- "polygon-clipping": "^0.15.3",
69
- "tslib": "^2.6.2"
68
+ "polyclip-ts": "^0.16.8",
69
+ "tslib": "^2.8.1"
70
70
  },
71
- "gitHead": "68915eeebc9278bb40dec3f1034499698a0561ef"
71
+ "gitHead": "9f58a103e8f9a587ab640307ed03ba5233913ddd"
72
72
  }