
export class Vector3 {
    /**
     * @remarks Create a new Vector3.
     * @param value The value to crate a new Vector3. Either a single value used for x, y and z. Or an object with an x, y and z value.
     */
    constructor(value) {
        if (typeof value === 'object' && value !== null) {
            this.x = value.x;
            this.y = value.y;
            this.z = value.z;
        }
        else {
            this.x = value;
            this.y = value;
            this.z = value;
        }
    }
	
	
    add(value) {
        if (typeof value === 'object' && value !== null) {
            return new Vector3({ x: this.x + value.x, y: this.y + value.y, z: this.z + value.z });
        }
        else {
            return new Vector3({ x: this.x + value, y: this.y + value, z: this.z + value });
        }
    }
    subtract(value) {
        if (typeof value === 'object' && value !== null) {
            return new Vector3({ x: this.x - value.x, y: this.y - value.y, z: this.z - value.z });
        }
        else {
            return new Vector3({ x: this.x - value, y: this.y - value, z: this.z - value });
        }
    }
    multiply(value) {
        if (typeof value === 'object' && value !== null) {
            return new Vector3({ x: this.x * value.x, y: this.y * value.y, z: this.z * value.z });
        }
        else {
            return new Vector3({ x: this.x * value, y: this.y * value, z: this.z * value });
        }
    }
	
	equals(value) {
		return (this.x == value.x && this.y == value.y && this.z == value.z);
	}
	equals_xz(value) {
		return (this.x == value.x && this.z == value.z);
	}
	
	toCommand() {
		return `${this.x.toFixed(2)} ${this.y.toFixed(2)} ${this.z.toFixed(2)}`;
	}
	
}

export function copy(value)
{
	return new Vector3(value)
}
export function copyFloor(value)
{
	return new Vector3({x: Math.floor(value.x), y: Math.floor(value.y), z: Math.floor(value.z)});
}

export function fromRotation(rotation)
{
	let rotationH = rotation.y * -1;
	let z0 = Math.cos(rotationH *Math.PI/180);
	let x0 = Math.sin(rotationH *Math.PI/180);
	
	let rotationV = rotation.x * -1;
	let h = Math.cos(rotationV *Math.PI/180);
	let v = Math.sin(rotationV*Math.PI/180);
	
	return new Vector3({x: h*x0, y:v, z:h*z0});
}

export const North = new Vector3({ x: 0, y: 0, z: -1 });
export const South = new Vector3({ x: 0, y: 0, z: 1 });
export const West = new Vector3({ x: -1, y: 0, z: 0 });
export const East = new Vector3({ x: 1, y: 0, z: 0 });
export const Up = new Vector3({ x: 0, y: 1, z: 0 });
export const Down = new Vector3({ x: 0, y: -1, z: 0 });

