// Re-calculate the extents of a region
private static void CalculateExtents(Region reg)
{
if (reg.rects.Length == 0)
{
reg.extent = RectangleF.Empty;
return;
}
/* Since rectStart is the first rectangle in the region, it must have the
* smallest top and since rectEnd is the last rectangle in the region,
* it must have the largest bottom, because of banding.
*/
RectangleF rectStart = reg.rects[0];
float left = rectStart.Left;
float top = rectStart.Top;
RectangleF rectEnd = reg.rects[reg.rects.Length - 1];
float right = rectEnd.Right;
float bottom = rectEnd.Bottom;
for (int i = 0; i < reg.rects.Length; i++)
{
RectangleF rect = reg.rects[i];
if (rect.Left < left)
{
left = rect.Left;
}
if (rect.Right > right)
{
right = rect.Right;
}
}
reg.extent = RectangleF.FromLTRB(left, top, right, bottom);
}