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.Vec3b;
import speiger.src.coreengine.math.vector.doubles.Vec3d;
import speiger.src.coreengine.math.vector.floats.Vec3f;
import speiger.src.coreengine.math.vector.ints.Vec3i;
import speiger.src.coreengine.math.vector.shorts.Vec3s;

public interface Vec3l extends Vecl {
	public static final Vec3l ZERO = of();
	public static final Vec3l MINUS_ONE = of(-1L);
	public static final Vec3l ONE = of(1L);
	
	public static Vec3l mutable() { return new Vec3lMutable(); }
	public static Vec3l mutable(long value) { return new Vec3lMutable(value); }
	public static Vec3l mutable(long x, long y, long z) { return new Vec3lMutable(x, y, z); }
	public static Vec3l mutable(Vec3l vec) { return mutable(vec.x(), vec.y(), vec.z()); }
	public static Vec3l of() { return new Vec3lImmutable(); }
	public static Vec3l of(long value) { return new Vec3lImmutable(value); }
	public static Vec3l of(long x, long y, long z) { return new Vec3lImmutable(x, y, z); }
	public static Vec3l of(Vec3l vec) { return of(vec.x(), vec.y(), vec.z()); }
	
	public long x();
	public long y();
	public long z();
	public Vec3l x(long x);
	public Vec3l y(long y);
	public Vec3l z(long z);
	
	@Override
	public default long[] asArray() { return new long[] {x(), y(), z()}; }
	@Override
	public Vec3l copy();
	@Override
	public default Vec3l abs() { return set(Math.abs(x()), Math.abs(y()), Math.abs(z())); }
	@Override
	public default Vec3l negate() { return set(0L, 0L, 0L); }
	@Override
	public default Vec3l invert() { return set(-x(), -y(), -z()); }
	@Override
	public default Vec3l add(long value) { return add(value, value, value); }
	public default Vec3l add(Vec3l value) { return add(value.x(), value.y(), value.z()); }
	public default Vec3l add(long x, long y, long z) { return set(x() + x, y() + y, z() + z); }
	@Override
	public default Vec3l sub(long value) { return sub(value, value, value); }
	public default Vec3l sub(Vec3l value) { return sub(value.x(), value.y(), value.z()); }
	public default Vec3l sub(long x, long y, long z) { return set(x() - x, y() - y, z() - z); }
	@Override
	public default Vec3l multiply(long value) { return multiply(value, value, value); }
	public default Vec3l multiply(Vec3l value) { return multiply(value.x(), value.y(), value.z()); }
	public default Vec3l multiply(long x, long y, long z) { return set(x() * x, y() * y, z() * z); }
	@Override
	public default Vec3l devide(long value) { return devide(value, value, value); }
	public default Vec3l devide(Vec3l value) { return devide(value.x(), value.y(), value.z()); }
	public default Vec3l devide(long x, long y, long z) { return set(x() / x, y() / y, z() / z); }
	@Override
	public default Vec3l set(long value) { return set(value, value, value); }
	public default Vec3l set(Vec3l value) { return set(value.x(), value.y(), value.z()); }
	public Vec3l set(long x, long y, long z);
	public default double distanceTo(Vec3l value) { return distanceTo(value.x(), value.y(), value.z()); }
	public default double distanceTo(long x, long y, long z) { return Math.sqrt(distanceToSquared(x, y, z)); }
	public default long distanceToSquared(Vec3l value) { return distanceToSquared(value.x(), value.y(), value.z()); }
	public default long distanceToSquared(long x, long y, long z) {
		long xPos = x() - x;
		long yPos = y() - y;
		long zPos = z() - z;
		return (xPos * xPos) + (yPos * yPos) + (zPos * zPos);
	}
	
	@Override
	public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()); }
	public default long dotProduct(Vec3l value) { return dotProduct(value.x(), value.y(), value.z()); }
	public default long dotProduct(long x, long y, long z) { return (x() * x) + (y() * y) + (z() * z); }
	public default Vec3l min(Vec3l other) { return min(other, this); }
	public default Vec3l min(Vec3l other, Vec3l result) { return min(other.x(), other.y(), other.z(), result); }
	public default Vec3l min(long x, long y, long z) { return min(x, y, z, this); }
	public default Vec3l min(long x, long y, long z, Vec3l result) { return result.set(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z)); }
	public default Vec3l max(Vec3l other) { return max(other, this); }
	public default Vec3l max(Vec3l other, Vec3l result) { return max(other.x(), other.y(), other.z(), result); }
	public default Vec3l max(long x, long y, long z) { return max(x, y, z, this); }
	public default Vec3l max(long x, long y, long z, Vec3l result) { return result.set(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z)); }
	public default Vec3l difference(Vec3l other) { return difference(other, this); }
	public default Vec3l difference(Vec3l other, Vec3l result) { return difference(other.x(), other.y(), other.z(), result); }
	public default Vec3l difference(long x, long y, long z) { return difference(x, y, z, this); }
	public default Vec3l difference(long x, long y, long z, Vec3l result) { return result.set(x() - x, y() - y, z() - z); }
	@Override
	public default Vec3l clamp(long min, long max) { return clamp(min, max, ALL); }
	public default Vec3l clamp(long min, long max, Vec3l result) { return clamp(min, max, result, ALL); }
	@Override
	public default Vec3l clamp(long min, long max, int filter) { return clamp(min, max, this, filter); }
	public default Vec3l clamp(long min, long max, Vec3l result, int filter) { return result.set((filter & X) == 0 ? x() : MathUtils.clamp(min, max, x()), (filter & Y) == 0 ? y() : MathUtils.clamp(min, max, y()), (filter & Z) == 0 ? z() : MathUtils.clamp(min, max, z())); }
	
	@Override
	public default Vec3l store(ByteBuffer buffer) {
		buffer.putLong(x()).putLong(y()).putLong(z());
		return this;
	}
	
	@Override
	public default Vec3l load(ByteBuffer buffer) { return set(buffer.getLong(), buffer.getLong(), buffer.getLong()); }
	
	@Override
	public default Vec3l store(LongBuffer buffer) {
		buffer.put(x()).put(y()).put(z());
		return this;
	}
	
	@Override
	public default Vec3l load(LongBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get()); }
	@Override
	public default Vec3b asByte() { return isMutable() ? Vec3b.mutable((byte)x(), (byte)y(), (byte)z()) : Vec3b.of((byte)x(), (byte)y(), (byte)z()); }
	@Override
	public default Vec3s asShort() { return isMutable() ? Vec3s.mutable((short)x(), (short)y(), (short)z()) : Vec3s.of((short)x(), (short)y(), (short)z()); }
	@Override
	public default Vec3i asInt() { return isMutable() ? Vec3i.mutable((int)x(), (int)y(), (int)z()) : Vec3i.of((int)x(), (int)y(), (int)z()); }
	@Override
	public default Vec3f asFloat() { return isMutable() ? Vec3f.mutable(x(), y(), z()) : Vec3f.of(x(), y(), z()); }
	@Override
	public default Vec3d asDouble() { return isMutable() ? Vec3d.mutable(x(), y(), z()) : Vec3d.of(x(), y(), z()); }
	@Override
	public default Vec3l asMutable() { return isMutable() ? this : mutable(this); }
	@Override
	public default Vec3l asImmutable() { return isMutable() ? of(this) : this; }
	@Override
	public default Vec3l copyAsMutable() { return mutable(this); }
	@Override
	public default Vec3l copyAsImmutable() { return of(this); }
}
