Created
February 10, 2011 06:04
-
-
Save jminor/820023 to your computer and use it in GitHub Desktop.
impactjs test for Entity.touches off-by-one issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// try with and without this next block | |
if (0) { | |
ig.Entity.prototype.touches = function( other ) { | |
return !( | |
this.pos.x >= other.pos.x + other.size.x || | |
this.pos.x + this.size.x <= other.pos.x || | |
this.pos.y >= other.pos.y + other.size.y || | |
this.pos.y + this.size.y <= other.pos.y | |
); | |
}; | |
} | |
var e1 = new ig.Entity(); | |
e1.pos.x = 0; | |
e1.pos.y = 0; | |
e1.size.x = 1; | |
e1.size.y = 1; | |
var e2 = new ig.Entity(); | |
e2.pos.x = 0; | |
e2.pos.y = 0; | |
e2.size.x = 1; | |
e2.size.y = 1; | |
console.log("testing x"); | |
for (var x=-5; x<5; x++) { | |
e2.pos.x = x; | |
console.log(x, e1.touches(e2)); | |
} | |
console.log("testing y"); | |
e2.pos.x = 0; | |
for (var y=-5; y<5; y++) { | |
e2.pos.y = y; | |
console.log(y, e1.touches(e2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment