/**
 * The smallest rectangle containing a set of Point objects (represented
 * as two Point objects, one containing the minimal coordinates and
 * one containing the maximal coordinates).
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class RectangularHull
{
    private Point max, min;


    /**
     * Explicit Value Constructor
     */
    public RectangularHull(Point min, Point max)
    {
       double[]          v;
       int               n;
       
       n = min.getDimension();
       v = new double[n];

       for (int i=0; i<n; i++) v[i] = min.getCoordinate(i);
       this.min = new Point(v);

       for (int i=0; i<n; i++) v[i] = max.getCoordinate(i);
       this.max = new Point(v);
    }
    

    /**
     * Adjust this RectangularHull (if necessary) 
     * so that it includes the given Point
     *
     * @param p   The new Point
     */
    public void adjustFor(Point p)
    {
       min = Point.min(p, min);
       max = Point.max(p, max);
    }
    

    

    /**
     * Adjust this RectangularHull (if necessary) 
     * so that it includes another RectangularHull
     *
     * @param other   The other RectangularHull
     */
    public void adjustFor(RectangularHull other)
    {
       min = Point.min(other.getMin(), min);
       max = Point.max(other.getMax(), max);
    }
    



    /**
     * Get the maximal Point (e.g., the upper right corner)
     *
     * @return   The maximal point
     */
    public Point getMax()
    {
       return max;
    }


    /**
     * Get the minimal Point (e.g., the lower left corner)
     *
     * @return   The minimal point
     */
    public Point getMin()
    {
       return min;
    }
    
}
