Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions impeller/tessellator/tessellator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ std::vector<Point> Tessellator::TessellateConvex(const Path& path,

output.reserve(polyline.points->size() +
(4 * (polyline.contours.size() - 1)));
bool previous_contour_odd_points = false;
for (auto j = 0u; j < polyline.contours.size(); j++) {
auto [start, end] = polyline.GetContourPointBounds(j);
auto first_point = polyline.GetPoint(start);
Expand All @@ -205,22 +206,31 @@ std::vector<Point> Tessellator::TessellateConvex(const Path& path,
output.emplace_back(output.back());
output.emplace_back(first_point);
output.emplace_back(first_point);
output.emplace_back(first_point);

// If the contour has an odd number of points, insert an extra point when
// bridging to the next contour to preserve the correct triangle winding
// order.
if (previous_contour_odd_points) {
output.emplace_back(first_point);
}
} else {
output.emplace_back(first_point);
}

size_t a = start + 1;
size_t b = end - 1;
while (a <= b) {
// If the contour has an odd number of points, two identical points will
// be appended when a == b. This ensures the triangle winding order will
// remain the same after bridging to the next contour.
while (a < b) {
output.emplace_back(polyline.GetPoint(a));
output.emplace_back(polyline.GetPoint(b));
a++;
b--;
}
if (a == b) {
previous_contour_odd_points = false;
output.emplace_back(polyline.GetPoint(a));
} else {
previous_contour_odd_points = true;
}
}
return output;
}
Expand Down
10 changes: 4 additions & 6 deletions impeller/tessellator/tessellator_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ TEST(TessellatorTest, TessellateConvex) {
auto pts = t.TessellateConvex(
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 10, 10)).TakePath(), 1.0);

std::vector<Point> expected = {
{0, 0}, {10, 0}, {0, 10}, {10, 10}, {10, 10}, //
};
std::vector<Point> expected = {{0, 0}, {10, 0}, {0, 10}, {10, 10}};
EXPECT_EQ(pts, expected);
}

Expand All @@ -125,9 +123,9 @@ TEST(TessellatorTest, TessellateConvex) {
.TakePath(),
1.0);

std::vector<Point> expected = {
{0, 0}, {10, 0}, {0, 10}, {10, 10}, {10, 10}, {10, 10}, {20, 20},
{20, 20}, {20, 20}, {30, 20}, {20, 30}, {30, 30}, {30, 30}};
std::vector<Point> expected = {{0, 0}, {10, 0}, {0, 10}, {10, 10},
{10, 10}, {20, 20}, {20, 20}, {30, 20},
{20, 30}, {30, 30}};
EXPECT_EQ(pts, expected);
}
}
Expand Down