## edu.neu.ccs.util Class Metric

```java.lang.Object
edu.neu.ccs.util.Metric
```

public abstract class Metric
extends Object

The abstract class `Metric` define the requirement for a 2-dimensional distance measure or metric and includes methods to test when a pair of points are near to one another.

The class contains several static instances of itself, namely, EUCLID, MAX, and SUM. The following relationships hold:

`  MAX <= EUCLID <= SUM <= 2 * MAX`

Since:
2.4.0
Version:
2.4.0

 Field Summary `static Metric` `EUCLID`           The EUCLID metric computes the distance between (x1, y1) and (x2,y2) using the classic euclidean metric. `static Metric` `MAX`           The MAX metric computes the distance between (x1, y1) and (x2,y2) using the maximum of the absolute values of the differences in the coordinates. `static Metric` `SUM`           The SUM metric computes the distance between (x1, y1) and (x2,y2) using the sum of the absolute values of the differences in the coordinates.

 Constructor Summary `Metric()`

 Method Summary ` double` ```distance(double[] p1, double[] p2)```           Returns the distance between points p1 and p2. `abstract  double` ```distance(double x1, double y1, double x2, double y2)```           Returns this distance between (x1,y1) and (x2,y2) in this metric. ` double` ```distance(float[] p1, float[] p2)```           Returns the distance between points p1 and p2. ` double` ```distance(Point2D p1, Point2D p2)```           Returns the distance between points p1 and p2. ` boolean` ```isNear(double[] p1, double[] p2, double epsilon)```           Returns true if points p1 and p2 have distance less than or equal to epsilon. ` boolean` ```isNear(double x1, double y1, double x2, double y2, double epsilon)```           Returns true if (x1,y1) and (x2,y2) have distance less than or equal to epsilon. ` boolean` ```isNear(float[] p1, float[] p2, double epsilon)```           Returns true if points p1 and p2 have distance less than or equal to epsilon. ` boolean` ```isNear(Point2D p1, Point2D p2, double epsilon)```           Returns true if points p1 and p2 have distance less than or equal to epsilon.

 Methods inherited from class java.lang.Object `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

 Field Detail

### EUCLID

`public static final Metric EUCLID`

The EUCLID metric computes the distance between (x1, y1) and (x2,y2) using the classic euclidean metric.

Specifically, returns:

`  Math.sqrt((x * x) + (y * y))`

where:

`  x = x2 - x1`
`  y = y2 - y1`

To reduce the chance of overflow, the computation is actually done in a more mathematically stable fashion but the answer is in effect the same as the above formula.

### MAX

`public static final Metric MAX`

The MAX metric computes the distance between (x1, y1) and (x2,y2) using the maximum of the absolute values of the differences in the coordinates.

### SUM

`public static final Metric SUM`

The SUM metric computes the distance between (x1, y1) and (x2,y2) using the sum of the absolute values of the differences in the coordinates.

 Constructor Detail

### Metric

`public Metric()`
 Method Detail

### distance

```public abstract double distance(double x1,
double y1,
double x2,
double y2)```

Returns this distance between (x1,y1) and (x2,y2) in this metric.

This is the single abstract method that needs to be instantiated.

Parameters:
`x1` - the x-coordinate of point 1
`y1` - the y-coordinate of point 1
`x2` - the x-coordinate of point 2
`y2` - the y-coordinate of point 2

### distance

```public final double distance(Point2D p1,
Point2D p2)```

Returns the distance between points p1 and p2.

Returns `Double.MAX_VALUE` if either parameter is `null`.

Parameters:
`p1` - point 1
`p2` - point 2

### distance

```public final double distance(double[] p1,
double[] p2)```

Returns the distance between points p1 and p2.

Returns `Double.MAX_VALUE` if either parameter is `null` or not of length 2.

Parameters:
`p1` - point 1
`p2` - point 2

### distance

```public final double distance(float[] p1,
float[] p2)```

Returns the distance between points p1 and p2.

Returns `Double.MAX_VALUE` if either parameter is `null` or not of length 2.

Parameters:
`p1` - point 1
`p2` - point 2

### isNear

```public final boolean isNear(double x1,
double y1,
double x2,
double y2,
double epsilon)```

Returns true if (x1,y1) and (x2,y2) have distance less than or equal to epsilon.

Parameters:
`x1` - the x-coordinate of point 1
`y1` - the y-coordinate of point 1
`x2` - the x-coordinate of point 2
`y2` - the y-coordinate of point 2
`epsilon` - the measure of nearness

### isNear

```public final boolean isNear(Point2D p1,
Point2D p2,
double epsilon)```

Returns true if points p1 and p2 have distance less than or equal to epsilon.

Parameters:
`p1` - point 1
`p2` - point 2
`epsilon` - the measure of nearness

### isNear

```public final boolean isNear(double[] p1,
double[] p2,
double epsilon)```

Returns true if points p1 and p2 have distance less than or equal to epsilon.

Parameters:
`p1` - point 1
`p2` - point 2
`epsilon` - the measure of nearness

### isNear

```public final boolean isNear(float[] p1,
float[] p2,
double epsilon)```

Returns true if points p1 and p2 have distance less than or equal to epsilon.

Parameters:
`p1` - point 1
`p2` - point 2
`epsilon` - the measure of nearness