-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
MinDist.java
42 lines (39 loc) · 991 Bytes
/
MinDist.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package net.citizensnpcs.api.util.prtree;
/**
* Class that can calculate the MINDIST between a point and a rectangle
*/
public class MinDist {
/**
* Do not instantiate
*/
private MinDist() {
// empty
}
/**
* Calculate the MINDIST between the given MBRND and the given point
*
* @param mbr
* the bounding box to use
* @param p
* the point
* @return the squared distance
*/
public static double get(MBR mbr, PointND p) {
double res = 0;
for (int i = 0; i < p.getDimensions(); i++) {
double o = p.getOrd(i);
double rv = r(o, mbr.getMin(i), mbr.getMax(i));
double dr = o - rv;
res += dr * dr;
}
return res;
}
private static double r(double x, double min, double max) {
double r = x;
if (x < min)
r = min;
if (x > max)
r = max;
return r;
}
}