Repository navigation
Commit 3392c91
authored
Part of flutter#187894
Improve `box_decoration.dart`
In Flutter’s codebase that pattern already exists in similar hit-test
code (RenderClipOval.hitTest
https://github.com/flutter/flutter/blob/8c17c5e0677a5c923a9f606d8963e2e0350e6ec2/packages/flutter/lib/src/rendering/proxy_box.dart#L1932).
Old code:
```dart
final double distance = (position - center).distance;
return distance <= math.min(size.width, size.height) / 2.0;
```
Offset.distance computes: `sqrt(dx * dx + dy * dy)`
---
New code:
```dart
final double radius = math.min(size.width, size.height) / 2.0;
return (position - center).distanceSquared <= radius * radius;
```
Offset.distanceSquared computes only: `dx * dx + dy * dy`
Then it compares that to radius * radius.
Mathematically: `sqrt(dx² + dy²) <= r` is equivalent to: `dx² + dy² <=
r²`
Then, I also found an issue: `elevated` shadow path doesn't need to be
initialized when there is no elevation to use it for.
1 parent 9d98366 commit 3392c91
4 files changed
Lines changed: 33 additions & 3 deletions
File tree
- packages/flutter
- lib/src
- painting
- rendering
- test
- painting
- rendering
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
388 | | - | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
389 | 390 | | |
390 | 391 | | |
391 | 392 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2210 | 2210 | | |
2211 | 2211 | | |
2212 | 2212 | | |
2213 | | - | |
2214 | 2213 | | |
2215 | 2214 | | |
2216 | 2215 | | |
| |||
2230 | 2229 | | |
2231 | 2230 | | |
2232 | 2231 | | |
| 2232 | + | |
2233 | 2233 | | |
2234 | 2234 | | |
2235 | 2235 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
177 | 187 | | |
178 | 188 | | |
179 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
81 | 100 | | |
82 | 101 | | |
83 | 102 | | |
| |||
0 commit comments