[gtk/path-stroke: 13/13] stroke: Tweak the way we do smooth joins




commit 6a792344215d4e12b532b335d39f8d7b0af5e0ec
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Dec 20 11:08:10 2020 -0500

    stroke: Tweak the way we do smooth joins
    
    Force round joins for small angles, and avoid extra
    lines for straight joins.

 gsk/gskpathstroke.c | 35 +++++++++++++++++------------------
 1 file changed, 17 insertions(+), 18 deletions(-)
---
diff --git a/gsk/gskpathstroke.c b/gsk/gskpathstroke.c
index 6225c51bf6..5d02f7e41d 100644
--- a/gsk/gskpathstroke.c
+++ b/gsk/gskpathstroke.c
@@ -315,10 +315,10 @@ cubic_curvature_points (const GskCurve *curve,
   return solve_quadratic (x, y, z, t);
 }
 
-/* Find cusps in the interior of [0,1]. According to Stone &
- * dRose, A Geometric Characterization of Parametric Cubic
- * curves, a necessary and sufficient condition is that the
- * first derivative vanishes.
+/* Find cusps inside the open interval from 0 to 1. According
+ * to Stone & dRose, A Geometric Characterization of Parametric
+ * Cubic curves, a necessary and sufficient condition is that
+ * the first derivative vanishes.
  */
 static int
 find_cusps (const GskCurve *curve,
@@ -488,15 +488,13 @@ add_line_cap (GskPathBuilder         *builder,
  * to the left and right, and collect the offset segments in
  * a left and a right contour.
  *
- * When the segment is too curvy, we subdivide it before we
- * add the pieces.
+ * When the segment is too curvy, or has cusps or inflections,
+ * we subdivide it before we add the pieces.
  *
  * Whenever we add a segment, we need to decide if the join
  * is a smooth connection, a right turn, or a left turn. For
- * the smooth connections, we just connect the end points of
- * the offset curves with line segments. For sharp turns, we
- * add a line join on the one side, and intersect the offset
- * curves on the other.
+ * sharp turns, we add a line join on the one side, and intersect
+ * the offset curves on the other.
  *
  * Since the intersection shortens both segments, we have to
  * delay adding the previous segments to the outlines until
@@ -589,6 +587,7 @@ add_segments (StrokeData     *stroke_data,
   float t1, t2;
   graphene_vec2_t tangent1, tangent2;
   graphene_point_t p;
+  GskLineJoin line_join;
 
   if (!stroke_data->has_current_curve)
     {
@@ -611,14 +610,16 @@ add_segments (StrokeData     *stroke_data,
   gsk_curve_get_start_tangent (curve, &tangent2);
   angle = angle_between (&tangent1, &tangent2);
 
-  if (fabs (angle) < DEG_TO_RAD (5))
+  if (force_round_join || fabs (angle) < DEG_TO_RAD (5))
+    line_join = GSK_LINE_JOIN_ROUND;
+  else
+    line_join = stroke_data->stroke->line_join;
+
+  if (fabs (angle) < DEG_TO_RAD (1))
     {
       /* Close enough to a straight line */
       append_right (stroke_data, &stroke_data->r);
-      path_builder_line_to_point (stroke_data->right, gsk_curve_get_start_point (r));
-
       append_left (stroke_data, &stroke_data->l);
-      path_builder_line_to_point (stroke_data->left, gsk_curve_get_start_point (l));
     }
   else if (angle > 0)
     {
@@ -643,8 +644,7 @@ add_segments (StrokeData     *stroke_data,
       append_left (stroke_data, &stroke_data->l);
 
       add_line_join (stroke_data->left,
-                     force_round_join ? GSK_LINE_JOIN_ROUND
-                                      : stroke_data->stroke->line_join,
+                     line_join,
                      stroke_data->stroke->line_width,
                      stroke_data->stroke->miter_limit,
                      gsk_curve_get_start_point (curve),
@@ -660,8 +660,7 @@ add_segments (StrokeData     *stroke_data,
       append_right (stroke_data, &stroke_data->r);
 
       add_line_join (stroke_data->right,
-                     force_round_join ? GSK_LINE_JOIN_ROUND
-                                      : stroke_data->stroke->line_join,
+                     line_join,
                      stroke_data->stroke->line_width,
                      stroke_data->stroke->miter_limit,
                      gsk_curve_get_start_point (curve),


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