summaryrefslogtreecommitdiff
path: root/test/03-test-clipping.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/03-test-clipping.js')
-rw-r--r--test/03-test-clipping.js77
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)
+ })
})
+
})
+