@turf/square 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 +33 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +8 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/{es → esm}/index.js +10 -21
- package/dist/esm/index.js.map +1 -0
- package/package.json +27 -22
- package/dist/es/package.json +0 -1
- package/dist/js/index.js +0 -51
- package/index.d.ts +0 -6
package/README.md
CHANGED
|
@@ -25,26 +25,21 @@ Returns **[BBox][1]** a square surrounding `bbox`
|
|
|
25
25
|
|
|
26
26
|
[1]: https://tools.ietf.org/html/rfc7946#section-5
|
|
27
27
|
|
|
28
|
-
<!-- This file is automatically generated. Please don't edit it directly
|
|
29
|
-
if you find an error, edit the source file (likely index.js), and re-run
|
|
30
|
-
./scripts/generate-readmes in the turf project. -->
|
|
28
|
+
<!-- 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. -->
|
|
31
29
|
|
|
32
30
|
---
|
|
33
31
|
|
|
34
|
-
This module is part of the [Turfjs project](
|
|
35
|
-
module collection dedicated to geographic algorithms. It is maintained in the
|
|
36
|
-
[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
|
37
|
-
PRs and issues.
|
|
32
|
+
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.
|
|
38
33
|
|
|
39
34
|
### Installation
|
|
40
35
|
|
|
41
|
-
Install this module individually:
|
|
36
|
+
Install this single module individually:
|
|
42
37
|
|
|
43
38
|
```sh
|
|
44
39
|
$ npm install @turf/square
|
|
45
40
|
```
|
|
46
41
|
|
|
47
|
-
Or install the
|
|
42
|
+
Or install the all-encompassing @turf/turf module that includes all modules as functions:
|
|
48
43
|
|
|
49
44
|
```sh
|
|
50
45
|
$ npm install @turf/turf
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// index.js
|
|
2
|
+
var _distance = require('@turf/distance');
|
|
3
|
+
function square(bbox) {
|
|
4
|
+
var west = bbox[0];
|
|
5
|
+
var south = bbox[1];
|
|
6
|
+
var east = bbox[2];
|
|
7
|
+
var north = bbox[3];
|
|
8
|
+
var horizontalDistance = _distance.distance.call(void 0, bbox.slice(0, 2), [east, south]);
|
|
9
|
+
var verticalDistance = _distance.distance.call(void 0, bbox.slice(0, 2), [west, north]);
|
|
10
|
+
if (horizontalDistance >= verticalDistance) {
|
|
11
|
+
var verticalMidpoint = (south + north) / 2;
|
|
12
|
+
return [
|
|
13
|
+
west,
|
|
14
|
+
verticalMidpoint - (east - west) / 2,
|
|
15
|
+
east,
|
|
16
|
+
verticalMidpoint + (east - west) / 2
|
|
17
|
+
];
|
|
18
|
+
} else {
|
|
19
|
+
var horizontalMidpoint = (west + east) / 2;
|
|
20
|
+
return [
|
|
21
|
+
horizontalMidpoint - (north - south) / 2,
|
|
22
|
+
south,
|
|
23
|
+
horizontalMidpoint + (north - south) / 2,
|
|
24
|
+
north
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
var turf_square_default = square;
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
exports.default = turf_square_default; exports.square = square;
|
|
33
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"names":[],"mappings":";AAAA,SAAS,gBAAgB;AAgBzB,SAAS,OAAO,MAAM;AACpB,MAAI,OAAO,KAAK,CAAC;AACjB,MAAI,QAAQ,KAAK,CAAC;AAClB,MAAI,OAAO,KAAK,CAAC;AACjB,MAAI,QAAQ,KAAK,CAAC;AAElB,MAAI,qBAAqB,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;AACjE,MAAI,mBAAmB,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;AAC/D,MAAI,sBAAsB,kBAAkB;AAC1C,QAAI,oBAAoB,QAAQ,SAAS;AACzC,WAAO;AAAA,MACL;AAAA,MACA,oBAAoB,OAAO,QAAQ;AAAA,MACnC;AAAA,MACA,oBAAoB,OAAO,QAAQ;AAAA,IACrC;AAAA,EACF,OAAO;AACL,QAAI,sBAAsB,OAAO,QAAQ;AACzC,WAAO;AAAA,MACL,sBAAsB,QAAQ,SAAS;AAAA,MACvC;AAAA,MACA,sBAAsB,QAAQ,SAAS;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACF;AAGA,IAAO,sBAAQ","sourcesContent":["import { distance } from \"@turf/distance\";\n\n/**\n * Takes a bounding box and calculates the minimum square bounding box that\n * would contain the input.\n *\n * @name square\n * @param {BBox} bbox extent in [west, south, east, north] order\n * @returns {BBox} a square surrounding `bbox`\n * @example\n * var bbox = [-20, -20, -15, 0];\n * var squared = turf.square(bbox);\n *\n * //addToMap\n * var addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)]\n */\nfunction square(bbox) {\n var west = bbox[0];\n var south = bbox[1];\n var east = bbox[2];\n var north = bbox[3];\n\n var horizontalDistance = distance(bbox.slice(0, 2), [east, south]);\n var verticalDistance = distance(bbox.slice(0, 2), [west, north]);\n if (horizontalDistance >= verticalDistance) {\n var verticalMidpoint = (south + north) / 2;\n return [\n west,\n verticalMidpoint - (east - west) / 2,\n east,\n verticalMidpoint + (east - west) / 2,\n ];\n } else {\n var horizontalMidpoint = (west + east) / 2;\n return [\n horizontalMidpoint - (north - south) / 2,\n south,\n horizontalMidpoint + (north - south) / 2,\n north,\n ];\n }\n}\n\nexport { square };\nexport default square;\n"]}
|
package/dist/{es → esm}/index.js
RENAMED
|
@@ -1,25 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Takes a bounding box and calculates the minimum square bounding box that
|
|
5
|
-
* would contain the input.
|
|
6
|
-
*
|
|
7
|
-
* @name square
|
|
8
|
-
* @param {BBox} bbox extent in [west, south, east, north] order
|
|
9
|
-
* @returns {BBox} a square surrounding `bbox`
|
|
10
|
-
* @example
|
|
11
|
-
* var bbox = [-20, -20, -15, 0];
|
|
12
|
-
* var squared = turf.square(bbox);
|
|
13
|
-
*
|
|
14
|
-
* //addToMap
|
|
15
|
-
* var addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)]
|
|
16
|
-
*/
|
|
1
|
+
// index.js
|
|
2
|
+
import { distance } from "@turf/distance";
|
|
17
3
|
function square(bbox) {
|
|
18
4
|
var west = bbox[0];
|
|
19
5
|
var south = bbox[1];
|
|
20
6
|
var east = bbox[2];
|
|
21
7
|
var north = bbox[3];
|
|
22
|
-
|
|
23
8
|
var horizontalDistance = distance(bbox.slice(0, 2), [east, south]);
|
|
24
9
|
var verticalDistance = distance(bbox.slice(0, 2), [west, north]);
|
|
25
10
|
if (horizontalDistance >= verticalDistance) {
|
|
@@ -28,7 +13,7 @@ function square(bbox) {
|
|
|
28
13
|
west,
|
|
29
14
|
verticalMidpoint - (east - west) / 2,
|
|
30
15
|
east,
|
|
31
|
-
verticalMidpoint + (east - west) / 2
|
|
16
|
+
verticalMidpoint + (east - west) / 2
|
|
32
17
|
];
|
|
33
18
|
} else {
|
|
34
19
|
var horizontalMidpoint = (west + east) / 2;
|
|
@@ -36,9 +21,13 @@ function square(bbox) {
|
|
|
36
21
|
horizontalMidpoint - (north - south) / 2,
|
|
37
22
|
south,
|
|
38
23
|
horizontalMidpoint + (north - south) / 2,
|
|
39
|
-
north
|
|
24
|
+
north
|
|
40
25
|
];
|
|
41
26
|
}
|
|
42
27
|
}
|
|
43
|
-
|
|
44
|
-
export
|
|
28
|
+
var turf_square_default = square;
|
|
29
|
+
export {
|
|
30
|
+
turf_square_default as default,
|
|
31
|
+
square
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../index.js"],"sourcesContent":["import { distance } from \"@turf/distance\";\n\n/**\n * Takes a bounding box and calculates the minimum square bounding box that\n * would contain the input.\n *\n * @name square\n * @param {BBox} bbox extent in [west, south, east, north] order\n * @returns {BBox} a square surrounding `bbox`\n * @example\n * var bbox = [-20, -20, -15, 0];\n * var squared = turf.square(bbox);\n *\n * //addToMap\n * var addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)]\n */\nfunction square(bbox) {\n var west = bbox[0];\n var south = bbox[1];\n var east = bbox[2];\n var north = bbox[3];\n\n var horizontalDistance = distance(bbox.slice(0, 2), [east, south]);\n var verticalDistance = distance(bbox.slice(0, 2), [west, north]);\n if (horizontalDistance >= verticalDistance) {\n var verticalMidpoint = (south + north) / 2;\n return [\n west,\n verticalMidpoint - (east - west) / 2,\n east,\n verticalMidpoint + (east - west) / 2,\n ];\n } else {\n var horizontalMidpoint = (west + east) / 2;\n return [\n horizontalMidpoint - (north - south) / 2,\n south,\n horizontalMidpoint + (north - south) / 2,\n north,\n ];\n }\n}\n\nexport { square };\nexport default square;\n"],"mappings":";AAAA,SAAS,gBAAgB;AAgBzB,SAAS,OAAO,MAAM;AACpB,MAAI,OAAO,KAAK,CAAC;AACjB,MAAI,QAAQ,KAAK,CAAC;AAClB,MAAI,OAAO,KAAK,CAAC;AACjB,MAAI,QAAQ,KAAK,CAAC;AAElB,MAAI,qBAAqB,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;AACjE,MAAI,mBAAmB,SAAS,KAAK,MAAM,GAAG,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC;AAC/D,MAAI,sBAAsB,kBAAkB;AAC1C,QAAI,oBAAoB,QAAQ,SAAS;AACzC,WAAO;AAAA,MACL;AAAA,MACA,oBAAoB,OAAO,QAAQ;AAAA,MACnC;AAAA,MACA,oBAAoB,OAAO,QAAQ;AAAA,IACrC;AAAA,EACF,OAAO;AACL,QAAI,sBAAsB,OAAO,QAAQ;AACzC,WAAO;AAAA,MACL,sBAAsB,QAAQ,SAAS;AAAA,MACvC;AAAA,MACA,sBAAsB,QAAQ,SAAS;AAAA,MACvC;AAAA,IACF;AAAA,EACF;AACF;AAGA,IAAO,sBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turf/square",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0-alpha.7+0ce6ecca0",
|
|
4
4
|
"description": "turf square module",
|
|
5
5
|
"author": "Turf Authors",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,39 +22,44 @@
|
|
|
22
22
|
"geojson",
|
|
23
23
|
"extent"
|
|
24
24
|
],
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "dist/cjs/index.cjs",
|
|
27
|
+
"module": "dist/esm/index.js",
|
|
28
|
+
"types": "dist/esm/index.d.ts",
|
|
27
29
|
"exports": {
|
|
28
30
|
"./package.json": "./package.json",
|
|
29
31
|
".": {
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/esm/index.d.ts",
|
|
34
|
+
"default": "./dist/esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"require": {
|
|
37
|
+
"types": "./dist/cjs/index.d.cts",
|
|
38
|
+
"default": "./dist/cjs/index.cjs"
|
|
39
|
+
}
|
|
33
40
|
}
|
|
34
41
|
},
|
|
35
|
-
"types": "index.d.ts",
|
|
36
42
|
"sideEffects": false,
|
|
37
43
|
"files": [
|
|
38
|
-
"dist"
|
|
39
|
-
"index.d.ts"
|
|
44
|
+
"dist"
|
|
40
45
|
],
|
|
41
46
|
"scripts": {
|
|
42
|
-
"bench": "tsx bench.
|
|
43
|
-
"build": "
|
|
44
|
-
"docs": "tsx ../../scripts/generate-readmes",
|
|
45
|
-
"test": "npm-run-all test:*",
|
|
46
|
-
"test:tape": "tsx test.
|
|
47
|
+
"bench": "tsx bench.ts",
|
|
48
|
+
"build": "tsup --config ../../tsup.config.ts",
|
|
49
|
+
"docs": "tsx ../../scripts/generate-readmes.ts",
|
|
50
|
+
"test": "npm-run-all --npm-path npm test:*",
|
|
51
|
+
"test:tape": "tsx test.ts"
|
|
47
52
|
},
|
|
48
53
|
"devDependencies": {
|
|
49
|
-
"benchmark": "
|
|
50
|
-
"npm-run-all": "
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"tsx": "
|
|
54
|
+
"benchmark": "^2.1.4",
|
|
55
|
+
"npm-run-all": "^4.1.5",
|
|
56
|
+
"tape": "^5.7.2",
|
|
57
|
+
"tsup": "^8.0.1",
|
|
58
|
+
"tsx": "^4.6.2"
|
|
54
59
|
},
|
|
55
60
|
"dependencies": {
|
|
56
|
-
"@turf/distance": "^7.
|
|
57
|
-
"@turf/helpers": "^7.
|
|
61
|
+
"@turf/distance": "^7.1.0-alpha.7+0ce6ecca0",
|
|
62
|
+
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0"
|
|
58
63
|
},
|
|
59
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea"
|
|
60
65
|
}
|
package/dist/es/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/dist/js/index.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var distance = require('@turf/distance');
|
|
4
|
-
|
|
5
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
6
|
-
|
|
7
|
-
var distance__default = /*#__PURE__*/_interopDefaultLegacy(distance);
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Takes a bounding box and calculates the minimum square bounding box that
|
|
11
|
-
* would contain the input.
|
|
12
|
-
*
|
|
13
|
-
* @name square
|
|
14
|
-
* @param {BBox} bbox extent in [west, south, east, north] order
|
|
15
|
-
* @returns {BBox} a square surrounding `bbox`
|
|
16
|
-
* @example
|
|
17
|
-
* var bbox = [-20, -20, -15, 0];
|
|
18
|
-
* var squared = turf.square(bbox);
|
|
19
|
-
*
|
|
20
|
-
* //addToMap
|
|
21
|
-
* var addToMap = [turf.bboxPolygon(bbox), turf.bboxPolygon(squared)]
|
|
22
|
-
*/
|
|
23
|
-
function square(bbox) {
|
|
24
|
-
var west = bbox[0];
|
|
25
|
-
var south = bbox[1];
|
|
26
|
-
var east = bbox[2];
|
|
27
|
-
var north = bbox[3];
|
|
28
|
-
|
|
29
|
-
var horizontalDistance = distance__default['default'](bbox.slice(0, 2), [east, south]);
|
|
30
|
-
var verticalDistance = distance__default['default'](bbox.slice(0, 2), [west, north]);
|
|
31
|
-
if (horizontalDistance >= verticalDistance) {
|
|
32
|
-
var verticalMidpoint = (south + north) / 2;
|
|
33
|
-
return [
|
|
34
|
-
west,
|
|
35
|
-
verticalMidpoint - (east - west) / 2,
|
|
36
|
-
east,
|
|
37
|
-
verticalMidpoint + (east - west) / 2,
|
|
38
|
-
];
|
|
39
|
-
} else {
|
|
40
|
-
var horizontalMidpoint = (west + east) / 2;
|
|
41
|
-
return [
|
|
42
|
-
horizontalMidpoint - (north - south) / 2,
|
|
43
|
-
south,
|
|
44
|
-
horizontalMidpoint + (north - south) / 2,
|
|
45
|
-
north,
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
module.exports = square;
|
|
51
|
-
module.exports.default = square;
|