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

import java.util.Objects;

public class Vec2dMutable implements Vec2d {
	double x;
	double y;
	
	public Vec2dMutable() {
		x = 0D;
		y = 0D;
	}
	
	public Vec2dMutable(double value) {
		x = value;
		y = value;
	}
	
	public Vec2dMutable(double x, double y) {
		this.x = x;
		this.y = y;
	}
	
	@Override
	public boolean isMutable() { return true; }
	@Override
	public double x() { return x; }
	@Override
	public double y() { return y; }
	
	@Override
	public Vec2d x(double x) {
		this.x = x;
		return this;
	}
	
	@Override
	public Vec2d y(double y) {
		this.y = y;
		return this;
	}
	
	@Override
	public Vec2d copy() { return Vec2d.mutable(this); }
	
	@Override
	public Vec2d set(double x, double y) {
		this.x = x;
		this.y = y;
		return this;
	}
	
	@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+"]"; }
}
