aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/getdims.js15
1 files changed, 15 insertions, 0 deletions
diff --git a/utils/getdims.js b/utils/getdims.js
new file mode 100644
index 0000000..2c18964
--- /dev/null
+++ b/utils/getdims.js
@@ -0,0 +1,15 @@
+// Takes a list of coordinate pairs (like the keys from a fetch block) and returns a dimension
+
+function dims(coords){
+ ext = [[Infinity, Infinity], [-Infinity, -Infinity]]
+ for (let i=0; i<coords.length; i++){
+ let coord = coords[i];
+ if (coord[0] < ext[0][0]) ext[0][0] = coord[0];
+ if (coord[1] < ext[0][1]) ext[0][1] = coord[1];
+ if (coord[0] > ext[1][0]) ext[1][0] = coord[0];
+ if (coord[1] > ext[1][1]) ext[1][1] = coord[1];
+ }
+ return ext;
+}
+
+exports = dims