mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 07:20:24 +01:00
Made Vector.equals() fuzzy.
By: sk89q <the.sk89q@gmail.com>
This commit is contained in:
parent
04c824307a
commit
6284b8117c
1 changed files with 21 additions and 3 deletions
|
@ -8,6 +8,11 @@ package org.bukkit;
|
||||||
public class Vector implements Cloneable {
|
public class Vector implements Cloneable {
|
||||||
private static final long serialVersionUID = -2657651106777219169L;
|
private static final long serialVersionUID = -2657651106777219169L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Threshold for fuzzy equals().
|
||||||
|
*/
|
||||||
|
private static final double epsilon = 0.000001;
|
||||||
|
|
||||||
protected double x;
|
protected double x;
|
||||||
protected double y;
|
protected double y;
|
||||||
protected double z;
|
protected double z;
|
||||||
|
@ -321,6 +326,10 @@ public class Vector implements Cloneable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to see if two objects are equal. Only two Vectors can ever
|
||||||
|
* return true
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (!(obj instanceof Vector)) {
|
if (!(obj instanceof Vector)) {
|
||||||
|
@ -329,9 +338,9 @@ public class Vector implements Cloneable {
|
||||||
|
|
||||||
Vector other = (Vector)obj;
|
Vector other = (Vector)obj;
|
||||||
|
|
||||||
return Double.doubleToLongBits(x) == Double.doubleToLongBits(other.x)
|
return Math.abs(x - other.x) < epsilon
|
||||||
&& Double.doubleToLongBits(y) == Double.doubleToLongBits(other.y)
|
&& Math.abs(y - other.y) < epsilon
|
||||||
&& Double.doubleToLongBits(z) == Double.doubleToLongBits(other.z);
|
&& Math.abs(z - other.z) < epsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -359,6 +368,15 @@ public class Vector implements Cloneable {
|
||||||
return new Location(world, x, y, z, yaw, pitch);
|
return new Location(world, x, y, z, yaw, pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the threshold used for equals().
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static double getEpsilon() {
|
||||||
|
return epsilon;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the minimum components of two vectors.
|
* Gets the minimum components of two vectors.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue