import type { DashSeg } from '../types';

export function dashifyLine(
  from: [number, number],
  to: [number, number],
  suspicious: boolean,
  distanceNm?: number,
  fromMmsi?: number,
  toMmsi?: number,
): DashSeg[] {
  const segs: DashSeg[] = [];
  const steps = 14;
  for (let i = 0; i < steps; i++) {
    if (i % 2 === 1) continue;
    const a0 = i / steps;
    const a1 = (i + 1) / steps;
    const lon0 = from[0] + (to[0] - from[0]) * a0;
    const lat0 = from[1] + (to[1] - from[1]) * a0;
    const lon1 = from[0] + (to[0] - from[0]) * a1;
    const lat1 = from[1] + (to[1] - from[1]) * a1;
    segs.push({
      from: [lon0, lat0],
      to: [lon1, lat1],
      suspicious,
      distanceNm,
      fromMmsi,
      toMmsi,
    });
  }
  return segs;
}
