Dev Helpers
← Back

Interpolate a readonly coordinate pair

Interpolate a readonly coordinate pair using TypeScript.

Open this example in the interactive library

Source code

type Point = readonly [x: number, y: number];
const a: Point = [3, 4],
  b: Point = [7, 1];
console.log(
  ((p: Point, q: Point, t: number): Point => [
    p[0] + (q[0] - p[0]) * t,
    p[1] + (q[1] - p[1]) * t,
  ])(a, b, 0.5),
);

Sample output

[ 5, 2.5 ]