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.Vec4b;
import speiger.src.coreengine.math.vector.doubles.Vec4d;
import speiger.src.coreengine.math.vector.floats.Vec4f;
import speiger.src.coreengine.math.vector.ints.Vec4i;
import speiger.src.coreengine.math.vector.longs.Vec4l;

public interface Vec4s extends Vecs {
	public static final Vec4s ZERO = of();
	public static final Vec4s MINUS_ONE = of((short)-1);
	public static final Vec4s ONE = of((short)1);
	
	public static Vec4s mutable() { return new Vec4sMutable(); }
	public static Vec4s mutable(short value) { return new Vec4sMutable(value); }
	public static Vec4s mutable(short x, short y, short z, short w) { return new Vec4sMutable(x, y, z, w); }
	public static Vec4s mutable(Vec4s vec) { return mutable(vec.x(), vec.y(), vec.z(), vec.w()); }
	public static Vec4s of() { return new Vec4sImmutable(); }
	public static Vec4s of(short value) { return new Vec4sImmutable(value); }
	public static Vec4s of(short x, short y, short z, short w) { return new Vec4sImmutable(x, y, z, w); }
	public static Vec4s of(Vec4s vec) { return of(vec.x(), vec.y(), vec.z(), vec.w()); }
	
	public short x();
	public short y();
	public short z();
	public short w();
	public Vec4s x(short x);
	public Vec4s y(short y);
	public Vec4s z(short z);
	public Vec4s w(short w);
	
	@Override
	public default short[] asArray() { return new short[] {x(), y(), z(), w()}; }
	@Override
	public Vec4s copy();
	@Override
	public default Vec4s abs() { return set((short)Math.abs(x()), (short)Math.abs(y()), (short)Math.abs(z()), (short)Math.abs(w())); }
	@Override
	public default Vec4s negate() { return set((short)0, (short)0, (short)0, (short)0); }
	@Override
	public default Vec4s invert() { return set((short)-x(), (short)-y(), (short)-z(), (short)-w()); }
	@Override
	public default Vec4s add(short value) { return add(value, value, value, value); }
	public default Vec4s add(Vec4s value) { return add(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4s add(short x, short y, short z, short w) { return set((short)(x() + x), (short)(y() + y), (short)(z() + z), (short)(w() + w)); }
	@Override
	public default Vec4s sub(short value) { return sub(value, value, value, value); }
	public default Vec4s sub(Vec4s value) { return sub(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4s sub(short x, short y, short z, short w) { return set((short)(x() - x), (short)(y() - y), (short)(z() - z), (short)(w() - w)); }
	@Override
	public default Vec4s multiply(short value) { return multiply(value, value, value, value); }
	public default Vec4s multiply(Vec4s value) { return multiply(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4s multiply(short x, short y, short z, short w) { return set((short)(x() * x), (short)(y() * y), (short)(z() * z), (short)(w() * w)); }
	@Override
	public default Vec4s devide(short value) { return devide(value, value, value, value); }
	public default Vec4s devide(Vec4s value) { return devide(value.x(), value.y(), value.z(), value.w()); }
	public default Vec4s devide(short x, short y, short z, short w) { return set((short)(x() / x), (short)(y() / y), (short)(z() / z), (short)(w() / w)); }
	@Override
	public default Vec4s set(short value) { return set(value, value, value, value); }
	public default Vec4s set(Vec4s value) { return set(value.x(), value.y(), value.z(), value.w()); }
	public Vec4s set(short x, short y, short z, short w);
	public default double distanceTo(Vec4s value) { return distanceTo(value.x(), value.y(), value.z(), value.w()); }
	public default double distanceTo(short x, short y, short z, short w) { return Math.sqrt(distanceTo(x, y, z, w)); }
	public default long distanceToSquared(Vec4s value) { return distanceToSquared(value.x(), value.y(), value.z(), value.w()); }
	public default long distanceToSquared(short x, short y, short z, short w) {
		long xPos = x() - x;
		long yPos = y() - y;
		long zPos = z() - z;
		long wPos = w() - w;
		return (xPos * xPos) + (yPos * yPos) + (zPos * zPos) + (wPos * wPos);
	}
	
	@Override
	public default long lengthSquared() { return (x() * x()) + (y() * y()) + (z() * z()) + (w() * w()); }
	public default long dotProduct(Vec4s value) { return dotProduct(value.x(), value.y(), value.z(), value.w()); }
	public default long dotProduct(short x, short y, short z, short w) { return (x() * x) + (y() * y) + (z() * z) + (w() * w); };
	public default Vec4s min(Vec4s other) { return min(other, this); }
	public default Vec4s min(Vec4s other, Vec4s result) { return min(other.x(), other.y(), other.z(), other.w(), result); }
	public default Vec4s min(short x, short y, short z, short w) { return min(x, y, z, w, this); }
	public default Vec4s min(short x, short y, short z, short w, Vec4s result) { return result.set((short)Math.min(x(), x), (short)Math.min(y(), y), (short)Math.min(z(), z), (short)Math.min(w(), w)); }
	public default Vec4s max(Vec4s other) { return max(other, this); }
	public default Vec4s max(Vec4s other, Vec4s result) { return max(other.x(), other.y(), other.z(), other.w(), result); }
	public default Vec4s max(short x, short y, short z, short w) { return max(x, y, z, w, this); }
	public default Vec4s max(short x, short y, short z, short w, Vec4s result) { return result.set((short)Math.max(x(), x), (short)Math.max(y(), y), (short)Math.max(z(), z), (short)Math.max(z(), z)); }
	public default Vec4s difference(Vec4s other) { return difference(other, this); }
	public default Vec4s difference(Vec4s other, Vec4s result) { return difference(other.x(), other.y(), other.z(), other.w(), result); }
	public default Vec4s difference(short x, short y, short z, short w) { return difference(x, y, z, w, this); }
	public default Vec4s difference(short x, short y, short z, short w, Vec4s result) { return result.set((short)(x() - x), (short)(y() - y), (short)(z() - z), (short)(w() - w)); }
	@Override
	public default Vec4s clamp(short min, short max) { return clamp(min, max, ALL); }
	public default Vec4s clamp(short min, short max, Vec4s result) { return clamp(min, max, result, ALL); }
	@Override
	public default Vec4s clamp(short min, short max, int filter) { return clamp(min, max, this, filter); }
	public default Vec4s clamp(short min, short max, Vec4s 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()), (filter & W) == 0 ? w() : MathUtils.clamp(min, max, w())); }
	
	@Override
	public default Vec4s store(ByteBuffer buffer) {
		buffer.putShort(x()).putShort(y()).putShort(z()).putShort(w());
		return this;
	}
	
	@Override
	public default Vec4s load(ByteBuffer buffer) { return set(buffer.getShort(), buffer.getShort(), buffer.getShort(), buffer.getShort()); }
	
	@Override
	public default Vec4s store(ShortBuffer buffer) {
		buffer.put(x()).put(y()).put(z()).put(w());
		return this;
	}
	
	@Override
	public default Vec4s load(ShortBuffer buffer) { return set(buffer.get(), buffer.get(), buffer.get(), buffer.get()); }
	@Override
	public default Vec4b asByte() { return isMutable() ? Vec4b.mutable((byte)x(), (byte)y(), (byte)z(), (byte)w()) : Vec4b.of((byte)x(), (byte)y(), (byte)z(), (byte)w()); }
	@Override
	public default Vec4i asInt() { return isMutable() ? Vec4i.mutable(x(), y(), z(), w()) : Vec4i.of(x(), y(), z(), w()); }
	@Override
	public default Vec4l asLong() { return isMutable() ? Vec4l.mutable(x(), y(), z(), w()) : Vec4l.of(x(), y(), z(), w()); }
	@Override
	public default Vec4f asFloat() { return isMutable() ? Vec4f.mutable(x(), y(), z(), w()) : Vec4f.of(x(), y(), z(), w()); }
	@Override
	public default Vec4d asDouble() { return isMutable() ? Vec4d.mutable(x(), y(), z(), w()) : Vec4d.of(x(), y(), z(), w()); }
	@Override
	public default Vec4s asMutable() { return isMutable() ? this : of(this); }
	@Override
	public default Vec4s asImmutable() { return isMutable() ? mutable(this) : this; }
	@Override
	public default Vec4s copyAsMutable() { return mutable(this); }
	@Override
	public default Vec4s copyAsImmutable() { return of(this); }
}
