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 = of();
	public static final Vec2l MINUS_ONE = of(-1L);
	public static final Vec2l ONE = of(1L);
	
	public static Vec2l mutable() { return new Vec2lMutable(); }
	public static Vec2l mutable(long value) { return new Vec2lMutable(value); }
	public static Vec2l mutable(long x, long y) { return new Vec2lMutable(x, y); }
	public static Vec2l mutable(Vec2l value) { return mutable(value.x(), value.y()); }
	public static Vec2l of() { return new Vec2lImmutable(); }
	public static Vec2l of(long value) { return new Vec2lImmutable(value); }
	public static Vec2l of(long x, long y) { return new Vec2lImmutable(x, y); }
	public static Vec2l of(Vec2l value) { return of(value.x(), value.y()); }
	
	public long x();
	public long y();
	public Vec2l x(long x);
	public Vec2l y(long y);
	
	@Override
	public default long[] asArray() { return new long[] {x(), y()}; }
	@Override
	public Vec2l copy();
	@Override
	public default Vec2l abs() { return set(Math.abs(x()), Math.abs(y())); }
	@Override
	public default Vec2l negate() { return set(0L, 0L); }
	@Override
	public default Vec2l invert() { return set(-x(), -y()); };
	@Override
	public default Vec2l add(long value) { return add(value, value); }
	public default Vec2l add(Vec2l value) { return add(value.x(), value.y()); }
	public default Vec2l add(long x, long y) { return set(x + x(), y + y()); }
	@Override
	public default Vec2l sub(long value) { return sub(value, value); }
	public default Vec2l sub(Vec2l value) { return sub(value.x(), value.y()); }
	public default Vec2l sub(long x, long y) { return set(x() - x, y() - y); }
	@Override
	public default Vec2l multiply(long value) { return multiply(value, value); }
	public default Vec2l multiply(Vec2l value) { return multiply(value.x(), value.y()); }
	public default Vec2l multiply(long x, long y) { return set(x * x(), y * y()); }
	@Override
	public default Vec2l devide(long value) { return devide(value, value); }
	public default Vec2l devide(Vec2l value) { return devide(value.x(), value.y()); }
	public default Vec2l devide(long x, long y) { return set(x() / x, y() / y); }
	@Override
	public default Vec2l set(long value) { return set(value, value); };
	public default Vec2l set(Vec2l value) { return set(value.x(), value.y()); }
	public Vec2l set(long x, long y);
	public default double distanceTo(Vec2l value) { return distanceTo(value.x(), value.y()); }
	public default double distanceTo(long x, long y) { return Math.sqrt(distanceToSquared(x, y)); }
	public default long distanceToSquared(Vec2l value) { return distanceToSquared(value.x(), value.y()); }
	public default long distanceToSquared(long x, long y) {
		long xPos = x() - x;
		long yPos = y() - y;
		return (xPos * xPos) + (yPos * yPos);
	}
	
	@Override
	public default long lengthSquared() { return (x() * x()) + (y() * y()); }
	public default long dotProduct(Vec2l value) { return dotProduct(value.x(), value.y()); }
	public default long dotProduct(long x, long y) { return (x() * x) + (y() * y); }
	public default Vec2l rotate(long angle, Vec2l center) { return rotate(angle, center.x(), center.y()); }
	public default Vec2l rotate(long angle, long x, long y) {
		long xPos = x() - x;
		long yPos = y() - 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.x(), other.y(), 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(x(), x), Math.min(y(), y)); }
	public default Vec2l max(Vec2l other) { return max(other, this); }
	public default Vec2l max(Vec2l other, Vec2l result) { return max(other.x(), other.y(), 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(x(), x), Math.max(y(), y)); }
	public default Vec2l difference(Vec2l other) { return difference(other, this); }
	public default Vec2l difference(Vec2l other, Vec2l result) { return difference(other.x(), other.y(), 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(x() - x, y() - 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 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y())); }
	
	@Override
	public default Vec2l store(ByteBuffer buffer) {
		buffer.putLong(x()).putLong(y());
		return this;
	}
	
	@Override
	public default Vec2l load(ByteBuffer buffer) { return set(buffer.getLong(), buffer.getLong()); }
	
	@Override
	public default Vec2l store(LongBuffer buffer) {
		buffer.put(x()).put(y());
		return this;
	}
	
	@Override
	public default Vec2l load(LongBuffer buffer) { return set(buffer.get(), buffer.get()); }
	@Override
	public default Vec2b asByte() { return isMutable() ? Vec2b.mutable((byte)x(), (byte)y()) : Vec2b.of((byte)x(), (byte)y()); }
	@Override
	public default Vec2s asShort() { return isMutable() ? Vec2s.mutable((short)x(), (short)y()) : Vec2s.of((short)x(), (short)y()); }
	@Override
	public default Vec2i asInt() { return isMutable() ? Vec2i.mutable((int)x(), (int)y()) : Vec2i.of((int)x(), (int)y()); }
	@Override
	public default Vec2f asFloat() { return isMutable() ? Vec2f.mutable(x(), y()) : Vec2f.of(x(), y()); }
	@Override
	public default Vec2d asDouble() { return isMutable() ? Vec2d.mutable(x(), y()) : Vec2d.of(x(), y()); }
	@Override
	public default Vec2l asMutable() { return isMutable() ? this : mutable(this); }
	@Override
	public default Vec2l asImmutable() { return isMutable() ? of(this) : this; }
	@Override
	public default Vec2l copyAsMutable() { return mutable(this); }
	@Override
	public default Vec2l copyAsImmutable() { return of(this); }
}
