diff options
Diffstat (limited to 'assets/javascripts/rectangles/models')
| -rw-r--r-- | assets/javascripts/rectangles/models/rect.js | 34 | ||||
| -rw-r--r-- | assets/javascripts/rectangles/models/wall.js | 13 |
2 files changed, 41 insertions, 6 deletions
diff --git a/assets/javascripts/rectangles/models/rect.js b/assets/javascripts/rectangles/models/rect.js index a5ae9bf..aca9212 100644 --- a/assets/javascripts/rectangles/models/rect.js +++ b/assets/javascripts/rectangles/models/rect.js @@ -53,6 +53,24 @@ window.Rect = (function(){ this.translation.a = this.translation.b = 0 return this } + Rect.prototype.resize = function(translation, sides){ + var translation = translation || this.translation + sides = sides || translation.sides + + if (sides & LEFT) { + this.x.a += translation.a + } + if (sides & RIGHT) { + this.x.b += translation.a + } + if (sides & FRONT) { + this.y.a += translation.b + } + if (sides & BACK) { + this.y.b += translation.b + } + this.translation.a = this.translation.b = 0 + } Rect.prototype.contains = function(x,y){ return this.x.contains(x) && this.y.contains(y) } @@ -62,6 +80,22 @@ window.Rect = (function(){ Rect.prototype.intersects = function(r){ return this.x.intersects(r.x) && this.y.intersects(r.y) } + Rect.prototype.nearEdge = function (x, y, r) { + var edges = 0 + if (x < this.x.a+r) { + edges |= LEFT + } + else if (x > this.x.b-r) { + edges |= RIGHT + } + if (y < this.y.a+r) { + edges |= FRONT + } + else if (y > this.y.b-r) { + edges |= BACK + } + return edges + } Rect.prototype.width = function(){ return this.x.length() } Rect.prototype.height = function(){ return this.y.length() } Rect.prototype.toString = function(){ diff --git a/assets/javascripts/rectangles/models/wall.js b/assets/javascripts/rectangles/models/wall.js index 73b98b8..8a74782 100644 --- a/assets/javascripts/rectangles/models/wall.js +++ b/assets/javascripts/rectangles/models/wall.js @@ -1,6 +1,7 @@ -window.Wall = (function(){ +var painting_distance_from_wall = 8 + - var PAINTING_DISTANCE_FROM_WALL = 5 +window.Wall = (function(){ var Wall = function(opt){ this.id = opt.id @@ -77,18 +78,18 @@ window.Wall = (function(){ switch (this.side) { case FRONT: x = major_axis.midpoint() - z = minor_axis.a + PAINTING_DISTANCE_FROM_WALL + z = minor_axis.a + painting_distance_from_wall break case BACK: x = major_axis.midpoint() - z = minor_axis.b - PAINTING_DISTANCE_FROM_WALL + z = minor_axis.b - painting_distance_from_wall break case LEFT: - x = minor_axis.a + PAINTING_DISTANCE_FROM_WALL + x = minor_axis.a + painting_distance_from_wall z = major_axis.midpoint() break case RIGHT: - x = minor_axis.b - PAINTING_DISTANCE_FROM_WALL + x = minor_axis.b - painting_distance_from_wall z = major_axis.midpoint() break } |
