Skip to content

Commit

Permalink
Ticket #101 - Make infinite planes a special case in rectangle geometry
Browse files Browse the repository at this point in the history
- Infinite planes should be treated as immutable.
  • Loading branch information
Jason Oster committed Sep 12, 2012
1 parent 38f96cf commit 28e5c30
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions src/math/geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,16 @@
}

});


// a special getter property for infinite planes
var infinitePlane = {
get : function() {
return Infinity;
},
configurable : true
};

/************************************************************************************/
/* */
/* a rectangle Class Object */
Expand Down Expand Up @@ -293,10 +303,16 @@
*/
Object.defineProperty(this, "right", {
get : function() {
return (this.pos.x + this.width) || Infinity;
return this.pos.x + this.width;
},
configurable : true
});
// special-case for infinite plane
// -Infinity + Infinity === NaN
// NaN != NaN
if (this.right != this.right) {
Object.defineProperty(this, "right", infinitePlane);
}
/**
* top coordinate of the Rectange<br>
* takes in account the adjusted size of the rectangle (if set)
Expand All @@ -319,10 +335,16 @@
*/
Object.defineProperty(this, "bottom", {
get : function() {
return (this.pos.y + this.height) || Infinity;
return this.pos.y + this.height;
},
configurable : true
});
// special-case for infinite plane
// -Infinity + Infinity === NaN
// NaN != NaN
if (this.bottom != this.bottom) {
Object.defineProperty(this, "bottom", infinitePlane);
}

},

Expand Down Expand Up @@ -401,11 +423,17 @@
if (this.right !== this.pos.x + this.colPos.x + this.width) {
Object.defineProperty(this, "right", {
get : function() {
return (this.pos.x + this.colPos.x + this.width) || Infinity;
return this.pos.x + this.colPos.x + this.width;
},
configurable : true
});
}
// special-case for infinite plane
// -Infinity + Infinity === NaN
// NaN != NaN
if (this.right != this.right) {
Object.defineProperty(this, "right", infinitePlane);
}
}
if (y != -1) {
this.colPos.y = y;
Expand All @@ -425,11 +453,17 @@
if (this.bottom !== this.pos.y + this.colPos.y + this.height) {
Object.defineProperty(this, "bottom", {
get : function() {
return (this.pos.y + this.colPos.y + this.height) || Infinity;
return this.pos.y + this.colPos.y + this.height;
},
configurable : true
});
}
// special-case for infinite plane
// -Infinity + Infinity === NaN
// NaN != NaN
if (this.bottom != this.bottom) {
Object.defineProperty(this, "bottom", infinitePlane);
}
}
},

Expand Down

0 comments on commit 28e5c30

Please sign in to comment.