diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-07-22 16:23:57 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-07-22 16:23:57 -0400 |
| commit | 725cc3cd23890d5369ae20c27c97465c34168913 (patch) | |
| tree | a2e398ab6694ad53a9d5d03decfe41203f9badca /test/test-rect.js | |
| parent | e2b1d4ca8c7a83b41fe4c0fc6c4d9490a6736c68 (diff) | |
starting math tests
Diffstat (limited to 'test/test-rect.js')
| -rw-r--r-- | test/test-rect.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/test/test-rect.js b/test/test-rect.js new file mode 100644 index 0000000..7dd7ae6 --- /dev/null +++ b/test/test-rect.js @@ -0,0 +1,63 @@ +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 FRONT = 0x1, BACK = 0x2, LEFT = 0x4, RIGHT = 0x8, FLOOR = 0x10, CEILING = 0x20 +var ALL = FRONT | BACK | LEFT | RIGHT + +describe('rect', function(){ + describe('#intersects()', function(){ + var rect = new Rect(0, 0, 10, 10) + + it('intersects itself', function(){ + assert.equal(true, rect.intersects( new Rect(0, 0, 10, 10) )); + }) + it('intersects more wide', function(){ + assert.equal(true, rect.intersects( new Rect(0, 0, 5, 10) )); + }) + it('intersects less wide', function(){ + assert.equal(true, rect.intersects( new Rect(0, 0, 15, 10) )); + }) + it('intersects more tall', function(){ + assert.equal(true, rect.intersects( new Rect(0, 0, 10, 5) )); + }) + it('intersects less tall', function(){ + assert.equal(true, rect.intersects( new Rect(0, 0, 10, 15) )); + }) + it('intersects if right-adjacent', function(){ + assert.equal(true, rect.intersects( new Rect(10, 0, 20, 10) )); + }) + it('intersects if bottom-adjacent', function(){ + assert.equal(true, rect.intersects( new Rect(0, 10, 10, 20) )); + }) + it('does not intersect if to the right', function(){ + assert.equal(false, rect.intersects( new Rect(20, 0, 40, 10) )); + }) + it('does not intersect if beneath', function(){ + assert.equal(false, rect.intersects( new Rect(0, 20, 10, 40) )); + }) + /* + it('does not intersect if corners intersect', function(){ + assert.equal(false, rect.intersects( new Rect(10, 10, 20, 20) )); + }) + */ + + }) + describe('#split()', function(){ + var rect = new Rect( 0, 0, 10, 10) + var east = new Rect( 5, 0, 15, 10) + var east_in = new Rect( 5, 0, 10, 10) + var east_edge = new Rect(10, 0, 20, 10) + var south = new Rect( 0, 5, 10, 15) + var south_in = new Rect( 0, 5, 10, 10) + var south_edge = new Rect( 0, 10, 10, 15) + var corner = new Rect( 5, 5, 15, 15) + + it('splits east', function(){ + var splits = rect.split(east) + var splits2 = east.split(rect) + console.log("\n") + console.log(rect+"") + console.log(splits.map(function(r){ return r.toString() })) + }) + }) +}) |
