All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ags.utils.dataStructures.trees.thirdGenKD.SquareEuclideanDistanceFunction Maven / Gradle / Ivy

There is a newer version: 0.9.1
Show newest version
package ags.utils.dataStructures.trees.thirdGenKD;

/**
 *
 */
public class SquareEuclideanDistanceFunction implements DistanceFunction {
    @Override
    public double distance(double[] p1, double[] p2) {
        double d = 0;

        for (int i = 0; i < p1.length; i++) {
            double diff = (p1[i] - p2[i]);
            d += diff * diff;
        }

        return d;
    }

    @Override
    public double distanceToRect(double[] point, double[] min, double[] max) {
        double d = 0;

        for (int i = 0; i < point.length; i++) {
            double diff = 0;
            if (point[i] > max[i]) {
                diff = (point[i] - max[i]);
            }
            else if (point[i] < min[i]) {
                diff = (point[i] - min[i]);
            }
            d += diff * diff;
        }

        return d;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy