Sparrow.Display.DisplayObjectContainer.BoundsInSpace C# (CSharp) Method

BoundsInSpace() public method

public BoundsInSpace ( DisplayObject targetSpace ) : Rectangle
targetSpace DisplayObject
return Sparrow.Geom.Rectangle
        override public Rectangle BoundsInSpace(DisplayObject targetSpace)
        {
            int numChildren = _children.Count;

            if (numChildren == 0)
            {
                Matrix transformationMatrix = TransformationMatrixToSpace(targetSpace);
                Point transformedPoint = transformationMatrix.TransformPoint(X, Y);
                return new Rectangle(transformedPoint.X, transformedPoint.Y);
            }
            else if (numChildren == 1)
            {
                return _children[0].BoundsInSpace(targetSpace);
            }
            else
            {
                float minX = float.MaxValue, maxX = -float.MaxValue, minY = float.MaxValue, maxY = -float.MaxValue;
                foreach (DisplayObject child in _children)
                {
                    Rectangle childBounds = child.BoundsInSpace(targetSpace);
                    minX = Math.Min(minX, childBounds.X);
                    maxX = Math.Max(maxX, childBounds.X + childBounds.Width);
                    minY = Math.Min(minY, childBounds.Top);
                    maxY = Math.Max(maxY, childBounds.Top + childBounds.Height);
                }
                return new Rectangle(minX, minY, maxX - minX, maxY - minY);
            }
        }