diff options
| author | Julie Lala <jules@okfoc.us> | 2014-07-23 18:51:51 -0400 |
|---|---|---|
| committer | Julie Lala <jules@okfoc.us> | 2014-07-23 18:51:51 -0400 |
| commit | 5e0c67b5d70d90ea12b207e3c442378559f8f219 (patch) | |
| tree | ebda69733e3362243d5f2225425acc51fd8ef34d /test/03-test-clipping.js | |
| parent | c7e27b743eb8488ec71adaf365056ff500b458ab (diff) | |
basic culling tests
Diffstat (limited to 'test/03-test-clipping.js')
| -rw-r--r-- | test/03-test-clipping.js | 77 |
1 files changed, 70 insertions, 7 deletions
diff --git a/test/03-test-clipping.js b/test/03-test-clipping.js index 1668bd1..4743eb0 100644 --- a/test/03-test-clipping.js +++ b/test/03-test-clipping.js @@ -1,5 +1,5 @@ var assert = require("assert") -var vec2 = require("../public/assets/javascripts/rectangles/models/vec2.js") +var vec = require("../public/assets/javascripts/rectangles/models/vec2.js") var Rect = require("../public/assets/javascripts/rectangles/models/rect.js") var Room = require("../public/assets/javascripts/rectangles/models/room.js") var Rooms = require("../public/assets/javascripts/rectangles/engine/rooms/_rooms.js") @@ -7,15 +7,78 @@ var Clipper = require("../public/assets/javascripts/rectangles/engine/rooms/clip var FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20 var ALL = FRONT | BACK | LEFT | RIGHT +var rect = new Rect( new vec(1,4), new vec(1,4) ) +var east = new Rect( new vec(2,5), new vec(1,4) ) +var corner = new Rect( new vec(3,5), new vec(3,5) ) + +function report(a) { + console.log( a.join("\n") ) +} + describe('clipper', function(){ - describe('#intersects()', function(){ - // var rect = new Rect(0, 0, 10, 10) + Rooms.list = {} + Rooms.regions = [] + Rooms.add_with_rect( rect ) + Rooms.add_with_rect( east ) + + describe('#clip_rects(rect, east)', function(){ + Rooms.clipper.reset_rects() + var regions = Rooms.clipper.clip_rects() - /* - it('intersects itself', function(){ - assert.equal(true, rect.intersects( new Rect(0, 0, 10, 10) )); + it('contains duplicates', function(){ + var map = {} + var state = regions.some(function(a){ + var s = a.toString() + if (s in map) return true + map[s] = s + return false + }) + assert.equal(true, state) + }) + }) + + describe('#cull_rects(rect, east)', function(){ + Rooms.clipper.reset_rects() + var regions = Rooms.clipper.clip_rects() + var culled = Rooms.clipper.cull_rects() + var culled_dupes = culled.filter(function(r){ return r.dupe }) + var culled_regions = culled.filter(function(r){ return ! r.dupe }) + + it('clipper returns 4 rects', function(){ + assert.equal(4, regions.length) + }) + it('culling marks 1 duplicate', function(){ + assert.equal(1, culled_dupes.length) + }) + it('culling marks 3 non-duplicate', function(){ + assert.equal(3, culled_regions.length) }) - */ + }) + + // + + Rooms.list = {} + Rooms.regions = [] + Rooms.add_with_rect( rect ) + Rooms.add_with_rect( corner ) + describe('#cull_rects(rect, corner)', function(){ + Rooms.clipper.reset_rects() + var regions = Rooms.clipper.clip_rects() + var culled = Rooms.clipper.cull_rects() + var culled_dupes = culled.filter(function(r){ return r.dupe }) + var culled_regions = culled.filter(function(r){ return ! r.dupe }) + + it('clipper returns 8 rects', function(){ + assert.equal(8, regions.length) + }) + it('culling marks 1 duplicate', function(){ + assert.equal(1, culled_dupes.length) + }) + it('culling marks 7 non-duplicate', function(){ + assert.equal(7, culled_regions.length) + }) }) + }) + |
