summaryrefslogtreecommitdiff
path: root/debian/tests/test_modules/topojson-client/src/bbox.js
diff options
context:
space:
mode:
Diffstat (limited to 'debian/tests/test_modules/topojson-client/src/bbox.js')
-rw-r--r--debian/tests/test_modules/topojson-client/src/bbox.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/debian/tests/test_modules/topojson-client/src/bbox.js b/debian/tests/test_modules/topojson-client/src/bbox.js
new file mode 100644
index 0000000..3b12204
--- /dev/null
+++ b/debian/tests/test_modules/topojson-client/src/bbox.js
@@ -0,0 +1,39 @@
+import transform from "./transform.js";
+
+export default function(topology) {
+ var t = transform(topology.transform), key,
+ x0 = Infinity, y0 = x0, x1 = -x0, y1 = -x0;
+
+ function bboxPoint(p) {
+ p = t(p);
+ if (p[0] < x0) x0 = p[0];
+ if (p[0] > x1) x1 = p[0];
+ if (p[1] < y0) y0 = p[1];
+ if (p[1] > y1) y1 = p[1];
+ }
+
+ function bboxGeometry(o) {
+ switch (o.type) {
+ case "GeometryCollection": o.geometries.forEach(bboxGeometry); break;
+ case "Point": bboxPoint(o.coordinates); break;
+ case "MultiPoint": o.coordinates.forEach(bboxPoint); break;
+ }
+ }
+
+ topology.arcs.forEach(function(arc) {
+ var i = -1, n = arc.length, p;
+ while (++i < n) {
+ p = t(arc[i], i);
+ if (p[0] < x0) x0 = p[0];
+ if (p[0] > x1) x1 = p[0];
+ if (p[1] < y0) y0 = p[1];
+ if (p[1] > y1) y1 = p[1];
+ }
+ });
+
+ for (key in topology.objects) {
+ bboxGeometry(topology.objects[key]);
+ }
+
+ return [x0, y0, x1, y1];
+}