Skip to content

Commit

Permalink
Add some helper methods to Region3D
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Jul 30, 2013
1 parent 8d9cd1e commit f4bac0d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/main/java/net/citizensnpcs/api/util/prtree/Region3D.java
Expand Up @@ -87,4 +87,27 @@ public double getMin(int axis, Region3D<C> t) {
return t.getMin(axis);
}
}

public static <T> DistanceCalculator<Region3D<T>> distanceCalculator() {
return new DistanceCalculator<Region3D<T>>() {
@Override
public double distanceTo(Region3D<T> t, PointND p) {
double x = p.getOrd(0);
double y = p.getOrd(1);
double z = p.getOrd(2);
return Math.sqrt(Math.pow(x - ((t.getMin(0) + t.getMax(0)) / 2), 2)
+ Math.pow(y - ((t.getMin(1) + t.getMax(1)) / 2), 2)
+ Math.pow(z - ((t.getMin(2) + t.getMax(2)) / 2), 2));
}
};
}

public static <T> NodeFilter<Region3D<T>> alwaysAcceptNodeFilter() {
return new NodeFilter<Region3D<T>>() {
@Override
public boolean accept(Region3D<T> t) {
return true;
}
};
}
}

0 comments on commit f4bac0d

Please sign in to comment.