summaryrefslogtreecommitdiff
path: root/assets/javascripts/rectangles/models/room.js
blob: 3d512c3818ef2b4de4d089a909246cf302ace02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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 ]
		this.intersects = []
		this.constructed = false
	}

	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

})()