2017-01-01 15:30:54 +00:00
|
|
|
var Rectangle = require('../rectangle/Rectangle');
|
2017-01-05 00:20:11 +00:00
|
|
|
var RectangleToRectangle = require('./RectangleToRectangle');
|
2017-01-01 15:30:54 +00:00
|
|
|
|
|
|
|
var GetRectangleIntersection = function (rectA, rectB, output)
|
|
|
|
{
|
|
|
|
if (output === undefined) { output = new Rectangle(); }
|
|
|
|
|
2017-01-05 00:20:11 +00:00
|
|
|
if (RectangleToRectangle(rectA, rectB))
|
2017-01-01 15:30:54 +00:00
|
|
|
{
|
|
|
|
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;
|