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

import java.nio.ByteBuffer;
import java.nio.ShortBuffer;

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.longs.Vec3l;

public interface Vec3s extends Vecs {
	public static final Vec3s ZERO = of();
	public static final Vec3s MINUS_ONE = of((short)-1);
	public static final Vec3s ONE = of((short)1);
	
	public static Vec3s mutable() { return new Vec3sMutable(); }
	public static Vec3s mutable(short value) { return new Vec3sMutable(value); }
	public static Vec3s mutable(short x, short y, short z) { return new Vec3sMutable(x, y, z); }
	public static Vec3s mutable(Vec3s vec) { return mutable(vec.x(), vec.y(), vec.z()); }
	public static Vec3s of() { return new Vec3sImmutable(); }
	public static Vec3s of(short value) { return new Vec3sImmutable(value); }
	public static Vec3s of(short x, short y, short z) { return new Vec3sImmutable(x, y, z); }
	public static Vec3s of(Vec3s vec) { return of(vec.x(), vec.y(), vec.z()); }
	
	public short x();
	public short y();
	public short z();
	public Vec3s x(short x);
	public Vec3s y(short y);
	public Vec3s z(short z);
	
	@Override
	public default short[] asArray() { return new short[] {x(), y(), z()}; }
	@Override
	public Vec3s copy();
	@Override
	public default Vec3s abs() { return set((short)Math.abs(x()), (short)Math.abs(y()), (short)Math.abs(z())); }
	@Override
	public default Vec3s negate() { return set((short)0, (short)0, (short)0); }
	@Override
	public default Vec3s invert() { return set((short)-x(), (short)-y(), (short)-z()); }
	@Override
	public default Vec3s add(short value) { return add(value, value, value); }
	public default Vec3s add(Vec3s value) { return add(value.x(), value.y(), value.z()); }
	public default Vec3s add(short x, short y, short z) { return set((short)(x() + x), (short)(y() + y), (short)(z() + z)); }
	@Override
	public default Vec3s sub(short value) { return sub(value, value, value); }
	public default Vec3s sub(Vec3s value) { return sub(value.x(), value.y(), value.z()); }
	public default Vec3s sub(short x, short y, short z) { return set((short)(x() - x), (short)(y() - y), (short)(z() - z)); }
	@Override
	public default Vec3s multiply(short value) { return multiply(value, value, value); }
	public default Vec3s multiply(Vec3s value) { return multiply(value.x(), value.y(), value.z()); }
	public default Vec3s multiply(short x, short y, short z) { return set((short)(x() * x), (short)(y() * y), (short)(z() * z)); }
	@Override
	public default Vec3s devide(short value) { return devide(value, value, value); }
	public default Vec3s devide(Vec3s value) { return devide(value.x(), value.y(), value.z()); }
	public default Vec3s devide(short x, short y, short z) { return set((short)(x() / x), (short)(y() / y), (short)(z() / z)); }
	@Override
	public default Vec3s set(short value) { return set(value, value, value); }
	public default Vec3s set(Vec3s value) { return set(value.x(), value.y(), value.z()); }
	public Vec3s set(short x, short y, short z);
	public default double distanceTo(Vec3s value) { return distanceTo(value.x(), value.y(), value.z()); }
	public default double distanceTo(short x, short y, short z) { return Math.sqrt(distanceToSquared(x, y, z)); }
	public default long distanceToSquared(Vec3s value) { return distanceToSquared(value.x(), value.y(), value.z()); }
	public default long distanceToSquared(short x, short y, short 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(Vec3s value) { return dotProduct(value.x(), value.y(), value.z()); }
	public default long dotProduct(short x, short y, short z) { return (x() * x) + (y() * y) + (z() * z); }
	public default Vec3s min(Vec3s other) { return min(other, this); }
	public default Vec3s min(Vec3s other, Vec3s result) { return min(other.x(), other.y(), other.z(), result); }
	public default Vec3s min(short x, short y, short z) { return min(x, y, z, this); }
	public default Vec3s min(short x, short y, short z, Vec3s result) { return result.set((short)Math.min(x(), x), (short)Math.min(y(), y), (short)Math.min(z(), z)); }
	public default Vec3s max(Vec3s other) { return max(other, this); }
	public default Vec3s max(Vec3s other, Vec3s result) { return max(other.x(), other.y(), other.z(), result); }
	public default Vec3s max(short x, short y, short z) { return max(x, y, z, this); }
	public default Vec3s max(short x, short y, short z, Vec3s result) { return result.set((short)Math.max(x(), x), (short)Math.max(y(), y), (short)Math.max(z(), z)); }
	public default Vec3s difference(Vec3s other) { return difference(other, this); }
	public default Vec3s difference(Vec3s other, Vec3s result) { return difference(other.x(), other.y(), other.z(), result); }
	public default Vec3s difference(short x, short y, short z) { return difference(x, y, z, this); }
	public default Vec3s difference(short x, short y, short z, Vec3s result) { return result.set((short)(x() - x), (short)(y() - y), (short)(z() - z)); }
	@Override
	public default Vec3s clamp(short min, short max) { return clamp(min, max, ALL); }
	public default Vec3s clamp(short min, short max, Vec3s result) { return clamp(min, max, result, ALL); }
	@Override
	public default Vec3s clamp(short min, short max, int filter) { return clamp(min, max, this, filter); }
	public default Vec3s clamp(short min, short max, Vec3s 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 Vec3s store(ByteBuffer buffer) {
		buffer.putShort(x()).putShort(y()).putShort(z());
		return this;
	}
	
	@Override
	public default Vec3s load(ByteBuffer buffer) { return set(buffer.getShort(), buffer.getShort(), buffer.getShort()); }
	
	@Override
	public default Vec3s store(ShortBuffer buffer) {
		buffer.put(x()).put(y()).put(z());
		return this;
	}
	
	@Override
	public default Vec3s load(ShortBuffer 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 Vec3i asInt() { return isMutable() ? Vec3i.mutable(x(), y(), z()) : Vec3i.of(x(), y(), z()); }
	@Override
	public default Vec3l asLong() { return isMutable() ? Vec3l.mutable(x(), y(), z()) : Vec3l.of(x(), y(), 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 Vec3s asMutable() { return isMutable() ? this : of(this); }
	@Override
	public default Vec3s asImmutable() { return isMutable() ? mutable(this) : this; }
	@Override
	public default Vec3s copyAsMutable() { return mutable(this); }
	@Override
	public default Vec3s copyAsImmutable() { return of(this); }
}
