Apachai.Effects.Core.Utility.GetRegionBounds C# (CSharp) Method

GetRegionBounds() public static method

Allows you to find the bounding box for a "region" that is described as an array of bounding boxes.
public static GetRegionBounds ( Rectangle rects, int startIndex, int length ) : Rectangle
rects System.Drawing.Rectangle
startIndex int
length int
return System.Drawing.Rectangle
        public static Rectangle GetRegionBounds(Rectangle[] rects, int startIndex, int length)
        {
            if (rects.Length == 0) {
                return new Rectangle (0, 0, 0, 0);
            }

            int left = rects[startIndex].Left;
            int top = rects[startIndex].Top;
            int right = rects[startIndex].Right;
            int bottom = rects[startIndex].Bottom;

            for (int i = startIndex + 1; i < startIndex + length; ++i) {
                Rectangle rect = rects[i];

                if (rect.Left < left) {
                    left = rect.Left;
                }

                if (rect.Top < top) {
                    top = rect.Top;
                }

                if (rect.Right > right) {
                    right = rect.Right;
                }

                if (rect.Bottom > bottom) {
                    bottom = rect.Bottom;
                }
            }

            return Rectangle.FromLTRB (left, top, right, bottom);
        }