distance

geo.distance · #wphrjtgy · term · runs anywhere

The distance between two points, to digits decimal places if given.

distance({ x: 0, y: 0 }, { x: 1, y: 1 }, 3)
⧩ 1.414
import type { Point } from "#codebase/geo";

export const distance = (a: Point, b: Point, digits?: number): number => {
  const d = Math.hypot(a.x - b.x, a.y - b.y);
  return digits === undefined ? d : Number(d.toFixed(digits));
}

uses

used by