SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/ints/Vec3iImmutable.java

61 lines
1.4 KiB
Java

package speiger.src.coreengine.math.vector.ints;
import java.util.Objects;
public class Vec3iImmutable implements Vec3i {
final int x;
final int y;
final int z;
public Vec3iImmutable() {
x = 0;
y = 0;
z = 0;
}
public Vec3iImmutable(int value) {
x = value;
y = value;
z = value;
}
public Vec3iImmutable(int x, int y, int z) {
this.x = x;
this.y = y;
this.z = z;
}
@Override
public boolean isMutable() { return false; }
@Override
public int getX() { return x; }
@Override
public int getY() { return y; }
@Override
public int getZ() { return z; }
@Override
public Vec3i setX(int x) { return this.x == x ? this : Vec3i.of(x, y, z); }
@Override
public Vec3i setY(int y) { return this.y == y ? this : Vec3i.of(x, y, z); }
@Override
public Vec3i setZ(int z) { return this.z == z ? this : Vec3i.of(x, y, z); }
@Override
public Vec3i copy() { return Vec3i.of(this); }
@Override
public Vec3i set(int x, int y, int z) { return this.x == x && this.y == y && this.z == z ? this : Vec3i.of(x, y, z); }
@Override
public int hashCode() { return Objects.hash(x, y, z); }
@Override
public boolean equals(Object obj) {
if(obj instanceof Vec3i) {
Vec3i vec = (Vec3i)obj;
return vec.getX() == x && vec.getY() == y && vec.getZ() == z;
}
return false;
}
@Override
public String toString() { return "Vec3i[x="+x+", y="+y+", z="+z+"]"; }
}