diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-08-21 16:05:55 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-08-21 16:05:55 -0400 |
| commit | 3e87dcb3de9ad29f7c021792cbafc32d4c758d3f (patch) | |
| tree | 6f73303f7b4c0a47dd8f9d55009795c2181e47af /public/assets/javascripts/rectangles/engine/shapes/regionlist.js | |
| parent | 0c1864a114a2efe1a3bb8b2b4951e8655712757a (diff) | |
assigning sides
Diffstat (limited to 'public/assets/javascripts/rectangles/engine/shapes/regionlist.js')
| -rw-r--r-- | public/assets/javascripts/rectangles/engine/shapes/regionlist.js | 59 |
1 files changed, 51 insertions, 8 deletions
diff --git a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js index 93a0df7..fb2c8e5 100644 --- a/public/assets/javascripts/rectangles/engine/shapes/regionlist.js +++ b/public/assets/javascripts/rectangles/engine/shapes/regionlist.js @@ -27,7 +27,7 @@ var RegionList = (function(){ open_segments.splice(j--, 1) x_segment = new vec2( open_segment.x.a, segment.x.b ) - y_segments = open_segment.y.split(segment.y, TOP, BOTTOM) + y_segments = open_segment.y.split(segment.y, 0, 0) seen_segments = {} @@ -35,9 +35,11 @@ var RegionList = (function(){ seen_segments[ seg[0]+"" ] = true var room = new Rect( x_segment, seg[0] ) - if (seen_rooms[ room+"" ]) return; - + if (seen_rooms[ room+"" ]) return seen_rooms[ room+"" ] = true + + room.sides = 0 + rooms.push(room) var new_seg = new Rect( segment.x, seg[0] ) open_segments.unshift(new_seg) @@ -54,7 +56,6 @@ var RegionList = (function(){ } } if (overlapped) { - // sort open segments? open_segments = open_segments.sort(function(a,b){ if (a.y.a < b.y.a) { return -1 } if (a.y.a == b.y.a) { return 0 } @@ -69,7 +70,6 @@ var RegionList = (function(){ } else if (open_segments[k-1].y.overlaps(open_segments[k].y)) { open_segments[k].y = open_segments[k].y.clone() - console.log(open_segments[k-1].y+"", open_segments[k].y+"") open_segments[k].y.a = open_segments[k-1].y.b } } @@ -79,14 +79,57 @@ var RegionList = (function(){ } } + var splits, splitter + for (var i = 0; i < segments.length; i++) { segment = segments[i] - if (! segment.isHorizontal()) { - continue + var horizontal = segment.isHorizontal(), vertical = segment.isVertical() + for (var r = 0; r < rooms.length; r++){ + room = rooms[r] + if (vertical) { + if (segment.y.containsVec(room.y)) { + if (segment.x.a == room.x.a) { + room.sides |= LEFT + } + if (segment.x.a == room.x.b) { + room.sides |= RIGHT + } + } + } + if (horizontal) { + if (segment.x.containsVec(room.x)) { + if (segment.y.a == room.y.a) { + room.sides |= FRONT + } + if (segment.y.a == room.y.b) { + room.sides |= BACK + } + } +/* + else if ((segment.y.a == room.y.a || segment.y.a == room.y.b) && room.x.containsVec(segment.x)) { + splits = room.x.split(segment.x, LEFT, RIGHT) + for (var k = 0; k < splits.length; k++) { + splitter = splits[k] + var new_room = new Rect( splitter[0], room.y ) + new_room.sides |= splitter[1] + if (segment.x.containsVec(splitter[0])) { + if (segment.y.a == room.y.a) { + room.sides |= FRONT + } + if (segment.y.a == room.y.b) { + room.sides |= BACK + } + } + rooms.unshift(new_room) + r++ + } + } +*/ + } } } - return { rooms: rooms, open_segments: open_segments, segments: segments, closed_segments: closed_segments } + return { rooms: rooms } } RegionList.getSortedSegments = function(){ |
