make Flocation's getCircle not use a square root

This commit is contained in:
Henry Ammermann 2014-07-01 14:51:39 -07:00
parent 8a6a97cc90
commit 95899e7ab9

View File

@ -131,10 +131,18 @@ public class FLocation {
return Math.sqrt(dx * dx + dz * dz);
}
public double getDistanceSquaredTo(FLocation that) {
double dx = that.x - this.x;
double dz = that.z - this.z;
return dx * dx + dz * dz;
}
//----------------------------------------------//
// Some Geometry
//----------------------------------------------//
public Set<FLocation> getCircle(double radius) {
double radiusSquared = radius * radius;
Set<FLocation> ret = new LinkedHashSet<FLocation>();
if (radius <= 0) {
return ret;
@ -148,7 +156,7 @@ public class FLocation {
for (int x = xfrom; x <= xto; x++) {
for (int z = zfrom; z <= zto; z++) {
FLocation potential = new FLocation(this.worldName, x, z);
if (this.getDistanceTo(potential) <= radius) {
if (this.getDistanceSquaredTo(potential) <= radiusSquared) {
ret.add(potential);
}
}