Skip to content

Commit

Permalink
Fix Path::GetBoundingBox crash for cubics with no local min/max (flut…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdero authored and dnfield committed Apr 27, 2022
1 parent 533b86d commit 0ed6d4c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,17 @@ TEST(GeometryTest, BoundingBoxOfCompositePathIsCorrect) {
ASSERT_RECT_NEAR(actual.value(), expected);
}

TEST(GeometryTest, PathGetBoundingBoxForCubicWithNoDerivativeRootsIsCorrect) {
PathBuilder builder;
// Straight diagonal line.
builder.AddCubicCurve({0, 1}, {2, 3}, {4, 5}, {6, 7});
auto path = builder.TakePath();
auto actual = path.GetBoundingBox();
auto expected = Rect::MakeLTRB(0, 1, 6, 7);
ASSERT_TRUE(actual.has_value());
ASSERT_RECT_NEAR(actual.value(), expected);
}

TEST(GeometryTest, CanGenerateMipCounts) {
ASSERT_EQ((Size{128, 128}.MipCount()), 7u);
ASSERT_EQ((Size{128, 256}.MipCount()), 8u);
Expand Down
4 changes: 4 additions & 0 deletions impeller/geometry/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ std::optional<std::pair<Point, Point>> Path::GetMinMaxCoveragePoints() const {
clamp(cubic.Extrema());
}

if (!min.has_value() || !max.has_value()) {
return std::nullopt;
}

return std::make_pair(min.value(), max.value());
}

Expand Down
2 changes: 1 addition & 1 deletion impeller/geometry/path_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ std::vector<Point> CubicPathComponent::Extrema() const {
CubicPathBoundingPopulateValues(values, p1.x, cp1.x, cp2.x, p2.x);
CubicPathBoundingPopulateValues(values, p1.y, cp1.y, cp2.y, p2.y);

std::vector<Point> points;
std::vector<Point> points = {p1, p2};

for (const auto& value : values) {
points.emplace_back(Solve(value));
Expand Down

0 comments on commit 0ed6d4c

Please sign in to comment.