Java Geometry Algorithm boundingBox(Vector points)

Here you can find the source of boundingBox(Vector points)

Description

bounding Box

License

Open Source License

Declaration

public static Rectangle2D boundingBox(Vector<Point2D> points) 

Method Source Code

//package com.java2s;
/*  /*from   w  w w .  j a v a  2s .  co  m*/
 *   Authors: Caroline Appert (caroline.appert@lri.fr)
 *   Copyright (c) Universite Paris-Sud XI, 2007. All Rights Reserved
 *   Licensed under the GNU LGPL. For full terms see the file COPYING.
*/

import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.Iterator;
import java.util.Vector;

public class Main {
    public static Rectangle2D boundingBox(Vector<Point2D> points) {
        double minX = Double.MAX_VALUE;
        double minY = Double.MAX_VALUE;
        double maxX = Double.MIN_VALUE;
        double maxY = Double.MIN_VALUE;
        Point2D next;
        for (Iterator<Point2D> iterator = points.iterator(); iterator.hasNext();) {
            next = iterator.next();
            minX = Math.min(minX, next.getX());
            maxX = Math.max(maxX, next.getX());
            minY = Math.min(minY, next.getY());
            maxY = Math.max(maxY, next.getY());
        }
        double w = maxX - minX;
        if (w < 1)
            w = 1;
        double h = maxY - minY;
        if (h < 1)
            h = 1;
        return new Rectangle2D.Double(minX, minY, w, h);
    }
}

Related

  1. assertEDT(String point)
  2. botCorners(Point2D.Double p)
  3. botRect(Point2D.Double botLocation)
  4. botSides( Point2D.Double botLocation)
  5. bound(Point... points)
  6. boundsOf(Collection points)
  7. cap(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, double radius)
  8. centroid(Vector points)
  9. checkPoint(Point p)