mirror of
https://github.com/hex248/tsos.git
synced 2026-02-07 18:23:05 +00:00
morphPoints function
This commit is contained in:
18
src/lib/shapes/morph.ts
Normal file
18
src/lib/shapes/morph.ts
Normal 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,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user