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:
Hannah Li
2022-09-26 19:14:27 -07:00
committed by GitHub
co-authored by Keavon Chambers
parent 6e12651c56
commit aff454ec77
10 changed files with 308 additions and 57 deletions
@@ -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;