Fix Path::GetBoundingBox crash for cubics with no local min/max (flutter/engine#126)

This commit is contained in:
Brandon DeRosier 2022-04-08 18:01:53 -07:00 committed by Dan Field
parent f48865ec86
commit 2e41cfc501
3 changed files with 16 additions and 1 deletions

View File

@ -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);

View File

@ -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());
}

View File

@ -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));