From 5b84b2c85b503bb67aa37c8c5322544ecae0e58d Mon Sep 17 00:00:00 2001 From: Brandon DeRosier Date: Thu, 23 May 2024 06:47:36 -0700 Subject: [PATCH] [Impeller] Fix stroke curves. (flutter/engine#52978) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves https://github.com/flutter/flutter/issues/147139. Added an explanation inline for why we need to use different direction values depending on whether or not we're capping off the last component of the contour. Before: Screenshot 2024-05-21 at 11 18 51 PM Screenshot 2024-05-21 at 11 19 35 PM After: Screenshot 2024-05-21 at 11 17 25 PM Screenshot 2024-05-21 at 11 16 38 PM --- .../impeller/entity/geometry/stroke_path_geometry.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc b/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc index cc7a3da53ed..3ccf294cbb3 100644 --- a/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc +++ b/engine/src/flutter/impeller/entity/geometry/stroke_path_geometry.cc @@ -232,9 +232,17 @@ class StrokeGenerator { // For curve components, the polyline is detailed enough such that // it can avoid worrying about joins altogether. if (is_end_of_component) { - vtx.position = polyline.GetPoint(point_i + 1) + offset; + // Append two additional vertices to close off the component. If we're + // on the _last_ component of the contour then we need to use the + // contour's end direction. + // `ComputeOffset` returns the contour's end direction when attempting + // to grab offsets past `contour_end_point_i`, so just use `offset` when + // we're on the last component. + Point last_component_offset = + is_last_component ? offset : previous_offset; + vtx.position = polyline.GetPoint(point_i + 1) + last_component_offset; vtx_builder.AppendVertex(vtx.position); - vtx.position = polyline.GetPoint(point_i + 1) - offset; + vtx.position = polyline.GetPoint(point_i + 1) - last_component_offset; vtx_builder.AppendVertex(vtx.position); // Generate join from the current line to the next line. if (!is_last_component) {