mirror of
https://github.com/photonstorm/phaser
synced 2024-12-18 17:16:03 +00:00
20 lines
600 B
JavaScript
20 lines
600 B
JavaScript
|
var Rectangle = require('../rectangle/Rectangle');
|
||
|
var RectangleVsRectangle = require('./RectangleVsRectangle');
|
||
|
|
||
|
var GetRectangleIntersection = function (rectA, rectB, output)
|
||
|
{
|
||
|
if (output === undefined) { output = new Rectangle(); }
|
||
|
|
||
|
if (RectangleVsRectangle(rectA, rectB))
|
||
|
{
|
||
|
output.x = Math.max(rectA.x, rectB.x);
|
||
|
output.y = Math.max(rectA.y, rectB.y);
|
||
|
output.width = Math.min(rectA.right, rectB.right) - output.x;
|
||
|
output.height = Math.min(rectA.bottom, rectB.bottom) - output.y;
|
||
|
}
|
||
|
|
||
|
return output;
|
||
|
};
|
||
|
|
||
|
module.exports = GetRectangleIntersection;
|