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

import java.nio.ByteBuffer;
import java.nio.LongBuffer;

import speiger.src.coreengine.math.MathUtils;
import speiger.src.coreengine.math.vector.bytes.Vec2b;
import speiger.src.coreengine.math.vector.doubles.Vec2d;
import speiger.src.coreengine.math.vector.floats.Vec2f;
import speiger.src.coreengine.math.vector.ints.Vec2i;
import speiger.src.coreengine.math.vector.shorts.Vec2s;

public interface Vec2l extends Vecl
{
	public static final Vec2l ZERO = newVec();
	public static final Vec2l MINUS_ONE = newVec(-1L);
	public static final Vec2l ONE = newVec(1L);
	
	public static Vec2l newMutable(){return new Vec2lMutable();}
	public static Vec2l newMutable(long value){return new Vec2lMutable(value);}
	public static Vec2l newMutable(long x, long y){return new Vec2lMutable(x, y);}
	public static Vec2l newMutable(Vec2l value){return newMutable(value.getX(), value.getY());}
	
	public static Vec2l newVec(){return new Vec2lImmutable();}
	public static Vec2l newVec(long value){return new Vec2lImmutable(value);}
	public static Vec2l newVec(long x, long y){return new Vec2lImmutable(x, y);}
	public static Vec2l newVec(Vec2l value){return newVec(value.getX(), value.getY());}
	
	public long getX();
	public long getY();
	public Vec2l setX(long x);
	public Vec2l setY(long y);
	@Override
	public default long[] asArray(){return new long[]{getX(), getY()};}
	@Override
	public Vec2l copy();
	@Override
	public default Vec2l abs(){return set(Math.abs(getX()), Math.abs(getY()));}
	@Override
	public default Vec2l negate(){return set(0L, 0L);}
	@Override
	public default Vec2l invert(){return set(-getX(), -getY());};
	
	@Override
	public default Vec2l add(long value) {return add(value, value);}
	public default Vec2l add(Vec2l value) {return add(value.getX(), value.getY());}
	public default Vec2l add(long x, long y) {return set(x + getX(), y + getY());}
	
	@Override
	public default Vec2l sub(long value){return sub(value, value);}
	public default Vec2l sub(Vec2l value){return sub(value.getX(), value.getY());}
	public default Vec2l sub(long x, long y) {return set(getX() - x, getY() - y);}
	
	@Override
	public default Vec2l multiply(long value){return multiply(value, value);}
	public default Vec2l multiply(Vec2l value){return multiply(value.getX(), value.getY());}
	public default Vec2l multiply(long x, long y) {return set(x * getX(), y * getY());}
	
	@Override
	public default Vec2l devide(long value){return devide(value, value);}
	public default Vec2l devide(Vec2l value){return devide(value.getX(), value.getY());}
	public default Vec2l devide(long x, long y){return set(getX() / x, getY() / y);}
	
	@Override
	public default Vec2l set(long value){return set(value, value);};
	public default Vec2l set(Vec2l value){return set(value.getX(), value.getY());}
	public Vec2l set(long x, long y);
	
	public default double distanceTo(Vec2l value){return distanceTo(value.getX(), value.getY());}
	public default double distanceTo(long x, long y){return Math.sqrt(distanceToSquared(x, y));}
	
	public default long distanceToSquared(Vec2l value){return distanceToSquared(value.getX(), value.getY());}
	public default long distanceToSquared(long x, long y)
	{
		long xPos = getX() - x;
		long yPos = getY() - y;
		return (xPos * xPos) + (yPos * yPos);
	}
	@Override
	public default long lengthSquared() {return (getX() * getX()) + (getY() * getY());}
	
	public default long dotProduct(Vec2l value){return dotProduct(value.getX(), value.getY());}
	public default long dotProduct(long x, long y){return (getX() * x) + (getY() * y);}
	
	public default Vec2l rotate(long angle, Vec2l center){return rotate(angle, center.getX(), center.getY());}
	public default Vec2l rotate(long angle, long x, long y)
	{
		long xPos = getX() - x;
		long yPos = getY() - y;
		double cos = MathUtils.cos(angle);
		double sin = MathUtils.sin(angle);
	    return set((long)((xPos * cos) + (yPos * sin) + x), (long)(-(xPos * sin) + (yPos * cos) + y));
	}
	
	public default Vec2l min(Vec2l other) {return min(other, this);}
	public default Vec2l min(Vec2l other, Vec2l result){return min(other.getX(), other.getY(), result);}
	public default Vec2l min(long x, long y) {return min(x, y, this);}
	public default Vec2l min(long x, long y, Vec2l result){return result.set(Math.min(getX(), x), Math.min(getY(), y));}
	
	public default Vec2l max(Vec2l other) {return max(other, this);}
	public default Vec2l max(Vec2l other, Vec2l result){return max(other.getX(), other.getY(), result);}
	public default Vec2l max(long x, long y) {return max(x, y, this);}
	public default Vec2l max(long x, long y, Vec2l result){return result.set(Math.max(getX(), x), Math.max(getY(), y));}
	
	public default Vec2l difference(Vec2l other) {return difference(other, this);}
	public default Vec2l difference(Vec2l other, Vec2l result){return difference(other.getX(), other.getY(), result);}
	public default Vec2l difference(long x, long y) {return difference(x, y, this);}
	public default Vec2l difference(long x, long y, Vec2l result){return result.set(getX() - x, getY() - y);}
	
	@Override
	public default Vec2l clamp(long min, long max){return clamp(min, max, ALL);}
	public default Vec2l clamp(long min, long max, Vec2l result){return clamp(min, max, result, ALL);}
	@Override
	public default Vec2l clamp(long min, long max, int filter){return clamp(min, max, this, filter);}
	public default Vec2l clamp(long min, long max, Vec2l result, int filter){ return result.set((filter & X) == 0 ? getX() : MathUtils.clamp(min, max, getX()), (filter & Y) == 0 ? getY() : MathUtils.clamp(min, max, getY()));}
	
	@Override
	public default Vec2l store(ByteBuffer buffer)
	{
		buffer.putLong(getX()).putLong(getY());
		return this;
	}
	
	@Override
	public default Vec2l load(ByteBuffer buffer)
	{
		return set(buffer.getLong(), buffer.getLong());
	}
	
	@Override
	public default Vec2l store(LongBuffer buffer)
	{
		buffer.put(getX()).put(getY());
		return this;
	}
	
	@Override
	public default Vec2l load(LongBuffer buffer)
	{
		return set(buffer.get(), buffer.get());
	}
	
	@Override
	public default Vec2b asByte(){return isMutable() ? Vec2b.newMutable((byte)getX(), (byte)getY()) : Vec2b.newVec((byte)getX(), (byte)getY());}
	@Override
	public default Vec2s asShort(){return isMutable() ? Vec2s.newMutable((short)getX(), (short)getY()) : Vec2s.newVec((short)getX(), (short)getY());}
	@Override
	public default Vec2i asInt(){return isMutable() ? Vec2i.newMutable((int)getX(), (int)getY()) : Vec2i.newVec((int)getX(), (int)getY());}
	@Override
	public default Vec2f asFloat() {return isMutable() ? Vec2f.newMutable(getX(), getY()) : Vec2f.newVec(getX(), getY());}
	@Override
	public default Vec2d asDouble(){return isMutable() ? Vec2d.newMutable(getX(), getY()) : Vec2d.newVec(getX(), getY());}

	
	@Override
	public default Vec2l asMutable(){return isMutable() ? this : newMutable(this);}
	@Override
	public default Vec2l asImmutable(){return isMutable() ? newVec(this) : this;}
	@Override
	public default Vec2l copyAsMutable(){return newMutable(this);}
	@Override
	public default Vec2l copyAsImmutable(){return newVec(this);}
}
