Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

[Impeller] Fix path winding when bridging from contours with an odd number of points. #51218

Merged
merged 1 commit into from
Mar 6, 2024
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
48 changes: 34 additions & 14 deletions impeller/aiks/aiks_path_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,40 @@ TEST_P(AiksTest, CanRenderOverlappingMultiContourPath) {

const Scalar kTriangleHeight = 100;
canvas.Translate(Vector2(200, 200));
// Form a path similar to the Material drop slider value indicator.
auto path =
PathBuilder{}
.MoveTo({0, kTriangleHeight})
.LineTo({-kTriangleHeight / 2.0f, 0})
.LineTo({kTriangleHeight / 2.0f, 0})
.Close()
.AddRoundedRect(
Rect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f,
kTriangleHeight, kTriangleHeight),
radii)
.TakePath();

canvas.DrawPath(path, paint);
// Form a path similar to the Material drop slider value indicator. Both
// shapes should render identically side-by-side.
{
auto path =
PathBuilder{}
.MoveTo({0, kTriangleHeight})
.LineTo({-kTriangleHeight / 2.0f, 0})
.LineTo({kTriangleHeight / 2.0f, 0})
.Close()
.AddRoundedRect(
Rect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f,
kTriangleHeight, kTriangleHeight),
radii)
.TakePath();

canvas.DrawPath(path, paint);
}
canvas.Translate(Vector2(100, 0));
{
auto path =
PathBuilder{}
.MoveTo({0, kTriangleHeight})
.LineTo({-kTriangleHeight / 2.0f, 0})
.LineTo({0, -10})
.LineTo({kTriangleHeight / 2.0f, 0})
.Close()
.AddRoundedRect(
Rect::MakeXYWH(-kTriangleHeight / 2.0f, -kTriangleHeight / 2.0f,
kTriangleHeight, kTriangleHeight),
radii)
.TakePath();

canvas.DrawPath(path, paint);
}

ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture()));
}
Expand Down
8 changes: 4 additions & 4 deletions impeller/tessellator/tessellator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ std::vector<Point> Tessellator::TessellateConvex(const Path& path,

size_t a = start + 1;
size_t b = end - 1;
while (a < b) {
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.
output.emplace_back(polyline.GetPoint(a));
output.emplace_back(polyline.GetPoint(b));
a++;
b--;
}
if (a == b) {
output.emplace_back(polyline.GetPoint(a));
}
}
return output;
}
Expand Down
8 changes: 4 additions & 4 deletions impeller/tessellator/tessellator_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ TEST(TessellatorTest, TessellateConvex) {
PathBuilder{}.AddRect(Rect::MakeLTRB(0, 0, 10, 10)).TakePath(), 1.0);

std::vector<Point> expected = {
{0, 0}, {10, 0}, {0, 10}, {10, 10}, //
{0, 0}, {10, 0}, {0, 10}, {10, 10}, {10, 10}, //
};
EXPECT_EQ(pts, expected);
}
Expand All @@ -125,9 +125,9 @@ TEST(TessellatorTest, TessellateConvex) {
.TakePath(),
1.0);

std::vector<Point> expected = {{0, 0}, {10, 0}, {0, 10}, {10, 10},
{10, 10}, {20, 20}, {20, 20}, {20, 20},
{30, 20}, {20, 30}, {30, 30}};
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}};
EXPECT_EQ(pts, expected);
}
}
Expand Down