summaryrefslogtreecommitdiff
path: root/bezier.cpp
diff options
context:
space:
mode:
authorFox Caminiti <fox@foxcam.net>2022-10-25 23:47:17 -0400
committerFox Caminiti <fox@foxcam.net>2022-10-25 23:47:17 -0400
commitbf01cea7274d9ac8ae13fd447c8568c95da31614 (patch)
treeed3b9fb4ae56f1e19cf3514280249954b1043070 /bezier.cpp
parent87c3fbb37141827622eeadb89189c267ed4baf87 (diff)
graph development
Diffstat (limited to 'bezier.cpp')
-rw-r--r--bezier.cpp37
1 files changed, 37 insertions, 0 deletions
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