summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsk89q <the.sk89q@gmail.com>2011-01-03 17:55:42 +0800
committerDinner Bone <dinnerbone@dinnerbone.com>2011-01-03 22:59:04 +0800
commitb3bc868ce372aa25351087194c732e4c4db39da5 (patch)
treedd3f1dc1c10ffcb327bb1149b5b76d2c1e65c593 /src
parent135c6f240a4f6c82f9c8f127a4bd28b966fa7c64 (diff)
downloadbukkit-b3bc868ce372aa25351087194c732e4c4db39da5.tar
bukkit-b3bc868ce372aa25351087194c732e4c4db39da5.tar.gz
bukkit-b3bc868ce372aa25351087194c732e4c4db39da5.tar.lz
bukkit-b3bc868ce372aa25351087194c732e4c4db39da5.tar.xz
bukkit-b3bc868ce372aa25351087194c732e4c4db39da5.zip
Made Vector.equals() fuzzy.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/bukkit/Vector.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/main/java/org/bukkit/Vector.java b/src/main/java/org/bukkit/Vector.java
index b5ee2bde..11b56f40 100644
--- a/src/main/java/org/bukkit/Vector.java
+++ b/src/main/java/org/bukkit/Vector.java
@@ -8,6 +8,11 @@ package org.bukkit;
public class Vector implements Cloneable {
private static final long serialVersionUID = -2657651106777219169L;
+ /**
+ * Threshold for fuzzy equals().
+ */
+ private static final double epsilon = 0.000001;
+
protected double x;
protected double y;
protected double z;
@@ -321,6 +326,10 @@ public class Vector implements Cloneable {
return this;
}
+ /**
+ * Checks to see if two objects are equal. Only two Vectors can ever
+ * return true
+ */
@Override
public boolean equals(Object obj) {
if (!(obj instanceof Vector)) {
@@ -329,9 +338,9 @@ public class Vector implements Cloneable {
Vector other = (Vector)obj;
- return Double.doubleToLongBits(x) == Double.doubleToLongBits(other.x)
- && Double.doubleToLongBits(y) == Double.doubleToLongBits(other.y)
- && Double.doubleToLongBits(z) == Double.doubleToLongBits(other.z);
+ return Math.abs(x - other.x) < epsilon
+ && Math.abs(y - other.y) < epsilon
+ && Math.abs(z - other.z) < epsilon;
}
@Override
@@ -360,6 +369,15 @@ public class Vector implements Cloneable {
}
/**
+ * Get the threshold used for equals().
+ *
+ * @return
+ */
+ public static double getEpsilon() {
+ return epsilon;
+ }
+
+ /**
* Gets the minimum components of two vectors.
*
* @param v1