var GetBounds = { getBounds: function () { var r = this.rotation; var wct = this.width * Math.cos(r); var hct = this.height * Math.cos(r); var wst = this.width * Math.sin(r); var hst = this.height * Math.sin(r); var x = this.x; var y = this.y; var xMin = x; var xMax = x; var yMin = y; var yMax = y; if (r > 0) { if (r < 1.5707963267948966) { // 0 < theta < 90 yMax = y + hct + wst; xMin = x - hst; xMax = x + wct; } else { // 90 <= theta <= 180 yMin = y + hct; yMax = y + wst; xMin = x - hst + wct; } } else { if (r > -1.5707963267948966) { // -90 < theta <= 0 yMin = y + wst; yMax = y + hct; xMax = x + wct - hst; } else { // -180 <= theta <= -90 yMin = y + wst + hct; xMin = x + wct; xMax = x - hst; } } return { x: xMin, y: yMin, width: xMax - xMin, height: yMax - yMin }; } }; module.exports = GetBounds;