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

Commit ff75dfd

Browse files
author
jonahwilliams
committed
chinmay review.
1 parent a7288ec commit ff75dfd

File tree

2 files changed

+24
-22
lines changed

2 files changed

+24
-22
lines changed

impeller/geometry/wangs_formula.cc

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,50 +9,44 @@ namespace impeller {
99
namespace {
1010

1111
// Don't allow linearized segments to be off by more than 1/4th of a pixel from
12-
// the true curve.
12+
// the true curve. This value should be scaled by the max basis of the
13+
// X and Y directions.
1314
constexpr static Scalar kPrecision = 4;
1415

15-
static inline Scalar length(Point n) {
16+
constexpr Scalar length(Point n) {
1617
Point nn = n * n;
1718
return std::sqrt(nn.x + nn.y);
1819
}
1920

20-
static inline Point Max(Point a, Point b) {
21-
return Point{
22-
a.x > b.x ? a.x : b.x, //
23-
a.y > b.y ? a.y : b.y //
24-
};
25-
}
26-
2721
} // namespace
2822

29-
Scalar ComputeCubicSubdivisions(Scalar intolerance,
23+
Scalar ComputeCubicSubdivisions(Scalar scale_factor,
3024
Point p0,
3125
Point p1,
3226
Point p2,
3327
Point p3) {
34-
Scalar k = intolerance * .75f * kPrecision;
28+
Scalar k = scale_factor * .75f * kPrecision;
3529
Point a = (p0 - p1 * 2 + p2).Abs();
3630
Point b = (p1 - p2 * 2 + p3).Abs();
37-
return std::sqrt(k * length(Max(a, b)));
31+
return std::sqrt(k * length(a.Max(b)));
3832
}
3933

40-
Scalar ComputeQuadradicSubdivisions(Scalar intolerance,
34+
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
4135
Point p0,
4236
Point p1,
4337
Point p2) {
44-
Scalar k = intolerance * .25f * kPrecision;
38+
Scalar k = scale_factor * .25f * kPrecision;
4539
return std::sqrt(k * length(p0 - p1 * 2 + p2));
4640
}
4741

48-
Scalar ComputeQuadradicSubdivisions(Scalar intolerance,
42+
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
4943
const QuadraticPathComponent& quad) {
50-
return ComputeQuadradicSubdivisions(intolerance, quad.p1, quad.cp, quad.p2);
44+
return ComputeQuadradicSubdivisions(scale_factor, quad.p1, quad.cp, quad.p2);
5145
}
5246

53-
Scalar ComputeCubicSubdivisions(float intolerance,
47+
Scalar ComputeCubicSubdivisions(float scale_factor,
5448
const CubicPathComponent& cub) {
55-
return ComputeCubicSubdivisions(intolerance, cub.p1, cub.cp1, cub.cp2,
49+
return ComputeCubicSubdivisions(scale_factor, cub.p1, cub.cp1, cub.cp2,
5650
cub.p2);
5751
}
5852

impeller/geometry/wangs_formula.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ namespace impeller {
2727
/// Returns the minimum number of evenly spaced (in the parametric sense) line
2828
/// segments that the cubic must be chopped into in order to guarantee all lines
2929
/// stay within a distance of "1/intolerance" pixels from the true curve.
30-
Scalar ComputeCubicSubdivisions(Scalar intolerance,
30+
///
31+
/// The scale_factor should be the max basis XY of the current transform.
32+
Scalar ComputeCubicSubdivisions(Scalar scale_factor,
3133
Point p0,
3234
Point p1,
3335
Point p2,
@@ -36,21 +38,27 @@ Scalar ComputeCubicSubdivisions(Scalar intolerance,
3638
/// Returns the minimum number of evenly spaced (in the parametric sense) line
3739
/// segments that the quadratic must be chopped into in order to guarantee all
3840
/// lines stay within a distance of "1/intolerance" pixels from the true curve.
39-
Scalar ComputeQuadradicSubdivisions(Scalar intolerance,
41+
///
42+
/// The scale_factor should be the max basis XY of the current transform.
43+
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
4044
Point p0,
4145
Point p1,
4246
Point p2);
4347

4448
/// Returns the minimum number of evenly spaced (in the parametric sense) line
4549
/// segments that the quadratic must be chopped into in order to guarantee all
4650
/// lines stay within a distance of "1/intolerance" pixels from the true curve.
47-
Scalar ComputeQuadradicSubdivisions(Scalar intolerance,
51+
///
52+
/// The scale_factor should be the max basis XY of the current transform.
53+
Scalar ComputeQuadradicSubdivisions(Scalar scale_factor,
4854
const QuadraticPathComponent& quad);
4955

5056
/// Returns the minimum number of evenly spaced (in the parametric sense) line
5157
/// segments that the cubic must be chopped into in order to guarantee all lines
5258
/// stay within a distance of "1/intolerance" pixels from the true curve.
53-
Scalar ComputeCubicSubdivisions(float intolerance,
59+
///
60+
/// The scale_factor should be the max basis XY of the current transform.
61+
Scalar ComputeCubicSubdivisions(float scale_factor,
5462
const CubicPathComponent& cub);
5563
} // namespace impeller
5664

0 commit comments

Comments
 (0)