« get me outta code hell

client: WikiRect.contains, containedWithin - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-03-09 15:39:00 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-03-09 15:40:23 -0400
commit47efe8bf8378515ae2647dd20bae07635dd403c0 (patch)
tree6b75a0dfa95e208115226e1cc3c37c7ba6f0f5c2 /src
parentdc978010dba8a7780771c79dcdc3894ba7971d67 (diff)
client: WikiRect.contains, containedWithin
Diffstat (limited to 'src')
-rw-r--r--src/static/client3.js29
1 files changed, 23 insertions, 6 deletions
diff --git a/src/static/client3.js b/src/static/client3.js
index 37bcee57..a44c4803 100644
--- a/src/static/client3.js
+++ b/src/static/client3.js
@@ -549,6 +549,28 @@ class WikiRect extends DOMRect {
     return Reflect.construct(this.constructor, [x, y, width, height]);
   }
 
+  // Comparisons
+
+  equals(rect) {
+    const rectNormalized = WikiRect.fromRect(rect).toNormalized();
+    const thisNormalized = this.toNormalized();
+
+    return (
+      rectNormalized.x === thisNormalized.x &&
+      rectNormalized.y === thisNormalized.y &&
+      rectNormalized.width === thisNormalized.width &&
+      rectNormalized.height === thisNormalized.height
+    );
+  }
+
+  contains(rect) {
+    return this.intersectionWith(rect).equals(rect);
+  }
+
+  containedWithin(rect) {
+    return this.intersectionWith(rect).equals(this);
+  }
+
   // Interfacing utilities
 
   static fromRect(rect) {
@@ -1437,12 +1459,7 @@ function positionTooltipFromHoverableWithBrains(hoverable) {
 
   const {baseline: baselineRect} = opportunities;
 
-  if (
-    tooltipRect.top >= baselineRect.top &&
-    tooltipRect.bottom <= baselineRect.bottom &&
-    tooltipRect.left >= baselineRect.left &&
-    tooltipRect.right <= baselineRect.right
-  ) {
+  if (baselineRect.contains(tooltipRect)) {
     return;
   }