Skip to content

Commit

Permalink
[ProgressIndicator] Updated the smoothness of the cubic bezier curve …
Browse files Browse the repository at this point in the history
…to make the wave more smooth.

PiperOrigin-RevId: 650879477
  • Loading branch information
pekingme authored and paulfthomas committed Jul 10, 2024
1 parent 2799892 commit f641cd0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private void createWavyPath(

private void appendCubicPerHalfCycle(
@NonNull Path outPath, @NonNull PathPoint anchor1, @NonNull PathPoint anchor2) {
float controlLength = adjustedWavelength / 2 * SINE_WAVE_FORM_SMOOTHNESS;
float controlLength = adjustedWavelength / 2 * WAVE_SMOOTHNESS;
PathPoint control1 = new PathPoint(anchor1);
PathPoint control2 = new PathPoint(anchor2);
control1.moveAlong(controlLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

/** A delegate abstract class for drawing the graphics in different drawable classes. */
abstract class DrawingDelegate<S extends BaseProgressIndicatorSpec> {
// The length of the control handles of the cubic bezier curve simulating y = A cos(PI*x),
// where 0 <= x <= 1 (half cycle).
static final float SINE_WAVE_FORM_SMOOTHNESS = 0.364f;
// The length of the control handles of the cubic bezier curve simulating half cycle (from peak to
// trough) with wavelength = 2.
static final float WAVE_SMOOTHNESS = 0.48f;

S spec;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void invalidateCachedPaths() {
if (spec.hasWavyEffect()) {
int cycleCount = (int) (trackLength / spec.wavelength);
adjustedWavelength = trackLength / cycleCount;
float smoothness = SINE_WAVE_FORM_SMOOTHNESS;
float smoothness = WAVE_SMOOTHNESS;
for (int i = 0; i <= cycleCount; i++) {
cachedActivePath.cubicTo(2 * i + smoothness, 0, 2 * i + 1 - smoothness, 1, 2 * i + 1, 1);
cachedActivePath.cubicTo(
Expand Down

0 comments on commit f641cd0

Please sign in to comment.