mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Add cubic bezier curve visual debug
Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
This commit is contained in:
parent
77ea537c69
commit
028c397c0a
4 changed files with 85 additions and 8 deletions
|
@ -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)
|
||||
);
|
||||
};
|
||||
|
|
|
@ -132,9 +132,11 @@ export type Extent = {
|
|||
_brand: "excalimath_extent";
|
||||
};
|
||||
|
||||
// an ellipse is specified by its center, angle, and its major and minor axes
|
||||
// but for the sake of simplicity, we've used halfWidth and halfHeight instead
|
||||
// in replace of semi major and semi minor axes
|
||||
/**
|
||||
An ellipse is specified by its center, angle, and its major and minor axes
|
||||
but for the sake of simplicity, we've used halfWidth and halfHeight instead
|
||||
in replace of semi major and semi minor axes
|
||||
*/
|
||||
export type Ellipse<Point extends GenericPoint> = {
|
||||
center: Point;
|
||||
halfWidth: number;
|
||||
|
@ -142,3 +144,14 @@ export type Ellipse<Point extends GenericPoint> = {
|
|||
} & {
|
||||
_brand: "excalimath_ellipse";
|
||||
};
|
||||
|
||||
/**
|
||||
* Represents a cubic bezier with 2 control points on the point space of your
|
||||
* choosing.
|
||||
*/
|
||||
export type CubicBezier<P extends GenericPoint> = {
|
||||
start: P;
|
||||
end: P;
|
||||
control1: P;
|
||||
control2: P;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue