SimpleJavaEngine/src/main/java/speiger/src/coreengine/math/vector/quaternion/QuaternionImmutable.java

62 lines
1.7 KiB
Java

package speiger.src.coreengine.math.vector.quaternion;
import java.util.Arrays;
public class QuaternionImmutable implements Quaternion {
final float x;
final float y;
final float z;
final float w;
public QuaternionImmutable() {
x = 0F;
y = 0F;
z = 0F;
w = 1F;
}
public QuaternionImmutable(float x, float y, float z, float w) {
this.x = x;
this.y = y;
this.z = z;
this.w = w;
}
@Override
public Quaternion setX(float x) { return this.x == x ? this : set(x, y, z, w); }
@Override
public Quaternion setY(float y) { return this.y == y ? this : set(x, y, z, w); }
@Override
public Quaternion setZ(float z) { return this.z == z ? this : set(x, y, z, w); }
@Override
public Quaternion setW(float w) { return this.w == w ? this : set(x, y, z, w); }
@Override
public float getX() { return x; }
@Override
public float getY() { return y; }
@Override
public float getZ() { return z; }
@Override
public float getW() { return w; }
@Override
public Quaternion set(float x, float y, float z, float w) { return this.x == x && this.y == y && this.z == z && this.w == w ? this : Quaternion.of(x, y, z, w); }
@Override
public Quaternion copy() { return Quaternion.of(this); }
@Override
public boolean isMutable() { return false; }
@Override
public int hashCode() { return Arrays.hashCode(new float[] {x, y, z, w}); }
@Override
public boolean equals(Object obj) {
if(obj instanceof Quaternion) {
Quaternion other = (Quaternion)obj;
return other.getX() == x && other.getY() == y && other.getZ() == z && other.getW() == w;
}
return false;
}
@Override
public String toString() { return "Quaternion[x="+x+", y="+y+", z="+z+", w="+w+"]"; }
}