Add cubic bezier curve visual debug

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
Mark Tolmacs 2025-01-14 10:26:35 +01:00
parent 77ea537c69
commit 028c397c0a
No known key found for this signature in database
4 changed files with 85 additions and 8 deletions

View file

@ -1,5 +1,5 @@
import { pointFrom, pointRotateRads } from "./point";
import type { Curve, GenericPoint, Radians } from "./types";
import { isPoint, pointFrom, pointRotateRads } from "./point";
import type { CubicBezier, Curve, GenericPoint, Radians } from "./types";
/**
*
@ -221,3 +221,20 @@ const findClosestParameter = <Point extends GenericPoint>(
return closestT;
};
export const isBezier = <Point extends GenericPoint>(
c: unknown,
): c is CubicBezier<Point> => {
return (
c != null &&
typeof c === "object" &&
Object.hasOwn(c, "start") &&
Object.hasOwn(c, "end") &&
Object.hasOwn(c, "control1") &&
Object.hasOwn(c, "control2") &&
isPoint((c as CubicBezier<Point>).start) &&
isPoint((c as CubicBezier<Point>).end) &&
isPoint((c as CubicBezier<Point>).control1) &&
isPoint((c as CubicBezier<Point>).control2)
);
};