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