import type { Cell, DistanceMode } from './types';

/**
 * Distance between two cells, in cells.
 *  - 5e: Chebyshev (diagonals cost 1).
 *  - pf2e: diagonals alternate 1,2,1,2 (the 5-10-5 rule).
 *  - euclid: straight-line, rounded.
 */
export function gridDistance(a: Cell, b: Cell, mode: DistanceMode = '5e'): number {
  const dx = Math.abs(a.col - b.col);
  const dy = Math.abs(a.row - b.row);
  const diag = Math.min(dx, dy);
  const straight = Math.max(dx, dy) - diag;
  if (mode === 'euclid') return Math.round(Math.hypot(dx, dy));
  if (mode === 'pf2e') return straight + diag + Math.floor(diag / 2);
  return straight + diag; // 5e Chebyshev
}

export function toFeet(cells: number, feetPerCell: number): number {
  return cells * feetPerCell;
}
