[gtk/wip/otte/lottie: 7/10] spline: Use Skia's tolerance checks




commit 25392118f7da813821c572ed729e75f237aaa25c
Author: Benjamin Otte <otte redhat com>
Date:   Wed Nov 25 02:18:34 2020 +0100

    spline: Use Skia's tolerance checks
    
    This avoids measuring being too far off (it's still off, but it's less
    than a percent now.

 gsk/gskspline.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
---
diff --git a/gsk/gskspline.c b/gsk/gskspline.c
index 8c3a1cef73..fb4502c697 100644
--- a/gsk/gskspline.c
+++ b/gsk/gskspline.c
@@ -102,6 +102,7 @@ gsk_spline_split_cubic (const graphene_point_t pts[4],
     memcpy (result2, (graphene_point_t[4]) { final, bccd, cd, pts[3] }, sizeof (graphene_point_t[4]));
 }
 
+#if 0
 /* Return an upper bound on the error (squared) that could result from
  * approximating a spline as a line segment connecting the two endpoints. */
 static float
@@ -179,6 +180,27 @@ gsk_spline_error_squared (const graphene_point_t pts[4])
     else
       return cerr;
 }
+#endif
+
+/* taken from Skia, including the very descriptive name */
+static gboolean
+gsk_spline_cubic_too_curvy (const graphene_point_t pts[4],
+                            float                  tolerance)
+{
+  graphene_point_t p;
+
+  graphene_point_interpolate (&pts[0], &pts[3], 1.0f / 3, &p);
+  if (ABS (p.x - pts[1].x) > tolerance ||
+      ABS (p.y - pts[1].y) > tolerance)
+    return TRUE;
+
+  graphene_point_interpolate (&pts[0], &pts[3], 2.0f / 3, &p);
+  if (ABS (p.x - pts[2].x) > tolerance ||
+      ABS (p.y - pts[2].y) > tolerance)
+    return TRUE;
+
+  return FALSE;
+}
 
 static void
 gsk_spline_decompose_into (GskCubicDecomposition  *decomp,
@@ -187,7 +209,7 @@ gsk_spline_decompose_into (GskCubicDecomposition  *decomp,
 {
   graphene_point_t left[4], right[4];
 
-  if (gsk_spline_error_squared (pts) < decomp->tolerance_squared)
+  if (!gsk_spline_cubic_too_curvy (pts, 0.5) || progress < 1 / 1024.f)
     {
       gsk_spline_decompose_add_point (decomp, &pts[3], progress);
       return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]