diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 02eebb9..e98523c 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -332,62 +332,67 @@ */ Container.prototype.getBounds = function () { - if (this.children.length === 0) + if(!this._currentBounds) { - return math.Rectangle.EMPTY; - } - // TODO the bounds have already been calculated this render session so return what we have - - var minX = Infinity; - var minY = Infinity; - - var maxX = -Infinity; - var maxY = -Infinity; - - var childBounds; - var childMaxX; - var childMaxY; - - var childVisible = false; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - var child = this.children[i]; - - if (!child.visible) + if (this.children.length === 0) { - continue; + return math.Rectangle.EMPTY; } - childVisible = true; + // TODO the bounds have already been calculated this render session so return what we have - childBounds = this.children[i].getBounds(); + var minX = Infinity; + var minY = Infinity; - minX = minX < childBounds.x ? minX : childBounds.x; - minY = minY < childBounds.y ? minY : childBounds.y; + var maxX = -Infinity; + var maxY = -Infinity; - childMaxX = childBounds.width + childBounds.x; - childMaxY = childBounds.height + childBounds.y; + var childBounds; + var childMaxX; + var childMaxY; - maxX = maxX > childMaxX ? maxX : childMaxX; - maxY = maxY > childMaxY ? maxY : childMaxY; + var childVisible = false; + + for (var i = 0, j = this.children.length; i < j; ++i) + { + var child = this.children[i]; + + if (!child.visible) + { + continue; + } + + childVisible = true; + + childBounds = this.children[i].getBounds(); + + minX = minX < childBounds.x ? minX : childBounds.x; + minY = minY < childBounds.y ? minY : childBounds.y; + + childMaxX = childBounds.width + childBounds.x; + childMaxY = childBounds.height + childBounds.y; + + maxX = maxX > childMaxX ? maxX : childMaxX; + maxY = maxY > childMaxY ? maxY : childMaxY; + } + + if (!childVisible) + { + return math.Rectangle.EMPTY; + } + + var bounds = this._bounds; + + bounds.x = minX; + bounds.y = minY; + bounds.width = maxX - minX; + bounds.height = maxY - minY; + + this._currentBounds = bounds; } - if (!childVisible) - { - return math.Rectangle.EMPTY; - } - - this._bounds.x = minX; - this._bounds.y = minY; - this._bounds.width = maxX - minX; - this._bounds.height = maxY - minY; - - // TODO: store a reference so that if this function gets called again in the render cycle we do not have to recalculate - //this._currentBounds = bounds; - - return this._bounds; + return this._currentBounds; }; /** @@ -421,7 +426,7 @@ { // if the object is not visible or the alpha is 0 then no need to render this element - if (this.isMask || !this.visible || this.worldAlpha <= 0 || !this.renderable) + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) { return; } diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 02eebb9..e98523c 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -332,62 +332,67 @@ */ Container.prototype.getBounds = function () { - if (this.children.length === 0) + if(!this._currentBounds) { - return math.Rectangle.EMPTY; - } - // TODO the bounds have already been calculated this render session so return what we have - - var minX = Infinity; - var minY = Infinity; - - var maxX = -Infinity; - var maxY = -Infinity; - - var childBounds; - var childMaxX; - var childMaxY; - - var childVisible = false; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - var child = this.children[i]; - - if (!child.visible) + if (this.children.length === 0) { - continue; + return math.Rectangle.EMPTY; } - childVisible = true; + // TODO the bounds have already been calculated this render session so return what we have - childBounds = this.children[i].getBounds(); + var minX = Infinity; + var minY = Infinity; - minX = minX < childBounds.x ? minX : childBounds.x; - minY = minY < childBounds.y ? minY : childBounds.y; + var maxX = -Infinity; + var maxY = -Infinity; - childMaxX = childBounds.width + childBounds.x; - childMaxY = childBounds.height + childBounds.y; + var childBounds; + var childMaxX; + var childMaxY; - maxX = maxX > childMaxX ? maxX : childMaxX; - maxY = maxY > childMaxY ? maxY : childMaxY; + var childVisible = false; + + for (var i = 0, j = this.children.length; i < j; ++i) + { + var child = this.children[i]; + + if (!child.visible) + { + continue; + } + + childVisible = true; + + childBounds = this.children[i].getBounds(); + + minX = minX < childBounds.x ? minX : childBounds.x; + minY = minY < childBounds.y ? minY : childBounds.y; + + childMaxX = childBounds.width + childBounds.x; + childMaxY = childBounds.height + childBounds.y; + + maxX = maxX > childMaxX ? maxX : childMaxX; + maxY = maxY > childMaxY ? maxY : childMaxY; + } + + if (!childVisible) + { + return math.Rectangle.EMPTY; + } + + var bounds = this._bounds; + + bounds.x = minX; + bounds.y = minY; + bounds.width = maxX - minX; + bounds.height = maxY - minY; + + this._currentBounds = bounds; } - if (!childVisible) - { - return math.Rectangle.EMPTY; - } - - this._bounds.x = minX; - this._bounds.y = minY; - this._bounds.width = maxX - minX; - this._bounds.height = maxY - minY; - - // TODO: store a reference so that if this function gets called again in the render cycle we do not have to recalculate - //this._currentBounds = bounds; - - return this._bounds; + return this._currentBounds; }; /** @@ -421,7 +426,7 @@ { // if the object is not visible or the alpha is 0 then no need to render this element - if (this.isMask || !this.visible || this.worldAlpha <= 0 || !this.renderable) + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) { return; } diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d3087d8..243a75b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -136,7 +136,7 @@ this._mask = null; //TODO rename to _isMask - this.isMask = false; + // this.isMask = false; /** * Cached internal flag. @@ -230,14 +230,14 @@ { if (this._mask) { - this._mask.isMask = false; + this._mask.renderable = true; } this._mask = value; if (this._mask) { - this._mask.isMask = true; + this._mask.renderable = false; } } }, @@ -333,6 +333,9 @@ // multiply the alphas.. this.worldAlpha = this.alpha * this.parent.worldAlpha; + + // reset the bounds each time this is called! + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 02eebb9..e98523c 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -332,62 +332,67 @@ */ Container.prototype.getBounds = function () { - if (this.children.length === 0) + if(!this._currentBounds) { - return math.Rectangle.EMPTY; - } - // TODO the bounds have already been calculated this render session so return what we have - - var minX = Infinity; - var minY = Infinity; - - var maxX = -Infinity; - var maxY = -Infinity; - - var childBounds; - var childMaxX; - var childMaxY; - - var childVisible = false; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - var child = this.children[i]; - - if (!child.visible) + if (this.children.length === 0) { - continue; + return math.Rectangle.EMPTY; } - childVisible = true; + // TODO the bounds have already been calculated this render session so return what we have - childBounds = this.children[i].getBounds(); + var minX = Infinity; + var minY = Infinity; - minX = minX < childBounds.x ? minX : childBounds.x; - minY = minY < childBounds.y ? minY : childBounds.y; + var maxX = -Infinity; + var maxY = -Infinity; - childMaxX = childBounds.width + childBounds.x; - childMaxY = childBounds.height + childBounds.y; + var childBounds; + var childMaxX; + var childMaxY; - maxX = maxX > childMaxX ? maxX : childMaxX; - maxY = maxY > childMaxY ? maxY : childMaxY; + var childVisible = false; + + for (var i = 0, j = this.children.length; i < j; ++i) + { + var child = this.children[i]; + + if (!child.visible) + { + continue; + } + + childVisible = true; + + childBounds = this.children[i].getBounds(); + + minX = minX < childBounds.x ? minX : childBounds.x; + minY = minY < childBounds.y ? minY : childBounds.y; + + childMaxX = childBounds.width + childBounds.x; + childMaxY = childBounds.height + childBounds.y; + + maxX = maxX > childMaxX ? maxX : childMaxX; + maxY = maxY > childMaxY ? maxY : childMaxY; + } + + if (!childVisible) + { + return math.Rectangle.EMPTY; + } + + var bounds = this._bounds; + + bounds.x = minX; + bounds.y = minY; + bounds.width = maxX - minX; + bounds.height = maxY - minY; + + this._currentBounds = bounds; } - if (!childVisible) - { - return math.Rectangle.EMPTY; - } - - this._bounds.x = minX; - this._bounds.y = minY; - this._bounds.width = maxX - minX; - this._bounds.height = maxY - minY; - - // TODO: store a reference so that if this function gets called again in the render cycle we do not have to recalculate - //this._currentBounds = bounds; - - return this._bounds; + return this._currentBounds; }; /** @@ -421,7 +426,7 @@ { // if the object is not visible or the alpha is 0 then no need to render this element - if (this.isMask || !this.visible || this.worldAlpha <= 0 || !this.renderable) + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) { return; } diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d3087d8..243a75b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -136,7 +136,7 @@ this._mask = null; //TODO rename to _isMask - this.isMask = false; + // this.isMask = false; /** * Cached internal flag. @@ -230,14 +230,14 @@ { if (this._mask) { - this._mask.isMask = false; + this._mask.renderable = true; } this._mask = value; if (this._mask) { - this._mask.isMask = true; + this._mask.renderable = false; } } }, @@ -333,6 +333,9 @@ // multiply the alphas.. this.worldAlpha = this.alpha * this.parent.worldAlpha; + + // reset the bounds each time this is called! + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index d590729..80bb6a0 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -812,79 +812,85 @@ */ Graphics.prototype.getBounds = function (matrix) { - // return an empty object if the item is a mask! - if (this.isMask) + if(!this._currentBounds) { - return math.Rectangle.EMPTY; + + // return an empty object if the item is a mask! + if (this.renderable) + { + return math.Rectangle.EMPTY; + } + + if (this.dirty) + { + this.updateLocalBounds(); + + this.glDirty = true; + this.cachedSpriteDirty = true; + this.dirty = false; + } + + var bounds = this._localBounds; + + var w0 = bounds.x; + var w1 = bounds.width + bounds.x; + + var h0 = bounds.y; + var h1 = bounds.height + bounds.y; + + var worldTransform = matrix || this.worldTransform; + + var a = worldTransform.a; + var b = worldTransform.b; + var c = worldTransform.c; + var d = worldTransform.d; + var tx = worldTransform.tx; + var ty = worldTransform.ty; + + var x1 = a * w1 + c * h1 + tx; + var y1 = d * h1 + b * w1 + ty; + + var x2 = a * w0 + c * h1 + tx; + var y2 = d * h1 + b * w0 + ty; + + var x3 = a * w0 + c * h0 + tx; + var y3 = d * h0 + b * w0 + ty; + + var x4 = a * w1 + c * h0 + tx; + var y4 = d * h0 + b * w1 + ty; + + var maxX = x1; + var maxY = y1; + + var minX = x1; + var minY = y1; + + minX = x2 < minX ? x2 : minX; + minX = x3 < minX ? x3 : minX; + minX = x4 < minX ? x4 : minX; + + minY = y2 < minY ? y2 : minY; + minY = y3 < minY ? y3 : minY; + minY = y4 < minY ? y4 : minY; + + maxX = x2 > maxX ? x2 : maxX; + maxX = x3 > maxX ? x3 : maxX; + maxX = x4 > maxX ? x4 : maxX; + + maxY = y2 > maxY ? y2 : maxY; + maxY = y3 > maxY ? y3 : maxY; + maxY = y4 > maxY ? y4 : maxY; + + this._bounds.x = minX; + this._bounds.width = maxX - minX; + + this._bounds.y = minY; + this._bounds.height = maxY - minY; + + this._currentBounds = this._bounds; } - if (this.dirty) - { - this.updateLocalBounds(); - - this.glDirty = true; - this.cachedSpriteDirty = true; - this.dirty = false; - } - - var bounds = this._localBounds; - - var w0 = bounds.x; - var w1 = bounds.width + bounds.x; - - var h0 = bounds.y; - var h1 = bounds.height + bounds.y; - - var worldTransform = matrix || this.worldTransform; - - var a = worldTransform.a; - var b = worldTransform.b; - var c = worldTransform.c; - var d = worldTransform.d; - var tx = worldTransform.tx; - var ty = worldTransform.ty; - - var x1 = a * w1 + c * h1 + tx; - var y1 = d * h1 + b * w1 + ty; - - var x2 = a * w0 + c * h1 + tx; - var y2 = d * h1 + b * w0 + ty; - - var x3 = a * w0 + c * h0 + tx; - var y3 = d * h0 + b * w0 + ty; - - var x4 = a * w1 + c * h0 + tx; - var y4 = d * h0 + b * w1 + ty; - - var maxX = x1; - var maxY = y1; - - var minX = x1; - var minY = y1; - - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; - - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; - - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; - - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; - - this._bounds.x = minX; - this._bounds.width = maxX - minX; - - this._bounds.y = minY; - this._bounds.height = maxY - minY; - - return this._bounds; + return this._currentBounds; }; /** diff --git a/src/core/display/Container.js b/src/core/display/Container.js index 02eebb9..e98523c 100644 --- a/src/core/display/Container.js +++ b/src/core/display/Container.js @@ -332,62 +332,67 @@ */ Container.prototype.getBounds = function () { - if (this.children.length === 0) + if(!this._currentBounds) { - return math.Rectangle.EMPTY; - } - // TODO the bounds have already been calculated this render session so return what we have - - var minX = Infinity; - var minY = Infinity; - - var maxX = -Infinity; - var maxY = -Infinity; - - var childBounds; - var childMaxX; - var childMaxY; - - var childVisible = false; - - for (var i = 0, j = this.children.length; i < j; ++i) - { - var child = this.children[i]; - - if (!child.visible) + if (this.children.length === 0) { - continue; + return math.Rectangle.EMPTY; } - childVisible = true; + // TODO the bounds have already been calculated this render session so return what we have - childBounds = this.children[i].getBounds(); + var minX = Infinity; + var minY = Infinity; - minX = minX < childBounds.x ? minX : childBounds.x; - minY = minY < childBounds.y ? minY : childBounds.y; + var maxX = -Infinity; + var maxY = -Infinity; - childMaxX = childBounds.width + childBounds.x; - childMaxY = childBounds.height + childBounds.y; + var childBounds; + var childMaxX; + var childMaxY; - maxX = maxX > childMaxX ? maxX : childMaxX; - maxY = maxY > childMaxY ? maxY : childMaxY; + var childVisible = false; + + for (var i = 0, j = this.children.length; i < j; ++i) + { + var child = this.children[i]; + + if (!child.visible) + { + continue; + } + + childVisible = true; + + childBounds = this.children[i].getBounds(); + + minX = minX < childBounds.x ? minX : childBounds.x; + minY = minY < childBounds.y ? minY : childBounds.y; + + childMaxX = childBounds.width + childBounds.x; + childMaxY = childBounds.height + childBounds.y; + + maxX = maxX > childMaxX ? maxX : childMaxX; + maxY = maxY > childMaxY ? maxY : childMaxY; + } + + if (!childVisible) + { + return math.Rectangle.EMPTY; + } + + var bounds = this._bounds; + + bounds.x = minX; + bounds.y = minY; + bounds.width = maxX - minX; + bounds.height = maxY - minY; + + this._currentBounds = bounds; } - if (!childVisible) - { - return math.Rectangle.EMPTY; - } - - this._bounds.x = minX; - this._bounds.y = minY; - this._bounds.width = maxX - minX; - this._bounds.height = maxY - minY; - - // TODO: store a reference so that if this function gets called again in the render cycle we do not have to recalculate - //this._currentBounds = bounds; - - return this._bounds; + return this._currentBounds; }; /** @@ -421,7 +426,7 @@ { // if the object is not visible or the alpha is 0 then no need to render this element - if (this.isMask || !this.visible || this.worldAlpha <= 0 || !this.renderable) + if (!this.visible || this.worldAlpha <= 0 || !this.renderable) { return; } diff --git a/src/core/display/DisplayObject.js b/src/core/display/DisplayObject.js index d3087d8..243a75b 100644 --- a/src/core/display/DisplayObject.js +++ b/src/core/display/DisplayObject.js @@ -136,7 +136,7 @@ this._mask = null; //TODO rename to _isMask - this.isMask = false; + // this.isMask = false; /** * Cached internal flag. @@ -230,14 +230,14 @@ { if (this._mask) { - this._mask.isMask = false; + this._mask.renderable = true; } this._mask = value; if (this._mask) { - this._mask.isMask = true; + this._mask.renderable = false; } } }, @@ -333,6 +333,9 @@ // multiply the alphas.. this.worldAlpha = this.alpha * this.parent.worldAlpha; + + // reset the bounds each time this is called! + this._currentBounds = null; }; // performance increase to avoid using call.. (10x faster) diff --git a/src/core/graphics/Graphics.js b/src/core/graphics/Graphics.js index d590729..80bb6a0 100644 --- a/src/core/graphics/Graphics.js +++ b/src/core/graphics/Graphics.js @@ -812,79 +812,85 @@ */ Graphics.prototype.getBounds = function (matrix) { - // return an empty object if the item is a mask! - if (this.isMask) + if(!this._currentBounds) { - return math.Rectangle.EMPTY; + + // return an empty object if the item is a mask! + if (this.renderable) + { + return math.Rectangle.EMPTY; + } + + if (this.dirty) + { + this.updateLocalBounds(); + + this.glDirty = true; + this.cachedSpriteDirty = true; + this.dirty = false; + } + + var bounds = this._localBounds; + + var w0 = bounds.x; + var w1 = bounds.width + bounds.x; + + var h0 = bounds.y; + var h1 = bounds.height + bounds.y; + + var worldTransform = matrix || this.worldTransform; + + var a = worldTransform.a; + var b = worldTransform.b; + var c = worldTransform.c; + var d = worldTransform.d; + var tx = worldTransform.tx; + var ty = worldTransform.ty; + + var x1 = a * w1 + c * h1 + tx; + var y1 = d * h1 + b * w1 + ty; + + var x2 = a * w0 + c * h1 + tx; + var y2 = d * h1 + b * w0 + ty; + + var x3 = a * w0 + c * h0 + tx; + var y3 = d * h0 + b * w0 + ty; + + var x4 = a * w1 + c * h0 + tx; + var y4 = d * h0 + b * w1 + ty; + + var maxX = x1; + var maxY = y1; + + var minX = x1; + var minY = y1; + + minX = x2 < minX ? x2 : minX; + minX = x3 < minX ? x3 : minX; + minX = x4 < minX ? x4 : minX; + + minY = y2 < minY ? y2 : minY; + minY = y3 < minY ? y3 : minY; + minY = y4 < minY ? y4 : minY; + + maxX = x2 > maxX ? x2 : maxX; + maxX = x3 > maxX ? x3 : maxX; + maxX = x4 > maxX ? x4 : maxX; + + maxY = y2 > maxY ? y2 : maxY; + maxY = y3 > maxY ? y3 : maxY; + maxY = y4 > maxY ? y4 : maxY; + + this._bounds.x = minX; + this._bounds.width = maxX - minX; + + this._bounds.y = minY; + this._bounds.height = maxY - minY; + + this._currentBounds = this._bounds; } - if (this.dirty) - { - this.updateLocalBounds(); - - this.glDirty = true; - this.cachedSpriteDirty = true; - this.dirty = false; - } - - var bounds = this._localBounds; - - var w0 = bounds.x; - var w1 = bounds.width + bounds.x; - - var h0 = bounds.y; - var h1 = bounds.height + bounds.y; - - var worldTransform = matrix || this.worldTransform; - - var a = worldTransform.a; - var b = worldTransform.b; - var c = worldTransform.c; - var d = worldTransform.d; - var tx = worldTransform.tx; - var ty = worldTransform.ty; - - var x1 = a * w1 + c * h1 + tx; - var y1 = d * h1 + b * w1 + ty; - - var x2 = a * w0 + c * h1 + tx; - var y2 = d * h1 + b * w0 + ty; - - var x3 = a * w0 + c * h0 + tx; - var y3 = d * h0 + b * w0 + ty; - - var x4 = a * w1 + c * h0 + tx; - var y4 = d * h0 + b * w1 + ty; - - var maxX = x1; - var maxY = y1; - - var minX = x1; - var minY = y1; - - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; - - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; - - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; - - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; - - this._bounds.x = minX; - this._bounds.width = maxX - minX; - - this._bounds.y = minY; - this._bounds.height = maxY - minY; - - return this._bounds; + return this._currentBounds; }; /** diff --git a/src/core/sprites/Sprite.js b/src/core/sprites/Sprite.js index de88ea8..ed69607 100644 --- a/src/core/sprites/Sprite.js +++ b/src/core/sprites/Sprite.js @@ -116,11 +116,11 @@ width: { get: function () { - return this.scale.x * this.texture.frame.width; + return this.scale.x * this.texture._frame.width; }, set: function (value) { - this.scale.x = value / this.texture.frame.width; + this.scale.x = value / this.texture._frame.width; this._width = value; } }, @@ -134,11 +134,11 @@ height: { get: function () { - return this.scale.y * this.texture.frame.height; + return this.scale.y * this.texture._frame.height; }, set: function (value) { - this.scale.y = value / this.texture.frame.height; + this.scale.y = value / this.texture._frame.height; this._height = value; } }, @@ -213,96 +213,100 @@ */ Sprite.prototype.getBounds = function (matrix) { - var width = this._texture._frame.width; - var height = this._texture._frame.height; - - var w0 = width * (1-this.anchor.x); - var w1 = width * -this.anchor.x; - - var h0 = height * (1-this.anchor.y); - var h1 = height * -this.anchor.y; - - var worldTransform = matrix || this.worldTransform ; - - var a = worldTransform.a; - var b = worldTransform.b; - var c = worldTransform.c; - var d = worldTransform.d; - var tx = worldTransform.tx; - var ty = worldTransform.ty; - - var minX, - maxX, - minY, - maxY; - - if (b === 0 && c === 0) + if(!this._currentBounds) { - // scale may be negative! - if (a < 0) + + var width = this._texture._frame.width; + var height = this._texture._frame.height; + + var w0 = width * (1-this.anchor.x); + var w1 = width * -this.anchor.x; + + var h0 = height * (1-this.anchor.y); + var h1 = height * -this.anchor.y; + + var worldTransform = matrix || this.worldTransform ; + + var a = worldTransform.a; + var b = worldTransform.b; + var c = worldTransform.c; + var d = worldTransform.d; + var tx = worldTransform.tx; + var ty = worldTransform.ty; + + var minX, + maxX, + minY, + maxY; + + if (b === 0 && c === 0) { - a *= -1; + // scale may be negative! + if (a < 0) + { + a *= -1; + } + + if (d < 0) + { + d *= -1; + } + + // this means there is no rotation going on right? RIGHT? + // if thats the case then we can avoid checking the bound values! yay + minX = a * w1 + tx; + maxX = a * w0 + tx; + minY = d * h1 + ty; + maxY = d * h0 + ty; + } + else + { + var x1 = a * w1 + c * h1 + tx; + var y1 = d * h1 + b * w1 + ty; + + var x2 = a * w0 + c * h1 + tx; + var y2 = d * h1 + b * w0 + ty; + + var x3 = a * w0 + c * h0 + tx; + var y3 = d * h0 + b * w0 + ty; + + var x4 = a * w1 + c * h0 + tx; + var y4 = d * h0 + b * w1 + ty; + + minX = x1; + minX = x2 < minX ? x2 : minX; + minX = x3 < minX ? x3 : minX; + minX = x4 < minX ? x4 : minX; + + minY = y1; + minY = y2 < minY ? y2 : minY; + minY = y3 < minY ? y3 : minY; + minY = y4 < minY ? y4 : minY; + + maxX = x1; + maxX = x2 > maxX ? x2 : maxX; + maxX = x3 > maxX ? x3 : maxX; + maxX = x4 > maxX ? x4 : maxX; + + maxY = y1; + maxY = y2 > maxY ? y2 : maxY; + maxY = y3 > maxY ? y3 : maxY; + maxY = y4 > maxY ? y4 : maxY; } - if (d < 0) - { - d *= -1; - } + var bounds = this._bounds; - // this means there is no rotation going on right? RIGHT? - // if thats the case then we can avoid checking the bound values! yay - minX = a * w1 + tx; - maxX = a * w0 + tx; - minY = d * h1 + ty; - maxY = d * h0 + ty; - } - else - { - var x1 = a * w1 + c * h1 + tx; - var y1 = d * h1 + b * w1 + ty; + bounds.x = minX; + bounds.width = maxX - minX; - var x2 = a * w0 + c * h1 + tx; - var y2 = d * h1 + b * w0 + ty; + bounds.y = minY; + bounds.height = maxY - minY; - var x3 = a * w0 + c * h0 + tx; - var y3 = d * h0 + b * w0 + ty; - - var x4 = a * w1 + c * h0 + tx; - var y4 = d * h0 + b * w1 + ty; - - minX = x1; - minX = x2 < minX ? x2 : minX; - minX = x3 < minX ? x3 : minX; - minX = x4 < minX ? x4 : minX; - - minY = y1; - minY = y2 < minY ? y2 : minY; - minY = y3 < minY ? y3 : minY; - minY = y4 < minY ? y4 : minY; - - maxX = x1; - maxX = x2 > maxX ? x2 : maxX; - maxX = x3 > maxX ? x3 : maxX; - maxX = x4 > maxX ? x4 : maxX; - - maxY = y1; - maxY = y2 > maxY ? y2 : maxY; - maxY = y3 > maxY ? y3 : maxY; - maxY = y4 > maxY ? y4 : maxY; + // store a reference so that if this function gets called again in the render cycle we do not have to recalculate + this._currentBounds = bounds; } - var bounds = this._bounds; - - bounds.x = minX; - bounds.width = maxX - minX; - - bounds.y = minY; - bounds.height = maxY - minY; - - // store a reference so that if this function gets called again in the render cycle we do not have to recalculate - this._currentBounds = bounds; - - return bounds; + return this._currentBounds; }; /**