From 95899e7ab9d25b4e8f9a9e56a7c21b356c12b52e Mon Sep 17 00:00:00 2001 From: Henry Ammermann Date: Tue, 1 Jul 2014 14:51:39 -0700 Subject: [PATCH] make Flocation's getCircle not use a square root --- src/main/java/com/massivecraft/factions/FLocation.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/massivecraft/factions/FLocation.java b/src/main/java/com/massivecraft/factions/FLocation.java index ee026c7a..c64bb8bf 100644 --- a/src/main/java/com/massivecraft/factions/FLocation.java +++ b/src/main/java/com/massivecraft/factions/FLocation.java @@ -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 getCircle(double radius) { + double radiusSquared = radius * radius; + Set ret = new LinkedHashSet(); 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); } }