flutter / flutter/flutter

Impeller: rounded superellipse conic weight jumps at each step of the fitted table

Open
#192,190 1 comment 0 reactions 0 assignees View on GitHub
c: rendering e: impeller engine needs repro info P2 team-engine triaged-engine waiting for response
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

`impeller/geometry/round_superellipse_param.cc`, in the conic-weight lookup:

```c++
Scalar weight1 = (1.f - frac) * kPrecomputedVariables[left][0] +
frac * kPrecomputedVariables[left + 1][0] * sqrt(n);
Scalar weight2 = (1.f - frac) * kPrecomputedVariables[left][1] +
frac * kPrecomputedVariables[left + 1][1] * xJOverA;
```

`sqrt(n)` multiplies only the right-hand term of the interpolation. The comment
a few lines above says the table holds normalized weights defined as
`weight1 = factor1 * sqrt(n)`, which reads as the factor being normalized — so
the scale should apply to the interpolated factor, not to one end of it. Same
shape for `weight2` and `xJOverA`.

The effect is a sawtooth. The weight climbs across each interval and drops back
at the next table entry, twelve times over the range. Sweeping the ratio of side
to corner radius and measuring the drawn outline against the analytic
superellipse: ratio 2.700 lands within 0.005 of the true curve, 2.705 lands
0.042 away. Ninefold change in how faithful the outline is, over two tenths of a
percent of corner radius, at a place where the shape itself is continuous. A
control animating its corner radius crosses several of these.

Worth saying before anyone reaches for the one-line fix: I tried it, and pulling
`sqrt(n)` out to multiply the whole interpolation is worse everywhere — 0.056 at
its worst against 0.046, and two to five times the error past a ratio of five.
The table was fitted against the formula as written, so correcting the formula
without refitting the table moves the shape further from the curve rather than
closer.

Found porting this; my version carries the same sawtooth on purpose so the
squircle matches Flutter's, which is why I'd rather it were fixed here than
diverge.

Contributor guide

Open the contributing guide

Research direction

Start in impeller/geometry/round_superellipse_param.cc at the conic-weight lookup and read how the normalized table values are used. Reproduce the ratio sweep against the analytic superellipse, checking the sawtooth across fitted-table intervals. Done means the table or formula is refitted or corrected without worsening the stated error, while preserving a faithful continuous outline.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.