public override RectangleX getBounds(DisplayObjectX targetSpace) { RectangleX resultRect = new RectangleX(); int numChildren = mChildren.Count; if (numChildren == 0) { getTransformationMatrix(targetSpace, sHelperTransform); //todo; resultRect.setTo(0, 0, 0, 0); } else if (numChildren == 1) { resultRect = mChildren[0].getBounds(targetSpace); } else { float minX = float.MaxValue; float maxX = -float.MaxValue; float minY = float.MinValue; float maxY = -float.MinValue; for (int i = 0; i < numChildren; ++i) { resultRect = mChildren[i].getBounds(targetSpace); if (minX > resultRect.x) { minX = resultRect.x; } if (maxX < resultRect.width) { maxX = resultRect.width; } if (minY > resultRect.y) { minY = resultRect.y; } if (maxY < resultRect.height) { maxY = resultRect.height; } } resultRect.setTo(minX, minY, maxX - minX, maxY - minY); } return(resultRect); }
public override RectangleX getBounds(DisplayObjectX targetSpace) { RectangleX resultRect = new RectangleX(); if (targetSpace == this) // optimization { resultRect.setTo(0.0f, 0.0f, vertices[2].x, vertices[2].y); } else if (targetSpace == parent && rotation == 0.0) // optimization { float scaleX = this.scaleX; float scaleY = this.scaleY; Vector3X v = vertices[2]; resultRect.setTo(x - pivotX * scaleX, y - pivotY * scaleY, v.x * scaleX, v.y * scaleY); if (scaleX < 0) { resultRect.width *= -1; resultRect.x -= resultRect.width; } if (scaleY < 0) { resultRect.height *= -1; resultRect.y -= resultRect.height; } } else { getTransformationMatrix(targetSpace, sHelperTransform); float minX = float.MaxValue; float maxX = -float.MaxValue; float minY = float.MinValue; float maxY = -float.MinValue; int len = vertices.Length; for (int i = 0; i < len; i++) { Vector3X v = sHelperTransform.transformVector(vertices[i]); if (minX > v.x) { minX = v.x; } if (maxX < v.x) { maxX = v.x; } if (minY > v.y) { minY = v.y; } if (maxY < v.y) { maxY = v.y; } } resultRect.setTo(minX, minY, maxX - minX, maxY - minY); } return(resultRect); }