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 x() { return x; }
	@Override
	public double y() { return y; }
	@Override
	public Vec2d x(double x) { return this.x == x ? this : Vec2d.of(x, y); }
	@Override
	public Vec2d y(double y) { return this.y == y ? this : Vec2d.of(x, y); }
	@Override
	public Vec2d copy() { return Vec2d.of(this); }
	@Override
	public Vec2d set(double x, double y) { return this.x == x && this.y == y ? this : Vec2d.of(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.x() == x && vec.y() == y;
		}
		return false;
	}
	
	@Override
	public String toString() { return "Vec2d[x="+x+", y="+y+"]"; }
}
