@turf/convex 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 +4 -9
- package/dist/cjs/index.cjs +25 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/{es/index.js → cjs/index.d.cts} +9 -22
- package/dist/{js → esm}/index.d.ts +6 -3
- package/dist/esm/index.js +25 -0
- package/dist/esm/index.js.map +1 -0
- package/package.json +34 -29
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -54
package/README.md
CHANGED
|
@@ -58,26 +58,21 @@ Returns **[Feature][9]<[Polygon][10]>** a convex hull
|
|
|
58
58
|
|
|
59
59
|
[10]: https://tools.ietf.org/html/rfc7946#section-3.1.6
|
|
60
60
|
|
|
61
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
62
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
63
|
-
./scripts/generate-readmes in the turf project. -->
|
|
61
|
+
<!-- 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. -->
|
|
64
62
|
|
|
65
63
|
---
|
|
66
64
|
|
|
67
|
-
This module is part of the [Turfjs project](
|
|
68
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
69
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
70
|
-
PRs and issues.
|
|
65
|
+
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.
|
|
71
66
|
|
|
72
67
|
### Installation
|
|
73
68
|
|
|
74
|
-
Install this module individually:
|
|
69
|
+
Install this single module individually:
|
|
75
70
|
|
|
76
71
|
```sh
|
|
77
72
|
$ npm install @turf/convex
|
|
78
73
|
```
|
|
79
74
|
|
|
80
|
-
Or install the
|
|
75
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
81
76
|
|
|
82
77
|
```sh
|
|
83
78
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// index.ts
|
|
2
|
+
var _helpers = require('@turf/helpers');
|
|
3
|
+
var _meta = require('@turf/meta');
|
|
4
|
+
var _concaveman = require('concaveman'); var _concaveman2 = _interopRequireDefault(_concaveman);
|
|
5
|
+
function convex(geojson, options = {}) {
|
|
6
|
+
options.concavity = options.concavity || Infinity;
|
|
7
|
+
const points = [];
|
|
8
|
+
_meta.coordEach.call(void 0, geojson, (coord) => {
|
|
9
|
+
points.push([coord[0], coord[1]]);
|
|
10
|
+
});
|
|
11
|
+
if (!points.length) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const convexHull = _concaveman2.default.call(void 0, points, options.concavity);
|
|
15
|
+
if (convexHull.length > 3) {
|
|
16
|
+
return _helpers.polygon.call(void 0, [convexHull]);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var turf_convex_default = convex;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.convex = convex; exports.default = turf_convex_default;
|
|
25
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"names":[],"mappings":";AACA,SAAqB,eAAe;AACpC,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AA8BvB,SAAS,OACP,SACA,UAGI,CAAC,GACuB;AAE5B,UAAQ,YAAY,QAAQ,aAAa;AAGzC,QAAM,SAAqB,CAAC;AAG5B,YAAU,SAAS,CAAC,UAAU;AAC5B,WAAO,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAAA,EAClC,CAAC;AACD,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,WAAW,QAAQ,QAAQ,SAAS;AAGvD,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,QAAQ,CAAC,UAAU,CAAC;AAAA,EAC7B;AACA,SAAO;AACT;AAGA,IAAO,sBAAQ","sourcesContent":["import { Feature, GeoJsonProperties, Polygon } from \"geojson\";\nimport { AllGeoJSON, polygon } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\nimport concaveman from \"concaveman\";\n\n/**\n * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.\n *\n * Internally this uses\n * the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that implements a\n * [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).\n *\n * @name convex\n * @param {GeoJSON} geojson input Feature or FeatureCollection\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull.\n * @param {Object} [options.properties={}] Translate Properties to Feature\n * @returns {Feature<Polygon>} a convex hull\n * @example\n * var points = turf.featureCollection([\n * turf.point([10.195312, 43.755225]),\n * turf.point([10.404052, 43.8424511]),\n * turf.point([10.579833, 43.659924]),\n * turf.point([10.360107, 43.516688]),\n * turf.point([10.14038, 43.588348]),\n * turf.point([10.195312, 43.755225])\n * ]);\n *\n * var hull = turf.convex(points);\n *\n * //addToMap\n * var addToMap = [points, hull]\n */\nfunction convex<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n concavity?: number;\n properties?: P;\n } = {}\n): Feature<Polygon, P> | null {\n // Default parameters\n options.concavity = options.concavity || Infinity;\n\n // Container\n const points: number[][] = [];\n\n // Convert all points to flat 2D coordinate Array\n coordEach(geojson, (coord) => {\n points.push([coord[0], coord[1]]);\n });\n if (!points.length) {\n return null;\n }\n\n const convexHull = concaveman(points, options.concavity);\n\n // Convex hull should have at least 3 different vertices in order to create a valid polygon\n if (convexHull.length > 3) {\n return polygon([convexHull]);\n }\n return null;\n}\n\nexport { convex };\nexport default convex;\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { GeoJsonProperties, Feature, Polygon } from 'geojson';
|
|
2
|
+
import { AllGeoJSON } from '@turf/helpers';
|
|
3
|
+
|
|
4
4
|
/**
|
|
5
5
|
* Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
|
|
6
6
|
*
|
|
@@ -29,22 +29,9 @@ import concaveman from "concaveman";
|
|
|
29
29
|
* //addToMap
|
|
30
30
|
* var addToMap = [points, hull]
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
coordEach(geojson, (coord) => {
|
|
39
|
-
points.push([coord[0], coord[1]]);
|
|
40
|
-
});
|
|
41
|
-
if (!points.length) {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
const convexHull = concaveman(points, options.concavity);
|
|
45
|
-
// Convex hull should have at least 3 different vertices in order to create a valid polygon
|
|
46
|
-
if (convexHull.length > 3) {
|
|
47
|
-
return polygon([convexHull]);
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
32
|
+
declare function convex<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
33
|
+
concavity?: number;
|
|
34
|
+
properties?: P;
|
|
35
|
+
}): Feature<Polygon, P> | null;
|
|
36
|
+
|
|
37
|
+
export { convex, convex as default };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AllGeoJSON } from
|
|
1
|
+
import { GeoJsonProperties, Feature, Polygon } from 'geojson';
|
|
2
|
+
import { AllGeoJSON } from '@turf/helpers';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
|
|
5
6
|
*
|
|
@@ -28,7 +29,9 @@ import { AllGeoJSON } from "@turf/helpers";
|
|
|
28
29
|
* //addToMap
|
|
29
30
|
* var addToMap = [points, hull]
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
|
+
declare function convex<P extends GeoJsonProperties = GeoJsonProperties>(geojson: AllGeoJSON, options?: {
|
|
32
33
|
concavity?: number;
|
|
33
34
|
properties?: P;
|
|
34
35
|
}): Feature<Polygon, P> | null;
|
|
36
|
+
|
|
37
|
+
export { convex, convex as default };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { polygon } from "@turf/helpers";
|
|
3
|
+
import { coordEach } from "@turf/meta";
|
|
4
|
+
import concaveman from "concaveman";
|
|
5
|
+
function convex(geojson, options = {}) {
|
|
6
|
+
options.concavity = options.concavity || Infinity;
|
|
7
|
+
const points = [];
|
|
8
|
+
coordEach(geojson, (coord) => {
|
|
9
|
+
points.push([coord[0], coord[1]]);
|
|
10
|
+
});
|
|
11
|
+
if (!points.length) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const convexHull = concaveman(points, options.concavity);
|
|
15
|
+
if (convexHull.length > 3) {
|
|
16
|
+
return polygon([convexHull]);
|
|
17
|
+
}
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var turf_convex_default = convex;
|
|
21
|
+
export {
|
|
22
|
+
convex,
|
|
23
|
+
turf_convex_default as default
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.ts"],"sourcesContent":["import { Feature, GeoJsonProperties, Polygon } from \"geojson\";\nimport { AllGeoJSON, polygon } from \"@turf/helpers\";\nimport { coordEach } from \"@turf/meta\";\nimport concaveman from \"concaveman\";\n\n/**\n * Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.\n *\n * Internally this uses\n * the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that implements a\n * [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).\n *\n * @name convex\n * @param {GeoJSON} geojson input Feature or FeatureCollection\n * @param {Object} [options={}] Optional parameters\n * @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull.\n * @param {Object} [options.properties={}] Translate Properties to Feature\n * @returns {Feature<Polygon>} a convex hull\n * @example\n * var points = turf.featureCollection([\n * turf.point([10.195312, 43.755225]),\n * turf.point([10.404052, 43.8424511]),\n * turf.point([10.579833, 43.659924]),\n * turf.point([10.360107, 43.516688]),\n * turf.point([10.14038, 43.588348]),\n * turf.point([10.195312, 43.755225])\n * ]);\n *\n * var hull = turf.convex(points);\n *\n * //addToMap\n * var addToMap = [points, hull]\n */\nfunction convex<P extends GeoJsonProperties = GeoJsonProperties>(\n geojson: AllGeoJSON,\n options: {\n concavity?: number;\n properties?: P;\n } = {}\n): Feature<Polygon, P> | null {\n // Default parameters\n options.concavity = options.concavity || Infinity;\n\n // Container\n const points: number[][] = [];\n\n // Convert all points to flat 2D coordinate Array\n coordEach(geojson, (coord) => {\n points.push([coord[0], coord[1]]);\n });\n if (!points.length) {\n return null;\n }\n\n const convexHull = concaveman(points, options.concavity);\n\n // Convex hull should have at least 3 different vertices in order to create a valid polygon\n if (convexHull.length > 3) {\n return polygon([convexHull]);\n }\n return null;\n}\n\nexport { convex };\nexport default convex;\n"],"mappings":";AACA,SAAqB,eAAe;AACpC,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AA8BvB,SAAS,OACP,SACA,UAGI,CAAC,GACuB;AAE5B,UAAQ,YAAY,QAAQ,aAAa;AAGzC,QAAM,SAAqB,CAAC;AAG5B,YAAU,SAAS,CAAC,UAAU;AAC5B,WAAO,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC;AAAA,EAClC,CAAC;AACD,MAAI,CAAC,OAAO,QAAQ;AAClB,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,WAAW,QAAQ,QAAQ,SAAS;AAGvD,MAAI,WAAW,SAAS,GAAG;AACzB,WAAO,QAAQ,CAAC,UAAU,CAAC;AAAA,EAC7B;AACA,SAAO;AACT;AAGA,IAAO,sBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/convex",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0-alpha.7+0ce6ecca0",
|
|
4
4
|
"description": "turf convex module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,48 +20,53 @@
|
|
|
20
20
|
"turf",
|
|
21
21
|
"gis"
|
|
22
22
|
],
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "dist/cjs/index.cjs",
|
|
25
|
+
"module": "dist/esm/index.js",
|
|
26
|
+
"types": "dist/esm/index.d.ts",
|
|
25
27
|
"exports": {
|
|
26
28
|
"./package.json": "./package.json",
|
|
27
29
|
".": {
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
"import": {
|
|
31
|
+
"types": "./dist/esm/index.d.ts",
|
|
32
|
+
"default": "./dist/esm/index.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/cjs/index.d.cts",
|
|
36
|
+
"default": "./dist/cjs/index.cjs"
|
|
37
|
+
}
|
|
31
38
|
}
|
|
32
39
|
},
|
|
33
|
-
"types": "dist/js/index.d.ts",
|
|
34
40
|
"sideEffects": false,
|
|
35
41
|
"files": [
|
|
36
42
|
"dist"
|
|
37
43
|
],
|
|
38
44
|
"scripts": {
|
|
39
|
-
"bench": "tsx bench.
|
|
40
|
-
"build": "
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"test": "npm-run-all test:*",
|
|
45
|
-
"test:tape": "tsx test.js"
|
|
45
|
+
"bench": "tsx bench.ts",
|
|
46
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
47
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
48
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
49
|
+
"test:tape": "tsx test.ts"
|
|
46
50
|
},
|
|
47
51
|
"devDependencies": {
|
|
48
|
-
"@types/
|
|
49
|
-
"@types/
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
52
|
+
"@types/benchmark": "^2.1.5",
|
|
53
|
+
"@types/concaveman": "^1.1.6",
|
|
54
|
+
"@types/tape": "^4.2.32",
|
|
55
|
+
"benchmark": "^2.1.4",
|
|
56
|
+
"glob": "^10.3.10",
|
|
57
|
+
"load-json-file": "^7.0.1",
|
|
58
|
+
"npm-run-all": "^4.1.5",
|
|
59
|
+
"tape": "^5.7.2",
|
|
60
|
+
"tsup": "^8.0.1",
|
|
61
|
+
"tsx": "^4.6.2",
|
|
62
|
+
"typescript": "^5.2.2",
|
|
63
|
+
"write-json-file": "^5.0.0"
|
|
59
64
|
},
|
|
60
65
|
"dependencies": {
|
|
61
|
-
"@turf/helpers": "^7.
|
|
62
|
-
"@turf/meta": "^7.
|
|
66
|
+
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0",
|
|
67
|
+
"@turf/meta": "^7.1.0-alpha.7+0ce6ecca0",
|
|
63
68
|
"concaveman": "^1.2.1",
|
|
64
|
-
"tslib": "^2.
|
|
69
|
+
"tslib": "^2.6.2"
|
|
65
70
|
},
|
|
66
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
|
|
67
72
|
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const helpers_1 = require("@turf/helpers");
|
|
5
|
-
const meta_1 = require("@turf/meta");
|
|
6
|
-
const concaveman_1 = tslib_1.__importDefault(require("concaveman"));
|
|
7
|
-
/**
|
|
8
|
-
* Takes a {@link Feature} or a {@link FeatureCollection} and returns a convex hull {@link Polygon}.
|
|
9
|
-
*
|
|
10
|
-
* Internally this uses
|
|
11
|
-
* the [convex-hull](https://github.com/mikolalysenko/convex-hull) module that implements a
|
|
12
|
-
* [monotone chain hull](http://en.wikibooks.org/wiki/Algorithm_Implementation/Geometry/Convex_hull/Monotone_chain).
|
|
13
|
-
*
|
|
14
|
-
* @name convex
|
|
15
|
-
* @param {GeoJSON} geojson input Feature or FeatureCollection
|
|
16
|
-
* @param {Object} [options={}] Optional parameters
|
|
17
|
-
* @param {number} [options.concavity=Infinity] 1 - thin shape. Infinity - convex hull.
|
|
18
|
-
* @param {Object} [options.properties={}] Translate Properties to Feature
|
|
19
|
-
* @returns {Feature<Polygon>} a convex hull
|
|
20
|
-
* @example
|
|
21
|
-
* var points = turf.featureCollection([
|
|
22
|
-
* turf.point([10.195312, 43.755225]),
|
|
23
|
-
* turf.point([10.404052, 43.8424511]),
|
|
24
|
-
* turf.point([10.579833, 43.659924]),
|
|
25
|
-
* turf.point([10.360107, 43.516688]),
|
|
26
|
-
* turf.point([10.14038, 43.588348]),
|
|
27
|
-
* turf.point([10.195312, 43.755225])
|
|
28
|
-
* ]);
|
|
29
|
-
*
|
|
30
|
-
* var hull = turf.convex(points);
|
|
31
|
-
*
|
|
32
|
-
* //addToMap
|
|
33
|
-
* var addToMap = [points, hull]
|
|
34
|
-
*/
|
|
35
|
-
function convex(geojson, options = {}) {
|
|
36
|
-
// Default parameters
|
|
37
|
-
options.concavity = options.concavity || Infinity;
|
|
38
|
-
// Container
|
|
39
|
-
const points = [];
|
|
40
|
-
// Convert all points to flat 2D coordinate Array
|
|
41
|
-
meta_1.coordEach(geojson, (coord) => {
|
|
42
|
-
points.push([coord[0], coord[1]]);
|
|
43
|
-
});
|
|
44
|
-
if (!points.length) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
const convexHull = concaveman_1.default(points, options.concavity);
|
|
48
|
-
// Convex hull should have at least 3 different vertices in order to create a valid polygon
|
|
49
|
-
if (convexHull.length > 3) {
|
|
50
|
-
return helpers_1.polygon([convexHull]);
|
|
51
|
-
}
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
exports.default = convex;
|