Added two new utility datatypes.

This commit is contained in:
Harrison Deng 2020-05-03 16:38:23 -05:00
parent dc3ccb6ff0
commit 9aaaede19f
2 changed files with 76 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}