From 73ba5656bd27f4fb40ef59b8a94f69c4af6b8b8a Mon Sep 17 00:00:00 2001
From: Holden Rohrer <holden.rohrer@gmail.com>
Date: Fri, 27 Dec 2019 00:08:46 -0500
Subject: added more utils

---
 utils/measurespace.js  | 13 +++++++++++++
 utils/rectintersect.js |  9 +++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 utils/measurespace.js
 create mode 100644 utils/rectintersect.js

(limited to 'utils')

diff --git a/utils/measurespace.js b/utils/measurespace.js
new file mode 100644
index 0000000..4020926
--- /dev/null
+++ b/utils/measurespace.js
@@ -0,0 +1,13 @@
+// Provides a utility which takes a Space, and returns its minimum and maximum x/y coordinates, based on .loc and .data
+
+const vec = require('./vec');
+
+module.exports = function(space){
+  let min = space.loc;
+  let data = space.data;
+  let disp = [data.length, 0];
+  for (let i = 0; i < data.length; i++){
+    disp[1] = Math.max(disp[1], data[i].length);
+  }
+  return [min, vec.add(min, disp)];
+}
diff --git a/utils/rectintersect.js b/utils/rectintersect.js
new file mode 100644
index 0000000..bd2c479
--- /dev/null
+++ b/utils/rectintersect.js
@@ -0,0 +1,9 @@
+// Provides rectIntersect, to determine if two rectangles intersect (and hide the code)
+
+module.exports = function(one, two){ // Rectangles defined by min/max pairs of y/x coords
+  if ( one[0][0] > two[1][0] ||
+       two[0][0] > one[1][0] ||
+       one[0][1] > two[1][1] ||
+       two[0][1] > two[1][1] ) return false;
+  return true;
+}
-- 
cgit