aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-09-25 12:11:08 -0400
committerbob <bcz@cs.brown.edu>2019-09-25 12:11:08 -0400
commit0a5b90021c0f48a3c5c6801b96b2c8834639a695 (patch)
tree0a074fa7995a4ff62148c6086dcdf9759dfd2bae /src/Utils.ts
parentb57741dbed846313e1b9d0dad3b6c8add2566277 (diff)
parentb69106994f5450e2ac2c515f28dacceb2e13b78b (diff)
Merge branch 'master' into pdf_refactor
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 65eb3cffd..4fac53c7d 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -235,6 +235,21 @@ export function timenow() {
return now.toLocaleDateString() + ' ' + h + ':' + m + ' ' + ampm;
}
+export function aggregateBounds(boundsList: { x: number, y: number, width: number, height: number }[]) {
+ return boundsList.reduce((bounds, b) => {
+ var [sptX, sptY] = [b.x, b.y];
+ let [bptX, bptY] = [sptX + b.width, sptY + b.height];
+ return {
+ x: Math.min(sptX, bounds.x), y: Math.min(sptY, bounds.y),
+ r: Math.max(bptX, bounds.r), b: Math.max(bptY, bounds.b)
+ };
+ }, { x: Number.MAX_VALUE, y: Number.MAX_VALUE, r: -Number.MAX_VALUE, b: -Number.MAX_VALUE });
+}
+export function intersectRect(r1: { left: number, top: number, width: number, height: number },
+ r2: { left: number, top: number, width: number, height: number }) {
+ return !(r2.left > r1.left + r1.width || r2.left + r2.width < r1.left || r2.top > r1.top + r1.height || r2.top + r2.height < r1.top);
+}
+
export function percent2frac(percent: string) {
return Number(percent.substr(0, percent.length - 1)) / 100;
}