Repository navigation
Commit e6aa89e
authored
Tolerate floating-point rounding in paintImage centerSlice assertion (flutter#185789)
## Summary
`paintImage` uses a strict `==` comparison between `sourceSize` and
`inputSize` to verify that the chosen `BoxFit` does not drop image
pixels when `centerSlice` is set. The check has two failure modes that
aren't actually bugs in the caller:
1. When the image's pixel dimensions are not evenly divisible by
`scale`, the `inputSize / scale * scale` round trip lands a few ULPs
away from the original `inputSize`. The assertion fires under strict
equality even though the math is correct.
2. When the destination rect is too small to fit the `centerSlice`
borders, `outputSize` becomes non-positive and `applyBoxFit`
short-circuits to `Size.zero`. The assertion then compares `(0,0)`
against the inner-input size and fires for a reason unrelated to what it
is meant to catch (this is the configuration in the linked issue's
repro).
This change:
- Compares with `precisionErrorTolerance` instead of `==`, absorbing the
FP rounding.
- Skips the assertion entirely when the centerSlice borders can't fit
the destination rect (so the assertion no longer fires for the
degenerate case it wasn't designed to police).
The original safety check — that the chosen `BoxFit` didn't shrink the
source — is preserved for the cases it was meant to catch.
## Test plan
- [x] Added `centerSlice tolerates floating-point rounding when scale
divides unevenly` — exercises the FP-tolerance path with a destination
rect large enough to enclose the borders.
- [x] Added `centerSlice does not throw when the destination rect is
smaller than the slice borders` — reproduces the exact configuration in
the linked issue (208×142 image, scale 3, 1×1 centerSlice into a 100×46
rect) which previously failed the assertion.
- [x] `flutter test
packages/flutter/test/painting/paint_image_test.dart` — all tests pass.
- [x] `flutter test packages/flutter/test/painting/decoration_test.dart
packages/flutter/test/rendering/image_test.dart` — pass.
- [x] `flutter analyze` — no issues on the changed files.
Fixes flutter#278271 parent 6f1ed6c commit e6aa89e
2 files changed
Lines changed: 60 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
553 | 553 | | |
554 | 554 | | |
555 | 555 | | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
556 | 561 | | |
557 | 562 | | |
558 | 563 | | |
559 | 564 | | |
| 565 | + | |
560 | 566 | | |
561 | 567 | | |
562 | 568 | | |
| |||
567 | 573 | | |
568 | 574 | | |
569 | 575 | | |
570 | | - | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
571 | 580 | | |
572 | | - | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
573 | 584 | | |
574 | 585 | | |
575 | 586 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
183 | 230 | | |
184 | 231 | | |
185 | 232 | | |
| |||
0 commit comments