mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
added Bounds.translate and Bounds.shift
This commit is contained in:
parent
77168e5faf
commit
38c541363a
1 changed files with 29 additions and 0 deletions
|
@ -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;
|
||||||
|
};
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in a new issue