Java tutorial
//package com.java2s; //License from project: Apache License import java.awt.*; public class Main { public static Rectangle bound(Point... points) { int smallestX = Integer.MAX_VALUE; int smallestY = Integer.MAX_VALUE; int largestX = Integer.MIN_VALUE; int largestY = Integer.MIN_VALUE; for (Point point : points) { if (point == null) { continue; } if (point.x > largestX) largestX = point.x; if (point.y > largestY) largestY = point.y; if (point.x < smallestX) smallestX = point.x; if (point.y < smallestY) smallestY = point.y; } return new Rectangle(smallestX, smallestY, largestX - smallestX, largestY - smallestY); } }