From f22879f695d01d1755ad3dfbda0883e41cf63539 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 24 Feb 2022 10:34:01 -0800 Subject: [PATCH] Do not include the leading point for cubic polylines (flutter/engine#29) This avoids having duplicated points present in the polyline. --- .../flutter/impeller/geometry/geometry_unittests.cc | 11 +++++++++++ .../src/flutter/impeller/geometry/path_component.cc | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/impeller/geometry/geometry_unittests.cc b/engine/src/flutter/impeller/geometry/geometry_unittests.cc index 3c4330c4b5..fe8c772688 100644 --- a/engine/src/flutter/impeller/geometry/geometry_unittests.cc +++ b/engine/src/flutter/impeller/geometry/geometry_unittests.cc @@ -6,6 +6,7 @@ #include "flutter/testing/testing.h" #include "impeller/geometry/path.h" #include "impeller/geometry/path_builder.h" +#include "impeller/geometry/path_component.h" #include "impeller/geometry/point.h" #include "impeller/geometry/rect.h" #include "impeller/geometry/size.h" @@ -524,5 +525,15 @@ TEST(GeometryTest, RectContainsRect) { } } +TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) { + CubicPathComponent component({10, 10}, {20,35}, {35, 20}, {40, 40}); + SmoothingApproximation approximation; + auto polyline = component.CreatePolyline(approximation); + ASSERT_NE(polyline.front().x, 10); + ASSERT_NE(polyline.front().y, 10); + ASSERT_EQ(polyline.back().x, 40); + ASSERT_EQ(polyline.back().y, 40); +} + } // namespace testing } // namespace impeller diff --git a/engine/src/flutter/impeller/geometry/path_component.cc b/engine/src/flutter/impeller/geometry/path_component.cc index a4b4737d88..919a14c939 100644 --- a/engine/src/flutter/impeller/geometry/path_component.cc +++ b/engine/src/flutter/impeller/geometry/path_component.cc @@ -339,7 +339,6 @@ static void CubicPathSmoothenRecursive(const SmoothingApproximation& approx, std::vector CubicPathComponent::CreatePolyline( const SmoothingApproximation& approximation) const { std::vector points; - points.emplace_back(p1); CubicPathSmoothenRecursive(approximation, points, p1, cp1, cp2, p2, 0); points.emplace_back(p2); return points;