Here you can find the source of boundingBox(Vector
public static Rectangle2D boundingBox(Vector<Point2D> points)
//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); } }