Added equals and hashCode functions to Point3D

This commit is contained in:
Obique PSWG
2016-01-31 15:36:47 -06:00
parent 8d3a941731
commit 159115cba4
+16
View File
@@ -110,6 +110,22 @@ public class Point3D implements Encodable, Serializable {
y = Packet.getFloat(data);
z = Packet.getFloat(data);
}
public boolean equals(Object o) {
if (!(o instanceof Point3D))
return false;
if (Math.abs(((Point3D) o).getX()-getX()) > 1E-7)
return false;
if (Math.abs(((Point3D) o).getY()-getY()) > 1E-7)
return false;
if (Math.abs(((Point3D) o).getZ()-getZ()) > 1E-7)
return false;
return true;
}
public int hashCode() {
return Double.hashCode(getX()) ^ Double.hashCode(getY()) ^ Double.hashCode(getZ());
}
public String toString() {
return String.format("Point3D[%.2f, %.2f, %.2f]", x, y, z);