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