Skip to content

Instantly share code, notes, and snippets.

@jminor
Created February 10, 2011 06:04
Show Gist options
  • Save jminor/820023 to your computer and use it in GitHub Desktop.
Save jminor/820023 to your computer and use it in GitHub Desktop.
impactjs test for Entity.touches off-by-one issue
// 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