2017-02-23 17:15:41 +00:00
|
|
|
var GetBounds = {
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
getBounds: function ()
|
2016-12-07 01:40:56 +00:00
|
|
|
{
|
2017-02-23 17:15:41 +00:00
|
|
|
var r = this.rotation;
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
var wct = this.width * Math.cos(r);
|
2017-02-24 01:45:15 +00:00
|
|
|
var hct = this.height * Math.cos(r);
|
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
var wst = this.width * Math.sin(r);
|
2017-02-24 01:45:15 +00:00
|
|
|
var hst = this.height * Math.sin(r);
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
var x = this.x;
|
|
|
|
var y = this.y;
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
var xMin = x;
|
|
|
|
var xMax = x;
|
|
|
|
var yMin = y;
|
|
|
|
var yMax = y;
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-24 01:45:15 +00:00
|
|
|
if (r > 0)
|
2017-02-23 17:15:41 +00:00
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
if (r < 1.5707963267948966)
|
2017-02-23 17:15:41 +00:00
|
|
|
{
|
|
|
|
// 0 < theta < 90
|
2017-02-24 01:45:15 +00:00
|
|
|
yMax = y + hct + wst;
|
|
|
|
xMin = x - hst;
|
|
|
|
xMax = x + wct;
|
2017-02-23 17:15:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 90 <= theta <= 180
|
2017-02-24 01:45:15 +00:00
|
|
|
yMin = y + hct;
|
|
|
|
yMax = y + wst;
|
|
|
|
xMin = x - hst + wct;
|
2017-02-23 17:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-24 01:45:15 +00:00
|
|
|
if (r > -1.5707963267948966)
|
2017-02-23 17:15:41 +00:00
|
|
|
{
|
|
|
|
// -90 < theta <= 0
|
2017-02-24 01:45:15 +00:00
|
|
|
yMin = y + wst;
|
|
|
|
yMax = y + hct;
|
|
|
|
xMax = x + wct - hst;
|
2017-02-23 17:15:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// -180 <= theta <= -90
|
2017-02-24 01:45:15 +00:00
|
|
|
yMin = y + wst + hct;
|
|
|
|
xMin = x + wct;
|
|
|
|
xMax = x - hst;
|
2017-02-23 17:15:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
return {
|
2017-02-24 01:45:15 +00:00
|
|
|
x: xMin,
|
|
|
|
y: yMin,
|
|
|
|
width: xMax - xMin,
|
|
|
|
height: yMax - yMin
|
2017-02-23 17:15:41 +00:00
|
|
|
};
|
|
|
|
}
|
2016-12-07 01:40:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetBounds;
|