src/hg/js/utils.js 1.24

1.24 2009/08/23 20:38:06 larrym
add Rectangle class support
Index: src/hg/js/utils.js
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/js/utils.js,v
retrieving revision 1.23
retrieving revision 1.24
diff -b -B -U 4 -r1.23 -r1.24
--- src/hg/js/utils.js	20 Aug 2009 17:07:48 -0000	1.23
+++ src/hg/js/utils.js	23 Aug 2009 20:38:06 -0000	1.24
@@ -409,4 +409,32 @@
         hgsid = getURLParam(window.location.href, "hgsid");
     }
     return hgsid;
 }
+
+function Rectangle()
+{
+// Rectangle object constructor:
+// calling syntax:
+// 
+// new Rectangle(startX, endX, startY, endY)
+// new Rectangle(coords) <-- coordinate string from an area item
+    if(arguments.length == 4) {
+        this.startX = arguments[0];
+        this.endX = arguments[1];
+        this.startY = arguments[2];
+        this.endY = arguments[3];
+    } else {
+        var coords = arguments[0].split(",");
+        this.startX = coords[0];
+        this.endX = coords[2];
+        this.startY = coords[1];
+        this.endY = coords[3];
+    }
+}
+
+Rectangle.prototype.contains = function(x, y)
+{
+// returns true if given points are in the rectangle
+    var retval = x >= this.startX && x <= this.endX && y >= this.startY && y <= this.endY;
+    return retval;
+}