diff options
author | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-18 20:56:40 -0500 |
---|---|---|
committer | Holden Rohrer <holden.rohrer@gmail.com> | 2019-12-18 20:56:40 -0500 |
commit | cb7d31d863320db9257a619eea0422cc43bb05a4 (patch) | |
tree | 9d2bedc9e6458423dcb923d786a9bf56563494fc | |
parent | df83eaa9e4a0e2697859cda0c7a075259c147886 (diff) |
added getdims and removed bug notice on README
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | utils/getdims.js | 15 |
2 files changed, 16 insertions, 1 deletions
@@ -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 |