Added a utility method for dealing with location precision to bukkit utilities.

This commit is contained in:
hash 2011-06-06 19:32:15 -05:00
parent 126815fcf5
commit b5c9f70e70

View File

@ -86,4 +86,16 @@ public class BukkitUtil {
public static World toWorld(WorldVector pt) {
return ((BukkitWorld)pt.getWorld()).getWorld();
}
/**
* Bukkit's Location class has serious problems with floating point
* precision.
*/
public static boolean equals(Location a, Location b) {
if (Math.abs(a.getX()-b.getX()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getY()-b.getY()) > EQUALS_PRECISION) return false;
if (Math.abs(a.getZ()-b.getZ()) > EQUALS_PRECISION) return false;
return true;
}
public static final double EQUALS_PRECISION = 0.0001;
}