From bf01cea7274d9ac8ae13fd447c8568c95da31614 Mon Sep 17 00:00:00 2001 From: Fox Caminiti Date: Tue, 25 Oct 2022 23:47:17 -0400 Subject: graph development --- bezier.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'bezier.cpp') diff --git a/bezier.cpp b/bezier.cpp index e5f9bf9..42ed04d 100644 --- a/bezier.cpp +++ b/bezier.cpp @@ -1,3 +1,39 @@ +static real32 Tau = 0.9; // tension + +static real32 +Bezier_SolveYForX(v2 Point_P0, v2 Point_P1, v2 Point_P2, v2 Point_P3, real32 TargetX) { + + real32 Y = 0; + + v2 m1 = (Point_P2 - Point_P0) / (2 * Tau); + v2 m2 = (Point_P3 - Point_P1) / (2 * Tau); + + real32 Precision = 0.001; + real32 t = (TargetX - Point_P0.x) / (Point_P3.x - Point_P0.x); + + for (;;) { + real32 t2 = t * t; + real32 t3 = t2 * t; + real32 mt = 1-t; + real32 mt2 = mt * mt; + real32 mt3 = mt2 * mt; + v2 Point = (Point_P0 * mt3) + (3 * Point_P1 * mt2 * t) + (3 * Point_P2 * mt * t2) + (Point_P3 * t3); + + bool32 Cond1 = (Point.x <= (TargetX - Precision)); + bool32 Cond2 = (Point.x >= (TargetX + Precision)); + + if (Cond1 || Cond2) { + t = t * TargetX / Point.x; + } else { + Y = Point.y; + break; + } + } + + return Y; +} + +#if 0 // A modified version of the bezier code in ImGui with extra features for bitmap and path interaction. // Function to convert a ratio back into a point for the bezier handles. @@ -307,3 +343,4 @@ void Mask_TriangulateAndRasterize(memory *Memory, project_layer *Layer, mask *Ma GL_RasterizeShape(Layer, Mask); } +#endif -- cgit v1.2.3