From b5c9f70e70e94d2ab3078ff6316b66495e01ab43 Mon Sep 17 00:00:00 2001 From: hash Date: Mon, 6 Jun 2011 19:32:15 -0500 Subject: [PATCH] Added a utility method for dealing with location precision to bukkit utilities. --- .../java/com/sk89q/worldedit/bukkit/BukkitUtil.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java index 3b422feeb..c200e3a97 100644 --- a/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java +++ b/src/main/java/com/sk89q/worldedit/bukkit/BukkitUtil.java @@ -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; }