mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-09 01:58:11 +08:00
Bezier-rs: Convert from canvas to svg for constructors (#776)
* Convert constructor to use svg * Convert the through_points functions to svg Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Keavon Chambers
parent
8dce2144c4
commit
e9cd792635
@@ -0,0 +1,27 @@
|
||||
import { BezierCurveType, WasmBezierConstructorKey } from "@/utils/types";
|
||||
|
||||
export const getCurveType = (numPoints: number): BezierCurveType => {
|
||||
switch (numPoints) {
|
||||
case 2:
|
||||
return BezierCurveType.Linear;
|
||||
case 3:
|
||||
return BezierCurveType.Quadratic;
|
||||
case 4:
|
||||
return BezierCurveType.Cubic;
|
||||
default:
|
||||
throw new Error("Invalid number of points for a bezier");
|
||||
}
|
||||
};
|
||||
|
||||
export const getConstructorKey = (bezierCurveType: BezierCurveType): WasmBezierConstructorKey => {
|
||||
switch (bezierCurveType) {
|
||||
case BezierCurveType.Linear:
|
||||
return "new_linear";
|
||||
case BezierCurveType.Quadratic:
|
||||
return "new_quadratic";
|
||||
case BezierCurveType.Cubic:
|
||||
return "new_cubic";
|
||||
default:
|
||||
throw new Error("Invalid value for a BezierCurveType");
|
||||
}
|
||||
};
|
||||
@@ -14,9 +14,18 @@ export enum BezierCurveType {
|
||||
Cubic = "Cubic",
|
||||
}
|
||||
|
||||
export type BezierCallback = (canvas: HTMLCanvasElement, bezier: WasmBezierInstance, options: Record<string, number>, mouseLocation?: Point) => void;
|
||||
export type Callback = (canvas: HTMLCanvasElement, bezier: WasmBezierInstance, options: Record<string, number>, mouseLocation?: Point) => void;
|
||||
export type BezierCallback = (bezier: WasmBezierInstance, options: Record<string, number>) => string;
|
||||
export type SubpathCallback = (subpath: WasmSubpathInstance) => string;
|
||||
|
||||
export type ExampleOptions = {
|
||||
[key in BezierCurveType]: {
|
||||
disabled: boolean;
|
||||
sliderOptions: SliderOption[];
|
||||
customPoints: number[][];
|
||||
};
|
||||
};
|
||||
|
||||
export type SliderOption = {
|
||||
min: number;
|
||||
max: number;
|
||||
|
||||
Reference in New Issue
Block a user