morphPoints function

This commit is contained in:
2026-01-25 09:06:47 +00:00
parent 6133453746
commit c1a18f44f2

18
src/lib/shapes/morph.ts Normal file
View File

@@ -0,0 +1,18 @@
import type { Point } from "./points";
// lerps each point pair by factor t
export function morphPoints(fromPoints: Point[], toPoints: Point[], t: number): Point[] {
if (fromPoints.length !== toPoints.length) {
throw new Error(
`Point arrays must have the same length. Got ${fromPoints.length} and ${toPoints.length}`,
);
}
return fromPoints.map((from, i) => {
const to = toPoints[i];
return {
x: from.x + (to.x - from.x) * t,
y: from.y + (to.y - from.y) * t,
};
});
}