We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent df2485c commit 3cff1a9Copy full SHA for 3cff1a9
2 files changed
impeller/geometry/geometry_unittests.cc
@@ -636,5 +636,24 @@ TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
636
ASSERT_EQ(polyline.back().y, 40);
637
}
638
639
+TEST(GeometryTest, PathCreatePolyLineDoesNotDuplicatePoints) {
640
+ Path path;
641
+ path.AddMoveComponent({10, 10});
642
+ path.AddLinearComponent({10, 10}, {20, 20});
643
+ path.AddLinearComponent({20, 20}, {30, 30});
644
+ path.AddMoveComponent({40, 40});
645
+ path.AddLinearComponent({40, 40}, {50, 50});
646
+
647
+ auto polyline = path.CreatePolyline();
648
649
+ ASSERT_EQ(polyline.breaks.size(), 2u);
650
+ ASSERT_EQ(polyline.points.size(), 5u);
651
+ ASSERT_EQ(polyline.points[0].x, 10);
652
+ ASSERT_EQ(polyline.points[1].x, 20);
653
+ ASSERT_EQ(polyline.points[2].x, 30);
654
+ ASSERT_EQ(polyline.points[3].x, 40);
655
+ ASSERT_EQ(polyline.points[4].x, 50);
656
+}
657
658
} // namespace testing
659
} // namespace impeller
impeller/geometry/path.cc
@@ -197,9 +197,18 @@ bool Path::UpdateMoveComponentAtIndex(size_t index,
197
Path::Polyline Path::CreatePolyline(
198
const SmoothingApproximation& approximation) const {
199
Polyline polyline;
200
- auto collect_points = [&polyline](const std::vector<Point>& collection) {
201
- polyline.points.reserve(polyline.points.size() + collection.size());
202
- polyline.points.insert(polyline.points.end(), collection.begin(),
+ // TODO(99177): Refactor this to have component polyline creation always
+ // exclude the first point, and append the destination point for
+ // move components. See issue for details.
203
+ bool new_contour = true;
204
+ auto collect_points = [&polyline,
205
+ &new_contour](const std::vector<Point>& collection) {
206
+ size_t offset = new_contour ? 0 : 1;
207
+ new_contour = false;
208
209
+ polyline.points.reserve(polyline.points.size() + collection.size() -
210
+ offset);
211
+ polyline.points.insert(polyline.points.end(), collection.begin() + offset,
212
collection.end());
213
};
214
for (const auto& component : components_) {
@@ -215,6 +224,7 @@ Path::Polyline Path::CreatePolyline(
215
224
break;
216
225
case ComponentType::kMove:
217
226
polyline.breaks.insert(polyline.points.size());
227
+ new_contour = true;
218
228
219
229
220
230
0 commit comments