Java Geometry Algorithm boundsOf(Collection points)

Here you can find the source of boundsOf(Collection points)

Description

Report the bounding box for all points

License

Open Source License

Parameter

Parameter Description
points the provided points

Return

the smallest rectangle that really contains all the points.

Declaration

public static Rectangle boundsOf(Collection<? extends Point> points) 

Method Source Code


//package com.java2s;
//  GNU Affero General Public License as published by the Free Software Foundation, either version

import java.awt.Point;
import java.awt.Rectangle;

import java.util.Collection;

public class Main {
    /**//from w w w .  j av a2s. co m
     * Report the bounding box for all points
     *
     * @param points the provided points
     * @return the smallest rectangle that really contains all the points.
     */
    public static Rectangle boundsOf(Collection<? extends Point> points) {
        if ((points == null) || points.isEmpty()) {
            return null;
        }

        Rectangle bounds = null;

        for (Point point : points) {
            if (bounds == null) {
                bounds = new Rectangle(point);
            } else {
                bounds.add(point);
            }
        }

        if (bounds != null) {
            // So that points located on right or bottom borders get really contained by the bounds
            bounds.width++;
            bounds.height++;
        }

        return bounds;
    }
}

Related

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