0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -05:00

added Bounds.translate and Bounds.shift

This commit is contained in:
liabru 2014-05-01 13:38:56 +01:00
parent 77168e5faf
commit 38c541363a

View file

@ -86,4 +86,33 @@ var Bounds = {};
&& boundsA.max.y >= boundsB.min.y && boundsA.min.y <= boundsB.max.y); && boundsA.max.y >= boundsB.min.y && boundsA.min.y <= boundsB.max.y);
}; };
/**
* Translates the bounds by the given vector
* @method translate
* @param {bounds} bounds
* @param {vector} vector
*/
Bounds.translate = function(bounds, vector) {
bounds.min.x += vector.x;
bounds.max.x += vector.x;
bounds.min.y += vector.y;
bounds.max.y += vector.y;
};
/**
* Shifts the bounds to the given position
* @method shift
* @param {bounds} bounds
* @param {vector} position
*/
Bounds.shift = function(bounds, position) {
var deltaX = bounds.max.x - bounds.min.x,
deltaY = bounds.max.y - bounds.min.y;
bounds.min.x = position.x;
bounds.max.x = position.x + deltaX;
bounds.min.y = position.y;
bounds.max.y = position.y + deltaY;
};
})(); })();