summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulie Lala <jules@okfoc.us>2014-07-23 11:11:08 -0400
committerJulie Lala <jules@okfoc.us>2014-07-23 11:11:08 -0400
commit8a8b78b3f6a4ce930263099fe14b0fe86d11597f (patch)
tree005aa6cd0d9e73cd75a02a6aab12f785788e0cc6
parent52d18ddb211a7f4ee814ef23ff09656134810519 (diff)
shorter stack traces
-rw-r--r--public/assets/javascripts/rectangles/models/rect.js26
-rw-r--r--public/assets/javascripts/rectangles/models/vec2.js21
-rw-r--r--test/00-setup.js2
-rw-r--r--test/02-test-rect.js56
4 files changed, 80 insertions, 25 deletions
diff --git a/public/assets/javascripts/rectangles/models/rect.js b/public/assets/javascripts/rectangles/models/rect.js
index 8b6a666..f724ecc 100644
--- a/public/assets/javascripts/rectangles/models/rect.js
+++ b/public/assets/javascripts/rectangles/models/rect.js
@@ -148,20 +148,22 @@
var rn = new Rect(x[0], y[0])
rn.id = rz.id
rn.sides = ((x[1] | y[1]) & sides)
-// if (r.intersects(rn)) {
-// rn.sides = 0
-// }
- // if (r.x.b == rn.x.a) {
-// rn.sides &= ~LEFT
-// }
-// if (rn.x.b == r.x.a) {
-// rn.sides &= ~RIGHT
+
+ if (r.x.contains(rn.x.a)) {
+ rn.sides &= ~ LEFT
+ }
+ if (r.x.contains(rn.x.b)) {
+ rn.sides &= ~ RIGHT
+ }
+// if (r.y.contains(rn.y.a)) {
+// rn.sides &= ~ FRONT
// }
-// if (r.y.b == rn.y.a) {
-// rn.sides &= ~FRONT
+// if (r.y.contains(rn.y.a)) {
+// rn.sides &= ~ BACK
// }
-// if (rn.y.b == r.y.a) {
-// rn.sides &= ~BACK
+
+// if (r.intersects(rn)) {
+// rn.sides = 0
// }
rn.focused = rz.focused
splits.push(rn)
diff --git a/public/assets/javascripts/rectangles/models/vec2.js b/public/assets/javascripts/rectangles/models/vec2.js
index 4480473..447c7a3 100644
--- a/public/assets/javascripts/rectangles/models/vec2.js
+++ b/public/assets/javascripts/rectangles/models/vec2.js
@@ -110,7 +110,7 @@
// given two vectors, test how they overlap
// return the set of overlapping segments in the initial vector, labelled with sides
vec2.prototype.split = function(v, left, right){
- var intervals = []
+ var intervals = [], _len
if (this.eq(v)) {
intervals.push([ new vec2( this.a, this.b ), left | right ])
@@ -119,12 +119,12 @@
// a---A===b---B (rightways overlap)
else if (this.contains(v.a) && v.contains(this.b)) {
intervals.push([ new vec2( this.a, v.a ), left ])
- intervals.push([ new vec2( v.a, this.b ), 0 ])
+ intervals.push([ new vec2( v.a, this.b ), right ])
}
// A---a===B---b (leftways overlap)
else if (v.contains(this.a) && this.contains(v.b)) {
- intervals.push([ new vec2( this.a, v.b ), 0 ])
+ intervals.push([ new vec2( this.a, v.b ), left ])
intervals.push([ new vec2( v.b, this.b ), right ])
}
@@ -137,7 +137,20 @@
// A---a===b---B (contained in v)
else { // if (v.contains(this.a) && v.contains(v.b)) {
- intervals.push([ new vec2( this.a, this.b ), 0 ])
+ intervals.push([ new vec2( this.a, this.b ), left | right ])
+ }
+
+ // cull empty vectors
+ _len = intervals.length
+ if (_len > 1) {
+ if (intervals[0][0].magnitude() == 0) {
+ intervals[1][1] |= intervals[0][1]
+ intervals.shift()
+ }
+ else if (intervals[_len-1][0].magnitude() == 0) {
+ intervals[_len-2][1] |= intervals[_len-1][1]
+ intervals.pop()
+ }
}
return intervals
diff --git a/test/00-setup.js b/test/00-setup.js
new file mode 100644
index 0000000..8d06a13
--- /dev/null
+++ b/test/00-setup.js
@@ -0,0 +1,2 @@
+Error.stackTraceLimit = 1
+
diff --git a/test/02-test-rect.js b/test/02-test-rect.js
index 39693f5..0ae59f7 100644
--- a/test/02-test-rect.js
+++ b/test/02-test-rect.js
@@ -64,6 +64,13 @@ describe('rect', function(){
describe('#split(rect, east)', function(){
var s0 = rect.split(east)
var s1 = east.split(rect)
+
+ console.log("\n")
+ console.log(rect+"")
+ console.log(east+"")
+ console.log(s0.map(function(r){ return r.toString() }))
+ console.log(s1.map(function(r){ return r.toString() }))
+
it('splits on all 4 sides', function(){
assert.equal(ALL, sides(s0) | sides(s1))
})
@@ -92,13 +99,16 @@ describe('rect', function(){
describe('#split(rect, east_edge)', function(){
var s0 = rect.split(east_edge)
var s1 = east_edge.split(rect)
-
- console.log("\n")
- console.log(rect+"")
- console.log(east_edge+"")
- console.log(s0.map(function(r){ return r.toString() }))
- console.log(s1.map(function(r){ return r.toString() }))
-
+ it('has no degenerate vectors', function(){
+ s0.forEach(function(r){
+ assert.notEqual(0, r.x.magnitude())
+ assert.notEqual(0, r.y.magnitude())
+ })
+ s1.forEach(function(r){
+ assert.notEqual(0, r.x.magnitude())
+ assert.notEqual(0, r.y.magnitude())
+ })
+ })
it('splits on all 4 sides', function(){
assert.equal(ALL, sides(s0) | sides(s1))
})
@@ -110,7 +120,35 @@ describe('rect', function(){
})
})
+ return
+ describe('#split(rect, south)', function(){
+ var s0 = rect.split(south)
+ var s1 = south.split(rect)
+ it('splits on all 4 sides', function(){
+ assert.equal(ALL, sides(s0) | sides(s1))
+ })
+ it('rect is front/left/right', function(){
+ assert.equal(FRONT | LEFT | RIGHT, sides(s0))
+ })
+ it('south is back/left/right', function(){
+ assert.equal(BACK | LEFT | RIGHT, sides(s1))
+ })
+ })
+
+ describe('#split(rect, corner)', function(){
+ var s0 = rect.split(corner)
+ var s1 = corner.split(rect)
+
+ it('splits on all 4 sides', function(){
+ // assert.equal(ALL, sides(s0) | sides(s1))
+ })
+ it('rect is front/left/right', function(){
+ // assert.equal(FRONT | LEFT | RIGHT, sides(s0))
+ })
+ it('corner is back/left/right', function(){
+// assert.equal(BACK| LEFT | RIGHT, sides(s1))
+ })
+ })
+
})
-/*
-*/