Skip to content

Commit cbeee62

Browse files
committed
Optimized getBounds, also allow container object to be passed to it.
1 parent b6bef1d commit cbeee62

2 files changed

Lines changed: 31 additions & 29 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: 'a913e160-fa32-11e6-a501-2b18fd50adf3'
2+
build: '675700d0-fa33-11e6-b99d-a10bc0cf71c4'
33
};
44
module.exports = CHECKSUM;

v3/src/components/GetBounds.js

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
var GetBounds = {
22

3-
getBounds: function ()
3+
getBounds: function (output)
44
{
5-
var r = this.rotation;
6-
7-
var wct = this.width * Math.cos(r);
8-
var hct = this.height * Math.cos(r);
9-
10-
var wst = this.width * Math.sin(r);
11-
var hst = this.height * Math.sin(r);
5+
if (output === undefined) { output = { x: 0, y: 0, width: 0, height: 0 }; }
126

137
var x = this.x;
148
var y = this.y;
159

10+
var w = this.width;
11+
var h = this.height;
12+
13+
var r = this.rotation;
14+
15+
var wct = w * Math.cos(r);
16+
var hct = h * Math.cos(r);
17+
18+
var wst = w * Math.sin(r);
19+
var hst = h * Math.sin(r);
20+
1621
var xMin = x;
1722
var xMax = x;
1823
var yMin = y;
@@ -35,30 +40,27 @@ var GetBounds = {
3540
xMin = x - hst + wct;
3641
}
3742
}
43+
else if (r > -1.5707963267948966)
44+
{
45+
// -90 < theta <= 0
46+
yMin = y + wst;
47+
yMax = y + hct;
48+
xMax = x + wct - hst;
49+
}
3850
else
3951
{
40-
if (r > -1.5707963267948966)
41-
{
42-
// -90 < theta <= 0
43-
yMin = y + wst;
44-
yMax = y + hct;
45-
xMax = x + wct - hst;
46-
}
47-
else
48-
{
49-
// -180 <= theta <= -90
50-
yMin = y + wst + hct;
51-
xMin = x + wct;
52-
xMax = x - hst;
53-
}
52+
// -180 <= theta <= -90
53+
yMin = y + wst + hct;
54+
xMin = x + wct;
55+
xMax = x - hst;
5456
}
5557

56-
return {
57-
x: xMin,
58-
y: yMin,
59-
width: xMax - xMin,
60-
height: yMax - yMin
61-
};
58+
output.x = xMin;
59+
output.y = yMin;
60+
output.width = xMax - xMin;
61+
output.height = yMax - yMin;
62+
63+
return output;
6264
}
6365
};
6466

0 commit comments

Comments
 (0)