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