export const Vec3Multiply = (vector3, scale) => ({
  x: vector3.x * scale.x,
  y: vector3.y * scale.y,
  z: vector3.z * scale.z,
});

export const Vec3Add = (vector3, addend) => ({
  x: vector3.x + addend.x,
  y: vector3.y + addend.y,
  z: vector3.z + addend.z,
});

export function Vec3Mormalize(vector) {
  const invMag = 1 / Vec3Magnitude(vector);
  return {
    x: vector.x * invMag,
    y: vector.y * invMag,
    z: vector.z * invMag,
  };
}
export const Vec3Subtract = (vector3, subtractor) => ({
  x: vector3.x - subtractor.x,
  y: vector3.y - subtractor.y,
  z: vector3.z - subtractor.z,
});

export const Vec3Scale = (vector3, scale) => ({
  x: vector3.x * scale,
  y: vector3.y * scale,
  z: vector3.z * scale,
});

export const Vec3Random = () => ({
  x: Math.random() * 2 - 1,
  y: Math.random() * 2 - 1,
  z: Math.random() * 2 - 1,
});

export const Vec3Magnitude = (vector3) =>
  Math.sqrt(vector3.x * vector3.x + vector3.y * vector3.y + vector3.z * vector3.z);

export const Vec3Normalize = (vector3) => {
  const magnitude = Vec3Magnitude(vector3);
  return {
    x: vector3.x / magnitude,
    y: vector3.y / magnitude,
    z: vector3.z / magnitude,
  };
};
export function applyImpulse(player, vector) {
  const { x, y, z } = vector;
  const horizontal = Math.sqrt(x * x + z * z) * 2.0;
  player.applyKnockback(x, z, horizontal, y);
}
export function clamp(value, min, max) {
  return Math.min(Math.max(value, min), max);
}
export function Vec3Pitch(vector) {
  const magnitude = Vec3Magnitude(vector);
  return Math.asin(vector.y / magnitude);
}
export function Vec3Degrees(radians) {
  return (radians * 180) / Math.PI;
}
export function Vec3Radians(degrees) {
  return (degrees * Math.PI) / 180;
}
export function Vec3Rotation(vector) {
  const vec2d = { x: vector.x, y: 0, z: vector.z };
  return Vec3Mormalize(vec2d);
}
