import { vec3 } from 'gl-matrix'

export function randomInt (min, max) {
  return Math.floor(Math.random() * (max - min + 1) + min)
}

export function clamp (num, min, max) {
  return Math.min(Math.max(num, min), max)
}

export function addv3 (one, two) {
  if (one.length !== 3) return null
  if (typeof two !== 'object') {
    return [
      one[0] + two, one[1] + two, one[2] + two
    ]
  }
  return [
    one[0] + two[0], one[1] + two[1], one[2] + two[2]
  ]
}

export function subv3 (one, two) {
  if (one.length !== 3) return null
  if (typeof two !== 'object') {
    return [
      one[0] - two, one[1] - two, one[2] - two
    ]
  }
  return [
    one[0] - two[0], one[1] - two[1], one[2] - two[2]
  ]
}

export function mulv3 (one, two) {
  if (one.length !== 3) return null
  if (typeof two !== 'object') {
    return [
      one[0] * two, one[1] * two, one[2] * two
    ]
  }
  return [
    one[0] * two[0], one[1] * two[1], one[2] * two[2]
  ]
}

export function divv3 (one, two) {
  if (one.length !== 3) return null
  if (typeof two !== 'object') {
    return [
      one[0] / two, one[1] / two, one[2] / two
    ]
  }
  return [
    one[0] / two[0], one[1] / two[1], one[2] / two[2]
  ]
}

export function normalv3 (vec) {
  let res = vec
  vec3.normalize(res, vec)
  return res
}

export function crossv3 (vec1, vec2) {
  let res = []
  vec3.cross(res, vec1, vec2)
  return res
}
