/// <summary> /// Divide the specified Rectangle into two component rectangles /// </summary> /// <param name="amount">Amount to move away from the given edge</param> /// <param name="fromEdge">The edge to create the slice from.</param> public static Tuple<RectangleF, RectangleF> Divide(this RectangleF This, float amount, RectEdge fromEdge) { var delta = default(float); switch (fromEdge) { case RectEdge.Left: delta = Math.Max(This.Width, amount); return Tuple.Create( new RectangleF(This.Left, This.Top, delta, This.Height), new RectangleF(This.Left + delta, This.Top, This.Width - delta, This.Height)); case RectEdge.Top: delta = Math.Max(This.Height, amount); return Tuple.Create( new RectangleF(This.Left, This.Top, This.Width, amount), new RectangleF(This.Left, This.Top + delta, This.Width, This.Height - delta)); case RectEdge.Right: delta = Math.Max(This.Width, amount); return Tuple.Create( new RectangleF(This.Right - delta, This.Top, delta, This.Height), new RectangleF(This.Left, This.Top, This.Width - delta, This.Height)); case RectEdge.Bottom: delta = Math.Max(This.Height, amount); return Tuple.Create( new RectangleF(This.Left, This.Bottom - delta, This.Width, delta), new RectangleF(This.Left, This.Top, This.Width, This.Height - delta)); default: throw new ArgumentException("edge"); } }
/// <summary> /// Divide the specified Rectangle into two component rectangles, adding /// a padding between them. /// </summary> /// <param name="amount">Amount to move away from the given edge</param> /// <param name="padding">The amount of padding that is in neither rectangle.</param> /// <param name="fromEdge">The edge to create the slice from.</param> public static Tuple<RectangleF, RectangleF> DivideWithPadding(this RectangleF This, float sliceAmount, float padding, RectEdge fromEdge) { var slice = This.Divide(sliceAmount, fromEdge); var pad = This.Divide(padding, fromEdge); return Tuple.Create(slice.Item1, pad.Item2); }