summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/models/rect.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/javascripts/rectangles/models/rect.js')
-rw-r--r--assets/javascripts/rectangles/models/rect.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js
index 86cdae3..51162c0 100644
--- a/assets/javascripts/rectangles/models/rect.js
+++ b/assets/javascripts/rectangles/models/rect.js
@@ -1,6 +1,15 @@
var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8,
FRONT_BACK = FRONT | BACK, LEFT_RIGHT = LEFT | RIGHT
+function sidesToString(sides){
+ var s = ""
+ if (sides & FRONT) s += "front "
+ if (sides & BACK) s += "back "
+ if (sides & LEFT) s += "left "
+ if (sides & RIGHT) s += "right "
+ return s
+}
+
window.rect = (function(){
var rect = function (x0,y0,x1,y1){
if (x0 instanceof vec2) {
@@ -49,17 +58,16 @@ window.rect = (function(){
rect.prototype.contains = function(x,y){
return this.x.contains(x) && this.y.contains(y)
}
+ rect.prototype.containsDisc = function(x,y,r){
+ return this.x.contains(x,r) && this.y.contains(y,r)
+ }
rect.prototype.intersects = function(r){
return this.x.intersects(r.x) && this.y.intersects(r.y)
}
rect.prototype.width = function(){ return this.x.length() }
rect.prototype.height = function(){ return this.y.length() }
rect.prototype.toString = function(){
- var sides = ""
- if (this.sides & FRONT) sides += "front "
- if (this.sides & BACK) sides += "back "
- if (this.sides & LEFT) sides += "left "
- if (this.sides & RIGHT) sides += "right "
+ var sides = sidesToString(this.sides)
var s = "[" + this.x.toString() + " " + this.y.toString() + "] " + sides
return s
}