mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-07 07:38:11 +08:00
Bezier-rs: Updated Bezier function signatures to accept TValue (#967)
* Create helper for converting d to t values * Add euclidean option for tangent and normal * Modified bezier functions signatures to accept ComputeType * Stylistic changes per review * Added ComputeType documentation * Renamed ComputeType to TValue * Fixed comments * Fixed failing unit tests * Code review * Fix comments in code review * Renamed compute_type_to_parametric to t_value_to_parametric --------- Co-authored-by: Linda Zheng <thelindazheng@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
committed by
Keavon Chambers
co-authored by
Linda Zheng
Keavon Chambers
parent
f0ad4c91d3
commit
a64c856ec4
@@ -6,7 +6,7 @@ export const tSliderOptions = {
|
||||
variable: "t",
|
||||
};
|
||||
|
||||
export const tErrorOptions = {
|
||||
export const errorOptions = {
|
||||
variable: "error",
|
||||
min: 0.1,
|
||||
max: 2,
|
||||
@@ -14,7 +14,7 @@ export const tErrorOptions = {
|
||||
default: 0.5,
|
||||
};
|
||||
|
||||
export const tMinimumSeperationOptions = {
|
||||
export const minimumSeparationOptions = {
|
||||
variable: "minimum_seperation",
|
||||
min: 0.001,
|
||||
max: 0.25,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ComputeType, Demo, DemoPane, SliderOption } from "@/utils/types";
|
||||
import { TVariant, Demo, DemoPane, SliderOption } from "@/utils/types";
|
||||
|
||||
export function renderDemo(demo: Demo): void {
|
||||
const header = document.createElement("h4");
|
||||
@@ -53,27 +53,27 @@ export function renderDemoPane(demoPane: DemoPane): void {
|
||||
header.className = "demo-pane-header";
|
||||
header.append(headerAnchorLink);
|
||||
|
||||
const computeTypeContainer = document.createElement("div");
|
||||
computeTypeContainer.className = "compute-type-choice";
|
||||
const tVariantContainer = document.createElement("div");
|
||||
tVariantContainer.className = "t-variant-choice";
|
||||
|
||||
const computeTypeLabel = document.createElement("strong");
|
||||
computeTypeLabel.innerText = "ComputeType:";
|
||||
computeTypeContainer.append(computeTypeLabel);
|
||||
const tVariantLabel = document.createElement("strong");
|
||||
tVariantLabel.innerText = "TValue Variant:";
|
||||
tVariantContainer.append(tVariantLabel);
|
||||
|
||||
const radioInputs = ["Parametric", "Euclidean"].map((computeType) => {
|
||||
const id = `${demoPane.id}-${computeType}`;
|
||||
const radioInputs = ["Parametric", "Euclidean"].map((tVariant) => {
|
||||
const id = `${demoPane.id}-${tVariant}`;
|
||||
const radioInput = document.createElement("input");
|
||||
radioInput.type = "radio";
|
||||
radioInput.id = id;
|
||||
radioInput.value = computeType;
|
||||
radioInput.name = "ComputeType";
|
||||
radioInput.checked = computeType === "Parametric";
|
||||
computeTypeContainer.append(radioInput);
|
||||
radioInput.value = tVariant;
|
||||
radioInput.name = `TVariant - ${demoPane.id}`;
|
||||
radioInput.checked = tVariant === "Parametric";
|
||||
tVariantContainer.append(radioInput);
|
||||
|
||||
const label = document.createElement("label");
|
||||
label.htmlFor = id;
|
||||
label.innerText = computeType;
|
||||
computeTypeContainer.append(label);
|
||||
label.innerText = tVariant;
|
||||
tVariantContainer.append(label);
|
||||
return radioInput;
|
||||
});
|
||||
|
||||
@@ -88,16 +88,16 @@ export function renderDemoPane(demoPane: DemoPane): void {
|
||||
|
||||
radioInputs.forEach((radioInput: HTMLElement) => {
|
||||
radioInput.addEventListener("input", (event: Event): void => {
|
||||
demoPane.computeType = (event.target as HTMLInputElement).value as ComputeType;
|
||||
demoComponent.setAttribute("computetype", demoPane.computeType);
|
||||
demoPane.tVariant = (event.target as HTMLInputElement).value as TVariant;
|
||||
demoComponent.setAttribute("tvariant", demoPane.tVariant);
|
||||
});
|
||||
});
|
||||
demoRow.append(demoComponent);
|
||||
});
|
||||
|
||||
container.append(header);
|
||||
if (demoPane.chooseComputeType) {
|
||||
container.append(computeTypeContainer);
|
||||
if (demoPane.chooseTVariant) {
|
||||
container.append(tVariantContainer);
|
||||
}
|
||||
container.append(demoRow);
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ export type WasmSubpathManipulatorKey = "set_anchor" | "set_in_handle" | "set_ou
|
||||
export const BEZIER_CURVE_TYPE = ["Linear", "Quadratic", "Cubic"] as const;
|
||||
export type BezierCurveType = typeof BEZIER_CURVE_TYPE[number];
|
||||
|
||||
export type ComputeType = "Euclidean" | "Parametric";
|
||||
export type TVariant = "Euclidean" | "Parametric";
|
||||
|
||||
export type BezierCallback = (bezier: WasmBezierInstance, options: Record<string, number>, mouseLocation?: [number, number], computeType?: ComputeType) => string;
|
||||
export type SubpathCallback = (subpath: WasmSubpathInstance, options: Record<string, number>, mouseLocation?: [number, number], computeType?: ComputeType) => string;
|
||||
export type BezierCallback = (bezier: WasmBezierInstance, options: Record<string, number>, mouseLocation?: [number, number], tVariant?: TVariant) => string;
|
||||
export type SubpathCallback = (subpath: WasmSubpathInstance, options: Record<string, number>, mouseLocation?: [number, number], tVariant?: TVariant) => string;
|
||||
|
||||
export type BezierDemoOptions = {
|
||||
[key in BezierCurveType]: {
|
||||
@@ -85,7 +85,7 @@ export interface DemoPane extends HTMLElement {
|
||||
name: string;
|
||||
demos: DemoArgs[];
|
||||
id: string;
|
||||
chooseComputeType: boolean;
|
||||
computeType: ComputeType;
|
||||
chooseTVariant: boolean;
|
||||
tVariant: TVariant;
|
||||
buildDemo(demo: DemoArgs): Demo;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user