Skip to content

Commit 0ed6d4c

Browse files
bderodnfield
authored andcommitted
Fix Path::GetBoundingBox crash for cubics with no local min/max (flutter#126)
1 parent 533b86d commit 0ed6d4c

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

impeller/geometry/geometry_unittests.cc

+11
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ TEST(GeometryTest, BoundingBoxOfCompositePathIsCorrect) {
315315
ASSERT_RECT_NEAR(actual.value(), expected);
316316
}
317317

318+
TEST(GeometryTest, PathGetBoundingBoxForCubicWithNoDerivativeRootsIsCorrect) {
319+
PathBuilder builder;
320+
// Straight diagonal line.
321+
builder.AddCubicCurve({0, 1}, {2, 3}, {4, 5}, {6, 7});
322+
auto path = builder.TakePath();
323+
auto actual = path.GetBoundingBox();
324+
auto expected = Rect::MakeLTRB(0, 1, 6, 7);
325+
ASSERT_TRUE(actual.has_value());
326+
ASSERT_RECT_NEAR(actual.value(), expected);
327+
}
328+
318329
TEST(GeometryTest, CanGenerateMipCounts) {
319330
ASSERT_EQ((Size{128, 128}.MipCount()), 7u);
320331
ASSERT_EQ((Size{128, 256}.MipCount()), 8u);

impeller/geometry/path.cc

+4
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,10 @@ std::optional<std::pair<Point, Point>> Path::GetMinMaxCoveragePoints() const {
322322
clamp(cubic.Extrema());
323323
}
324324

325+
if (!min.has_value() || !max.has_value()) {
326+
return std::nullopt;
327+
}
328+
325329
return std::make_pair(min.value(), max.value());
326330
}
327331

impeller/geometry/path_component.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ std::vector<Point> CubicPathComponent::Extrema() const {
408408
CubicPathBoundingPopulateValues(values, p1.x, cp1.x, cp2.x, p2.x);
409409
CubicPathBoundingPopulateValues(values, p1.y, cp1.y, cp2.y, p2.y);
410410

411-
std::vector<Point> points;
411+
std::vector<Point> points = {p1, p2};
412412

413413
for (const auto& value : values) {
414414
points.emplace_back(Solve(value));

0 commit comments

Comments
 (0)