aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--utils/getdims.js15
2 files changed, 16 insertions, 1 deletions
diff --git a/README.md b/README.md
index 158aed2..88f1cfe 100644
--- a/README.md
+++ b/README.md
@@ -18,4 +18,4 @@ Currently, `socket.js` provides `Socket` which has a few signals and functions (
`space.js` provides some dense spatial data management with `Space`, which is really good for specific dialogs and tests, but there may be some more work to be done to create a sparse storage device.
-`examples/helloworld.js` can get you started. Everything in that should work pretty well, but the remainder of the repo is probably pretty buggy until I test it.
+`examples/helloworld.js` can get you started. Everything in the core API (`utils`, `socket.js`, `space.js`) should be pretty stable, but please don't hesitate to report a bug.
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