Unify scale param for path and path component computation. (flutter/engine#40047)

[Impeller] Unify scale param for path and path component computation.
This commit is contained in:
luckysmg 2023-03-04 16:07:17 +08:00 committed by GitHub
parent 9ae49c0373
commit a7286607cc
4 changed files with 12 additions and 15 deletions

View File

@ -1580,7 +1580,7 @@ TEST(GeometryTest, RectGetPositive) {
TEST(GeometryTest, CubicPathComponentPolylineDoesNotIncludePointOne) {
CubicPathComponent component({10, 10}, {20, 35}, {35, 20}, {40, 40});
auto polyline = component.CreatePolyline();
auto polyline = component.CreatePolyline(1.0f);
ASSERT_NE(polyline.front().x, 10);
ASSERT_NE(polyline.front().y, 10);
ASSERT_EQ(polyline.back().x, 40);

View File

@ -224,7 +224,6 @@ bool Path::UpdateContourComponentAtIndex(size_t index,
Path::Polyline Path::CreatePolyline(Scalar scale) const {
Polyline polyline;
auto tolerance = kDefaultCurveTolerance / scale;
std::optional<Point> previous_contour_point;
auto collect_points = [&polyline, &previous_contour_point](
@ -287,11 +286,11 @@ Path::Polyline Path::CreatePolyline(Scalar scale) const {
previous_path_component = &linears_[component.index];
break;
case ComponentType::kQuadratic:
collect_points(quads_[component.index].CreatePolyline(tolerance));
collect_points(quads_[component.index].CreatePolyline(scale));
previous_path_component = &quads_[component.index];
break;
case ComponentType::kCubic:
collect_points(cubics_[component.index].CreatePolyline(tolerance));
collect_points(cubics_[component.index].CreatePolyline(scale));
previous_path_component = &cubics_[component.index];
break;
case ComponentType::kContour:

View File

@ -96,15 +96,15 @@ static Scalar ApproximateParabolaIntegral(Scalar x) {
return x / (1.0 - d + sqrt(sqrt(pow(d, 4) + 0.25 * x * x)));
}
std::vector<Point> QuadraticPathComponent::CreatePolyline(
Scalar tolerance) const {
std::vector<Point> QuadraticPathComponent::CreatePolyline(Scalar scale) const {
std::vector<Point> points;
FillPointsForPolyline(points, tolerance);
FillPointsForPolyline(points, scale);
return points;
}
void QuadraticPathComponent::FillPointsForPolyline(std::vector<Point>& points,
Scalar tolerance) const {
Scalar scale_factor) const {
auto tolerance = kDefaultCurveTolerance / scale_factor;
auto sqrt_tolerance = sqrt(tolerance);
auto d01 = cp - p1;
@ -171,11 +171,11 @@ Point CubicPathComponent::SolveDerivative(Scalar time) const {
};
}
std::vector<Point> CubicPathComponent::CreatePolyline(Scalar tolerance) const {
std::vector<Point> CubicPathComponent::CreatePolyline(Scalar scale) const {
auto quads = ToQuadraticPathComponents(.1);
std::vector<Point> points;
for (const auto& quad : quads) {
quad.FillPointsForPolyline(points, tolerance);
quad.FillPointsForPolyline(points, scale);
}
return points;
}

View File

@ -76,11 +76,10 @@ struct QuadraticPathComponent : public PathComponent {
// making it trivially parallelizable.
//
// See also the implementation in kurbo: https://github.com/linebender/kurbo.
std::vector<Point> CreatePolyline(
Scalar tolerance = kDefaultCurveTolerance) const;
std::vector<Point> CreatePolyline(Scalar scale) const;
void FillPointsForPolyline(std::vector<Point>& points,
Scalar tolerance = kDefaultCurveTolerance) const;
Scalar scale_factor) const;
std::vector<Point> Extrema() const;
@ -118,8 +117,7 @@ struct CubicPathComponent : public PathComponent {
// generates a polyline from those quadratics.
//
// See the note on QuadraticPathComponent::CreatePolyline for references.
std::vector<Point> CreatePolyline(
Scalar tolerance = kDefaultCurveTolerance) const;
std::vector<Point> CreatePolyline(Scalar scale) const;
std::vector<Point> Extrema() const;