+16
| function sort(bboxes) { | ||
| return bboxes.sort((a, b) => { | ||
| const [axmin, aymin, axmax, aymax] = a; | ||
| const [bxmin, bymin, bxmax, bymax] = b; | ||
| if (axmin < bxmin) return -1; | ||
| if (axmin > bxmin) return 1; | ||
| if (aymin < bymin) return 1; | ||
| if (aymin > bymin) return -1; | ||
| return 0; | ||
| }); | ||
| } | ||
| module.exports = sort; | ||
| module.exports.default = sort; |
+2
-0
@@ -24,2 +24,3 @@ "use_strict"; | ||
| const shift = require("./shift.js"); | ||
| const sort = require("./sort.js"); | ||
| const split = require("./split.js"); | ||
@@ -56,2 +57,3 @@ const validate = require("./validate.js"); | ||
| preciseValidate, | ||
| sort, | ||
| union, | ||
@@ -58,0 +60,0 @@ unwrap |
+2
-1
| { | ||
| "name": "bbox-fns", | ||
| "version": "0.18.0", | ||
| "version": "0.19.0", | ||
| "description": "Light-weight JavaScript Bounding Box Utility Functions", | ||
@@ -32,2 +32,3 @@ "main": "./index.js", | ||
| "shift.js", | ||
| "sort.js", | ||
| "split.js", | ||
@@ -34,0 +35,0 @@ "union.js", |
+13
-0
@@ -29,2 +29,3 @@ # bbox-fns: work in progress | ||
| - [shift](#shift) | ||
| - [sort](#sort) | ||
| - [split](#split) | ||
@@ -331,2 +332,14 @@ - [union](#union) | ||
| ### sort | ||
| ```js | ||
| import sort from "bbox-fns/sort.js"; | ||
| const bboxes = [ | ||
| [175, -85, 180, 90], | ||
| [-180, -85, -175, 90] | ||
| ]; | ||
| sort(bboxes) | ||
| [[-180,-85,-175,90],[175,-85,180,90]] | ||
| ``` | ||
| ### union | ||
@@ -333,0 +346,0 @@ Combine all bounding boxes that intersect. |
+3
-0
| "use_strict"; | ||
| const shift = require("./shift.js"); | ||
| const sort = require("./sort.js"); | ||
| const split = require("./split.js"); | ||
@@ -42,2 +43,4 @@ const union = require("./union.js"); | ||
| bboxes = sort(bboxes); | ||
| return bboxes; | ||
@@ -44,0 +47,0 @@ } |
43911
1.55%33
3.13%831
2.09%415
3.23%