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

[Impeller] Unify scale param for path and path component computation. #40047

Merged
merged 2 commits into from
Mar 4, 2023
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
2 changes: 1 addition & 1 deletion impeller/geometry/geometry_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions impeller/geometry/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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](
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions impeller/geometry/path_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions impeller/geometry/path_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down