/[projects]/dao/FuldDaekningWorker/src/main/java/ags/utils/dataStructures/trees/thirdGenKD/SquareEuclideanDistanceFunction.java
ViewVC logotype

Contents of /dao/FuldDaekningWorker/src/main/java/ags/utils/dataStructures/trees/thirdGenKD/SquareEuclideanDistanceFunction.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2744 - (show annotations) (download)
Wed Oct 7 19:32:00 2015 UTC (8 years, 7 months ago) by torben
File size: 840 byte(s)
Ny k-d tree implementation
1 package ags.utils.dataStructures.trees.thirdGenKD;
2
3 /**
4 *
5 */
6 public class SquareEuclideanDistanceFunction implements DistanceFunction {
7 @Override
8 public double distance(double[] p1, double[] p2) {
9 double d = 0;
10
11 for (int i = 0; i < p1.length; i++) {
12 double diff = (p1[i] - p2[i]);
13 d += diff * diff;
14 }
15
16 return d;
17 }
18
19 @Override
20 public double distanceToRect(double[] point, double[] min, double[] max) {
21 double d = 0;
22
23 for (int i = 0; i < point.length; i++) {
24 double diff = 0;
25 if (point[i] > max[i]) {
26 diff = (point[i] - max[i]);
27 }
28 else if (point[i] < min[i]) {
29 diff = (point[i] - min[i]);
30 }
31 d += diff * diff;
32 }
33
34 return d;
35 }
36 }

  ViewVC Help
Powered by ViewVC 1.1.20