package speiger.src.coreengine.math.vector.doubles;

import java.util.Objects;

public class Vec3dImmutable implements Vec3d {
	final double x;
	final double y;
	final double z;
	
	public Vec3dImmutable() {
		x = 0;
		y = 0;
		z = 0;
	}
	
	public Vec3dImmutable(double value) {
		x = value;
		y = value;
		z = value;
	}
	
	public Vec3dImmutable(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	@Override
	public boolean isMutable() { return false; }
	@Override
	public double x() { return x; }
	@Override
	public double y() { return y; }
	@Override
	public double z() { return z; }
	@Override
	public Vec3d x(double x) { return this.x == x ? this : Vec3d.of(x, y, z); }
	@Override
	public Vec3d y(double y) { return this.y == y ? this : Vec3d.of(x, y, z); }
	@Override
	public Vec3d z(double z) { return this.z == z ? this : Vec3d.of(x, y, z); }
	@Override
	public Vec3d copy() { return Vec3d.of(this); }
	@Override
	public Vec3d set(double x, double y, double z) { return this.x == x && this.y == y && this.z == z ? this : Vec3d.of(x, y, z); }
	@Override
	public int hashCode() { return Objects.hash(x, y, z); }
	
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof Vec3d) {
			Vec3d vec = (Vec3d)obj;
			return vec.x() == x && vec.y() == y && vec.z() == z;
		}
		return false;
	}
	
	@Override
	public String toString() { return "Vec3d[x="+x+", y="+y+", z="+z+"]"; }
}
