Permalink
Browse files

Switch to bitwise or for float to int conversion where possible.

  • Loading branch information...
1 parent 6d350f8 commit 7873bfac688a63e3a929a3fdba77940f35fb9770 John Weaver committed Apr 13, 2012
Showing with 6 additions and 4 deletions.
  1. +6 −4 lib/gamejs.js
View
@@ -209,14 +209,14 @@ objects.accessors(Rect.prototype, {
*/
'center': {
get: function() {
- return [this.left + Math.floor(this.width / 2),
- this.top + Math.floor(this.height / 2)
+ return [this.left + (this.width / 2) | 0,
+ this.top + (this.height / 2) | 0
];
},
set: function() {
var args = normalizeRectArguments.apply(this, arguments);
- this.left = args.left - Math.floor(this.width / 2);
- this.top = args.top - Math.floor(this.height / 2);
+ this.left = args.left - (this.width / 2) | 0;
+ this.top = args.top - (this.height / 2) | 0;
return;
}
},
@@ -424,6 +424,8 @@ Rect.prototype.inflate = function(x, y) {
* @param {Number} amount to change in the height
*/
Rect.prototype.inflateIp = function(x, y) {
+ // Use Math.floor here to deal with rounding of negative numbers the
+ // way this relies on.
this.left -= Math.floor(x / 2);
this.top -= Math.floor(y / 2);
this.width += x;

0 comments on commit 7873bfa

Please sign in to comment.