diff options
Diffstat (limited to 'assets/javascripts/rectangles/models/room.js')
| -rw-r--r-- | assets/javascripts/rectangles/models/room.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/assets/javascripts/rectangles/models/room.js b/assets/javascripts/rectangles/models/room.js new file mode 100644 index 0000000..8c9d67d --- /dev/null +++ b/assets/javascripts/rectangles/models/room.js @@ -0,0 +1,39 @@ +window.room = (function(){ + + var room = function(opt){ + this.id = opt.id || clipper.rooms.length + this.rect = opt.rect + this.regions = [] + this.height = opt.height || 200 + this.focused = false + } + + room.prototype.toString = function(){ + return this.rect.toString() + } + + room.prototype.reset = function(){ + var copy = this.rect.clone() + copy.id = this.id + copy.sides = FRONT | BACK | LEFT | RIGHT + this.regions = [ copy ] + } + + room.prototype.clipTo = function(r){ + // for each of this rect's regions split the region if necessary + var regions = this.regions + var splits + + for (var i = 0, len = regions.length; i < len; i++) { + if (regions[i] && regions[i].intersects(r)) { + splits = regions[i].split(r) + regions = regions.concat(splits) + regions[i] = null + } + } + this.regions = regions + } + + return room + +})() |
