// UTILITY THINGS

//Custom square function for code readability
export const sqr = function (num) {
    return num * num;
  };
  
  // Custom distance function for determining the distance between two vectors (entities, blocks, etc)
  export const distance3D = function (v1, v2) {
    return Math.sqrt(sqr(v1.x - v2.x) + sqr(v1.y - v2.y) + sqr(v1.z - v2.z));
  };
  // Generate a 3D vector from 2 provided angles
  export const vector3FromAngles = function (alpha, beta) {
    let x = Math.cos(alpha) * Math.cos(beta);
    let z = Math.sin(alpha) * Math.cos(beta);
    let y = Math.sin(beta);
    return { x, y, z };
  };
  
  // Subtracts one vector from another; essentially returns a vector that points from one vector to the other
  export const subtractVectors = function (v1, v2) {
    return { x: v1.x - v2.x, y: v1.y - v2.y, z: v1.z - v2.z };
  };
  
  // Multiplies the vector by the number
  export const multiplyVector = function (vector, number) {
    return { x: vector.x * number, y: vector.y * number, z: vector.z * number };
  };
  
  // Divides the vector by the number
  export const divideVector = function (vector, number) {
    return { x: vector.x / number, y: vector.y / number, z: vector.z / number };
  };