mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 14:58:12 +08:00
Implement bezier local_extrema function (#693)
* Implement backend of extrema in bezier-rs * Added extrema frontend * Added extrema interface * Wrapped extrema in filter function to remove points not on the curve * Saved intermediate results while computing extrema * Fixed extrema bug when a in cubic formula is 0 * Removed extra prints * Fixed quadratic extrema regression * Moved helper functions to utils file * Fixed bug in solve linear * Stylistic changes per review * Sentence comments Co-authored-by: Linda Zheng <thelindazheng@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Linda Zheng
Keavon Chambers
parent
4775a23c17
commit
0ad6e41a59
@@ -228,7 +228,7 @@ export default defineComponent({
|
||||
},
|
||||
{
|
||||
name: "Project",
|
||||
callback: (canvas: HTMLCanvasElement, bezier: WasmBezierInstance, options: Record<string, number>, mouseLocation: Point | null): void => {
|
||||
callback: (canvas: HTMLCanvasElement, bezier: WasmBezierInstance, options: Record<string, number>, mouseLocation?: Point): void => {
|
||||
if (mouseLocation != null) {
|
||||
const context = getContextFromCanvas(canvas);
|
||||
const closestPoint = JSON.parse(bezier.project(mouseLocation.x, mouseLocation.y));
|
||||
@@ -236,6 +236,20 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Local Extrema",
|
||||
callback: (canvas: HTMLCanvasElement, bezier: WasmBezierInstance): void => {
|
||||
const context = getContextFromCanvas(canvas);
|
||||
const dimensionColors = [COLORS.NON_INTERACTIVE.STROKE_1, COLORS.NON_INTERACTIVE.STROKE_2];
|
||||
const extrema: number[][] = JSON.parse(bezier.local_extrema());
|
||||
extrema.forEach((tValues, index) => {
|
||||
tValues.forEach((t) => {
|
||||
const point = JSON.parse(bezier.compute(t));
|
||||
drawPoint(context, point, 4, dimensionColors[index]);
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user