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 a = this.angle;
|
|
|
|
var r = this.rotation;
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
var hct = this.height * Math.cos(r);
|
|
|
|
var wct = this.width * Math.cos(r);
|
|
|
|
var hst = this.height * Math.sin(r);
|
|
|
|
var wst = this.width * 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-23 17:15:41 +00:00
|
|
|
var x_min;
|
|
|
|
var x_max;
|
|
|
|
var y_min;
|
|
|
|
var y_max;
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
if (a > 0)
|
|
|
|
{
|
|
|
|
if (a < 90)
|
|
|
|
{
|
|
|
|
// 0 < theta < 90
|
|
|
|
y_min = y;
|
|
|
|
y_max = y + hct + wst;
|
|
|
|
x_min = x - hst;
|
|
|
|
x_max = x + wct;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// 90 <= theta <= 180
|
|
|
|
y_min = y + hct;
|
|
|
|
y_max = y + wst;
|
|
|
|
x_min = x - hst + wct;
|
|
|
|
x_max = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (a > -90)
|
|
|
|
{
|
|
|
|
// -90 < theta <= 0
|
|
|
|
y_min = y + wst;
|
|
|
|
y_max = y + hct;
|
|
|
|
x_min = x;
|
|
|
|
x_max = x + wct - hst;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// -180 <= theta <= -90
|
|
|
|
y_min = y + wst + hct;
|
|
|
|
y_max = y;
|
|
|
|
x_min = x + wct;
|
|
|
|
x_max = x - hst;
|
|
|
|
}
|
|
|
|
}
|
2016-12-07 01:40:56 +00:00
|
|
|
|
2017-02-23 17:15:41 +00:00
|
|
|
return {
|
|
|
|
x: x_min,
|
|
|
|
y: y_min,
|
|
|
|
width: x_max - x_min,
|
|
|
|
height: y_max - y_min
|
|
|
|
};
|
|
|
|
}
|
2016-12-07 01:40:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = GetBounds;
|