@turf/difference 7.1.0-alpha.70 → 7.2.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.
- package/dist/cjs/index.cjs +8 -10
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +7 -9
- package/dist/esm/index.js.map +1 -1
- package/package.json +11 -11
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
2
|
-
var
|
|
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
|
|
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 =
|
|
15
|
-
if (differenced.length === 0)
|
|
16
|
-
|
|
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 =
|
|
19
|
+
var turf_difference_default = difference2;
|
|
22
20
|
|
|
23
21
|
|
|
24
22
|
|
|
25
|
-
exports.default = turf_difference_default; exports.difference =
|
|
23
|
+
exports.default = turf_difference_default; exports.difference = difference2;
|
|
26
24
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";
|
|
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,wBAAA,EAAQA,WAAAA;ADzCf;AACE;AACA;AACF,4EAAC","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"]}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -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
|
-
* @
|
|
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.d.ts
CHANGED
|
@@ -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
|
-
* @
|
|
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
|
|
2
|
+
import * as polyclip from "polyclip-ts";
|
|
3
3
|
import { polygon, multiPolygon } from "@turf/helpers";
|
|
4
4
|
import { geomEach } from "@turf/meta";
|
|
5
|
-
function
|
|
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 =
|
|
15
|
-
if (differenced.length === 0)
|
|
16
|
-
|
|
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 =
|
|
19
|
+
var turf_difference_default = difference2;
|
|
22
20
|
export {
|
|
23
21
|
turf_difference_default as default,
|
|
24
|
-
difference
|
|
22
|
+
difference2 as difference
|
|
25
23
|
};
|
|
26
24
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Polygon, MultiPolygon, Feature, FeatureCollection } from \"geojson\";\nimport
|
|
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,0BAAQC;","names":["difference","difference"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/difference",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"description": "turf difference module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,23 +50,23 @@
|
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/benchmark": "^2.1.5",
|
|
53
|
-
"@types/tape": "^4.
|
|
53
|
+
"@types/tape": "^4.13.4",
|
|
54
54
|
"benchmark": "^2.1.4",
|
|
55
55
|
"glob": "^10.3.10",
|
|
56
56
|
"load-json-file": "^7.0.1",
|
|
57
57
|
"npm-run-all": "^4.1.5",
|
|
58
|
-
"tape": "^5.
|
|
59
|
-
"tsup": "^8.
|
|
60
|
-
"tsx": "^4.
|
|
61
|
-
"typescript": "^5.
|
|
58
|
+
"tape": "^5.9.0",
|
|
59
|
+
"tsup": "^8.3.5",
|
|
60
|
+
"tsx": "^4.19.2",
|
|
61
|
+
"typescript": "^5.5.4",
|
|
62
62
|
"write-json-file": "^5.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@turf/helpers": "^7.
|
|
66
|
-
"@turf/meta": "^7.
|
|
65
|
+
"@turf/helpers": "^7.2.0",
|
|
66
|
+
"@turf/meta": "^7.2.0",
|
|
67
67
|
"@types/geojson": "^7946.0.10",
|
|
68
|
-
"
|
|
69
|
-
"tslib": "^2.
|
|
68
|
+
"polyclip-ts": "^0.16.8",
|
|
69
|
+
"tslib": "^2.8.1"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "7b0f0374c4668cd569f8904c71e2ae7d941be867"
|
|
72
72
|
}
|