Skip to content

Commit 3cff1a9

Browse files
bderodnfield
authored andcommitted
Remove duplicate points between connected components when generating polylines (#34)
1 parent df2485c commit 3cff1a9

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

impeller/geometry/geometry_unittests.cc

+19
Original file line numberDiff line numberDiff line change
@@ -636,5 +636,24 @@ TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
636636
ASSERT_EQ(polyline.back().y, 40);
637637
}
638638

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+
639658
} // namespace testing
640659
} // namespace impeller

impeller/geometry/path.cc

+13-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,18 @@ bool Path::UpdateMoveComponentAtIndex(size_t index,
197197
Path::Polyline Path::CreatePolyline(
198198
const SmoothingApproximation& approximation) const {
199199
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(),
200+
// TODO(99177): Refactor this to have component polyline creation always
201+
// exclude the first point, and append the destination point for
202+
// 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,
203212
collection.end());
204213
};
205214
for (const auto& component : components_) {
@@ -215,6 +224,7 @@ Path::Polyline Path::CreatePolyline(
215224
break;
216225
case ComponentType::kMove:
217226
polyline.breaks.insert(polyline.points.size());
227+
new_contour = true;
218228
break;
219229
}
220230
}

0 commit comments

Comments
 (0)