diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/datatypes/Point3.java b/src/main/java/ca/recrown/islandsurvivalcraft/datatypes/Point3.java new file mode 100644 index 0000000..3993398 --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/datatypes/Point3.java @@ -0,0 +1,38 @@ +package ca.recrown.islandsurvivalcraft.datatypes; + +import java.util.Objects; + +public class Point3 { + public final int x, y, z; + private final int hash; + + public Point3(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + this.hash = Objects.hash(x, y, z); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Point3) { + Point3 p = (Point3) obj; + return p.x == this.x && p.y == this.y && p.z == this.z; + } + return false; + } + + public boolean fastEquals(Point3 point) { + return point.hashCode() == this.hash && x == point.x && y == point.y && z == point.z; + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public String toString() { + return String.format("(%d, %d, %d)", x, y, z); + } +} \ No newline at end of file diff --git a/src/main/java/ca/recrown/islandsurvivalcraft/datatypes/Vector3.java b/src/main/java/ca/recrown/islandsurvivalcraft/datatypes/Vector3.java new file mode 100644 index 0000000..685d97e --- /dev/null +++ b/src/main/java/ca/recrown/islandsurvivalcraft/datatypes/Vector3.java @@ -0,0 +1,38 @@ +package ca.recrown.islandsurvivalcraft.datatypes; + +import java.util.Objects; + +public class Vector3 { + public final float x, y, z; + private final int hash; + + public Vector3(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + this.hash = Objects.hash(x, y, z); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof Point3) { + Point3 p = (Point3) obj; + return p.x == this.x && p.y == this.y && p.z == this.z; + } + return false; + } + + public boolean fastEquals(Point3 point) { + return point.hashCode() == this.hash && x == point.x && y == point.y && z == point.z; + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public String toString() { + return String.format("(%d, %d, %d)", x, y, z); + } +} \ No newline at end of file