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 /utils | |
parent | df83eaa9e4a0e2697859cda0c7a075259c147886 (diff) |
added getdims and removed bug notice on README
Diffstat (limited to 'utils')
-rw-r--r-- | utils/getdims.js | 15 |
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 |