package math;

/**
 * The supremum metric.  This is sometimes also
 * called the uniform metric and/or the infinity metric.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class      SupremumMetric
       implements Metric
{
    /**
     * Calculate the distance between two n-dimensional points
     * (required by Metric)
     *
     * Note: For simplicity, this method does not confirm that the
     * two arrays are the same size. It uses the smaller size.
     *
     * @param a   One n-dimensional point
     * @param b   Another n-dimensional point
     * @return    The distance
    */
    public double distance(double[] a, double[] b)
    {
       double  result, term;       
       int     n;
       
       result = Math.abs(a[0]-b[0]);       
       n      = Math.min(a.length, b.length);

       for (int i=1; i<n; i++)
       {
          term = Math.abs(a[i]-b[i]);

          if (term > result) result = term;          
       }

       return result;       
    }
    

}
