From 5e0c67b5d70d90ea12b207e3c442378559f8f219 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Wed, 23 Jul 2014 18:51:51 -0400 Subject: basic culling tests --- test/00-setup.js | 2 +- test/02-test-rect.js | 22 ++++++++++++++ test/03-test-clipping.js | 77 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 93 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/00-setup.js b/test/00-setup.js index 8d06a13..78ad2c4 100644 --- a/test/00-setup.js +++ b/test/00-setup.js @@ -1,2 +1,2 @@ -Error.stackTraceLimit = 1 +Error.stackTraceLimit = 5 diff --git a/test/02-test-rect.js b/test/02-test-rect.js index 55f1ec9..29998da 100644 --- a/test/02-test-rect.js +++ b/test/02-test-rect.js @@ -183,6 +183,28 @@ describe('rect', function(){ it('corner splits on all 4 sides', function(){ assert.equal(ALL, sides(s1)) }) + + var rect_map = {} + var corner_map = {} + var rect_state = s0.forEach(function(r){ + rect_map[r.sides] = rect_map[r.sides] || [] + rect_map[r.sides].push(r) + }) + var corner_state = s1.forEach(function(r){ + corner_map[r.sides] = corner_map[r.sides] || [] + corner_map[r.sides].push(r) + }) + + it('rect contains a rect with no sides', function(){ + assert.equal(1, rect_map[0].length) + }) + it('corner contains a rect with no sides', function(){ + assert.equal(1, corner_map[0].length) + }) + it('rect and corner overlap', function(){ + assert.equal(String(rect_map[0][0]), String(corner_map[0][0])) + }) + }) }) 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) + }) }) + }) + -- cgit v1.2.3-70-g09d2