From cbeee62549484625ece0f7ec60d74bf0fc128093 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 24 Feb 2017 01:58:27 +0000 Subject: [PATCH] Optimized getBounds, also allow container object to be passed to it. --- v3/src/checksum.js | 2 +- v3/src/components/GetBounds.js | 58 ++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/v3/src/checksum.js b/v3/src/checksum.js index c529806a0..ff30f48e1 100644 --- a/v3/src/checksum.js +++ b/v3/src/checksum.js @@ -1,4 +1,4 @@ var CHECKSUM = { -build: 'a913e160-fa32-11e6-a501-2b18fd50adf3' +build: '675700d0-fa33-11e6-b99d-a10bc0cf71c4' }; module.exports = CHECKSUM; \ No newline at end of file diff --git a/v3/src/components/GetBounds.js b/v3/src/components/GetBounds.js index 9f21d2c07..4c71ea491 100644 --- a/v3/src/components/GetBounds.js +++ b/v3/src/components/GetBounds.js @@ -1,18 +1,23 @@ var GetBounds = { - getBounds: function () + getBounds: function (output) { - 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); + if (output === undefined) { output = { x: 0, y: 0, width: 0, height: 0 }; } var x = this.x; var y = this.y; + var w = this.width; + var h = this.height; + + var r = this.rotation; + + var wct = w * Math.cos(r); + var hct = h * Math.cos(r); + + var wst = w * Math.sin(r); + var hst = h * Math.sin(r); + var xMin = x; var xMax = x; var yMin = y; @@ -35,30 +40,27 @@ var GetBounds = { xMin = x - hst + wct; } } + else if (r > -1.5707963267948966) + { + // -90 < theta <= 0 + yMin = y + wst; + yMax = y + hct; + xMax = x + wct - hst; + } 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; - } + // -180 <= theta <= -90 + yMin = y + wst + hct; + xMin = x + wct; + xMax = x - hst; } - return { - x: xMin, - y: yMin, - width: xMax - xMin, - height: yMax - yMin - }; + output.x = xMin; + output.y = yMin; + output.width = xMax - xMin; + output.height = yMax - yMin; + + return output; } };