diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-07-24 19:24:03 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-07-24 19:24:03 -0400 |
| commit | de9a0ec966a20540cafdad1019d498530b60700f (patch) | |
| tree | 9d86c1409e5ad4e05c53ffce0fd0a7546b885235 /test/03-test-clipper.js | |
| parent | 9261438f86b1faf22a0f8d9a366fb0daa3dd090d (diff) | |
testing wallbuilding with some broken testcases..
Diffstat (limited to 'test/03-test-clipper.js')
| -rw-r--r-- | test/03-test-clipper.js | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/test/03-test-clipper.js b/test/03-test-clipper.js new file mode 100644 index 0000000..923a8a5 --- /dev/null +++ b/test/03-test-clipper.js @@ -0,0 +1,129 @@ +var assert = require("assert") +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") +var Clipper = require("../public/assets/javascripts/rectangles/engine/rooms/clipper.js") +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,5), new vec(1,5) ) +var east = new Rect( new vec(2,6), new vec(1,5) ) +var corner = new Rect( new vec(3,7), new vec(3,7) ) +var peninsula = new Rect( new vec(4,6), new vec(6,8) ) + +function report(a) { + console.log( a.join("\n") ) +} + +describe('clipper', function(){ + 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('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_iterative() + var culled_dupes = regions.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 returns 3 non-duplicate', function(){ + assert.equal(3, culled.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_iterative() + var culled_dupes = regions.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 returns 7 non-duplicate', function(){ + assert.equal(7, culled.length) + }) + }) + + // + + Rooms.list = {} + Rooms.regions = [] + Rooms.add_with_rect( rect ) + Rooms.add_with_rect( corner ) + Rooms.add_with_rect( peninsula ) + +/* + // this method uses a tree to match areas, which tends to leave extra overlapping regions + describe('#cull_rects(rect, corner, peninsula)', function(){ + Rooms.clipper.reset_rects() + var regions = Rooms.clipper.clip_rects() + var culled = Rooms.clipper.cull_rects() + var culled_dupes = regions.filter(function(r){ return r.dupe }) + + it('clipper returns 16 rects', function(){ + assert.equal(16, regions.length) + }) + it('culling marks 3 duplicate', function(){ + assert.equal(3, culled_dupes.length) + }) + it('culling returns 13 non-duplicate', function(){ + assert.equal(13, regions.length) + }) + }) +*/ + + // this method iterates to match areas, which omits regions in some cases + describe('#cull_rects_iterative(rect, corner, peninsula)', function(){ + Rooms.clipper.reset_rects() + var regions = Rooms.clipper.clip_rects() + var culled = Rooms.clipper.cull_rects_iterative() + var culled_dupes = regions.filter(function(r){ return r.dupe }) + + it('clipper returns 16 rects', function(){ + assert.equal(16, regions.length) + }) + it('culling marks 3 duplicate', function(){ + assert.equal(3, culled_dupes.length) + }) + it('culling returns 14 non-duplicate', function(){ + assert.equal(13, culled.length) + }) + }) + +}) + |
