package math;

/**
 * The Euclidean metric (i.e., the notion of distance that
 * most people are familiar with)
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 1.0
 */
public class      EuclideanMetric
       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;       
       int     n;
       
       result = 0.0;       
       n      = Math.min(a.length, b.length);

       for (int i=0; i<n; i++)
       {
          result += Math.pow(a[i]-b[i], 2.0);          
       }

       return Math.sqrt(result);       
    }
    

}
