Java Rectangle Bounds getRectangleListBounds(Vector vctRectangles)

Here you can find the source of getRectangleListBounds(Vector vctRectangles)

Description

Return a rectangle that encapsulates all rectangles in the Vector.

License

Open Source License

Parameter

Parameter Description
vctRectangles The list of rectangles.

Declaration

public static Rectangle getRectangleListBounds(Vector vctRectangles) 

Method Source Code


//package com.java2s;
import java.awt.*;
import java.util.*;

public class Main {
    /**//from   www.  ja  v  a2  s.  co  m
     * Return a rectangle that encapsulates all rectangles in the Vector.
     * @param     vctRectangles    The list of rectangles.
     */
    public static Rectangle getRectangleListBounds(Vector vctRectangles) {
        // Call the version that takes an Enumeration object.
        return getRectangleListBounds(vctRectangles.elements());
    }

    /**
     * Return a rectangle that encapsulates all rectangles in the Enumeration.
     * @param     enumRectangles    The list of rectangles.
     */
    public static Rectangle getRectangleListBounds(Enumeration enumRectangles) {
        double nMinLeft = 20000;
        double nMinTop = 20000;
        double nMaxWidth = -1;
        double nMaxHeight = -1;
        // Process for rectangle in the list.
        while (enumRectangles.hasMoreElements()) {
            Rectangle rBounds = (Rectangle) (enumRectangles.nextElement());
            // Find new rectangle dimensions
            if (rBounds.getX() < nMinLeft) {
                nMinLeft = rBounds.getX();
            }
            if (rBounds.getY() < nMinTop) {
                nMinTop = rBounds.getY();
            }
            if (rBounds.getX() + rBounds.getWidth() > nMaxWidth) {
                nMaxWidth = rBounds.getX() + rBounds.getWidth();
            }
            if (rBounds.getY() + rBounds.getHeight() > nMaxHeight) {
                nMaxHeight = rBounds.getY() + rBounds.getHeight();
            }
        }
        return new Rectangle((int) nMinLeft, (int) nMinTop, (int) (nMaxWidth - nMinLeft),
                (int) (nMaxHeight - nMinTop));
    }
}

Related

  1. getBounds(Shape s)
  2. getBoundsInAncestor(Container ancestor, final Component comp, Rectangle bounds)
  3. getCenteredBoundsOn(Rectangle srcBounds, int width, int height)
  4. getLocalBounds(Component aComponent)
  5. getLocalBounds(Rectangle bounds, Container c)
  6. isInCollision(Rectangle boundedBoxPlayer, Rectangle boundedBoxObject)
  7. setBounds(Container container, Component component, Rectangle bounds)
  8. setBounds(java.awt.Rectangle hole, int xA, int yA, int xB, int yB)
  9. storeWindowBounds(java.awt.Window window, java.util.prefs.Preferences prefs)