export const degreesToRadians = (degrees: number): number => {
  return (degrees * Math.PI) / 180
}

export const radiansToDegrees = (radians: number): number => {
  return (radians * 180) / Math.PI
}

export const rotatePoint = (
  x: number,
  y: number,
  centerX: number,
  centerY: number,
  angleDegrees: number
): { x: number; y: number } => {
  const angle = degreesToRadians(angleDegrees)
  const cos = Math.cos(angle)
  const sin = Math.sin(angle)

  const dx = x - centerX
  const dy = y - centerY

  return {
    x: centerX + dx * cos - dy * sin,
    y: centerY + dx * sin + dy * cos,
  }
}

export const distance = (x1: number, y1: number, x2: number, y2: number): number => {
  const dx = x2 - x1
  const dy = y2 - y1
  return Math.sqrt(dx * dx + dy * dy)
}

export const clamp = (value: number, min: number, max: number): number => {
  return Math.min(Math.max(value, min), max)
}

export const lerp = (start: number, end: number, t: number): number => {
  return start * (1 - t) + end * t
}
