make Flocation's getCircle not use a square root
This commit is contained in:
parent
8a6a97cc90
commit
95899e7ab9
@ -131,10 +131,18 @@ public class FLocation {
|
|||||||
return Math.sqrt(dx * dx + dz * dz);
|
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
|
// Some Geometry
|
||||||
//----------------------------------------------//
|
//----------------------------------------------//
|
||||||
public Set<FLocation> getCircle(double radius) {
|
public Set<FLocation> getCircle(double radius) {
|
||||||
|
double radiusSquared = radius * radius;
|
||||||
|
|
||||||
Set<FLocation> ret = new LinkedHashSet<FLocation>();
|
Set<FLocation> ret = new LinkedHashSet<FLocation>();
|
||||||
if (radius <= 0) {
|
if (radius <= 0) {
|
||||||
return ret;
|
return ret;
|
||||||
@ -148,7 +156,7 @@ public class FLocation {
|
|||||||
for (int x = xfrom; x <= xto; x++) {
|
for (int x = xfrom; x <= xto; x++) {
|
||||||
for (int z = zfrom; z <= zto; z++) {
|
for (int z = zfrom; z <= zto; z++) {
|
||||||
FLocation potential = new FLocation(this.worldName, x, z);
|
FLocation potential = new FLocation(this.worldName, x, z);
|
||||||
if (this.getDistanceTo(potential) <= radius) {
|
if (this.getDistanceSquaredTo(potential) <= radiusSquared) {
|
||||||
ret.add(potential);
|
ret.add(potential);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user