Skip to content

Commit 1ca2e0b

Browse files
authored
Fix CastError in StadiumBorder.lerpTo and StadiumBorder.lerpFrom when using BorderRadiusDirectional (#114826)
* Fix casting in StadiumBorder lerp * Add tests * Fix made-up names
1 parent 585d445 commit 1ca2e0b

File tree

3 files changed

+259
-79
lines changed

3 files changed

+259
-79
lines changed

packages/flutter/lib/src/painting/rounded_rectangle_border.dart

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class RoundedRectangleBorder extends OutlinedBorder {
5757
return _RoundedRectangleToCircleBorder(
5858
side: BorderSide.lerp(a.side, side, t),
5959
borderRadius: borderRadius,
60-
circleness: 1.0 - t,
60+
circularity: 1.0 - t,
6161
eccentricity: a.eccentricity,
6262
);
6363
}
@@ -77,7 +77,7 @@ class RoundedRectangleBorder extends OutlinedBorder {
7777
return _RoundedRectangleToCircleBorder(
7878
side: BorderSide.lerp(side, b.side, t),
7979
borderRadius: borderRadius,
80-
circleness: t,
80+
circularity: t,
8181
eccentricity: b.eccentricity,
8282
);
8383
}
@@ -163,22 +163,22 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
163163
const _RoundedRectangleToCircleBorder({
164164
super.side,
165165
this.borderRadius = BorderRadius.zero,
166-
required this.circleness,
166+
required this.circularity,
167167
required this.eccentricity,
168168
}) : assert(side != null),
169169
assert(borderRadius != null),
170-
assert(circleness != null);
170+
assert(circularity != null);
171171

172172
final BorderRadiusGeometry borderRadius;
173-
final double circleness;
173+
final double circularity;
174174
final double eccentricity;
175175

176176
@override
177177
ShapeBorder scale(double t) {
178178
return _RoundedRectangleToCircleBorder(
179179
side: side.scale(t),
180180
borderRadius: borderRadius * t,
181-
circleness: t,
181+
circularity: t,
182182
eccentricity: eccentricity,
183183
);
184184
}
@@ -190,23 +190,23 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
190190
return _RoundedRectangleToCircleBorder(
191191
side: BorderSide.lerp(a.side, side, t),
192192
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!,
193-
circleness: circleness * t,
193+
circularity: circularity * t,
194194
eccentricity: eccentricity,
195195
);
196196
}
197197
if (a is CircleBorder) {
198198
return _RoundedRectangleToCircleBorder(
199199
side: BorderSide.lerp(a.side, side, t),
200200
borderRadius: borderRadius,
201-
circleness: circleness + (1.0 - circleness) * (1.0 - t),
201+
circularity: circularity + (1.0 - circularity) * (1.0 - t),
202202
eccentricity: a.eccentricity,
203203
);
204204
}
205205
if (a is _RoundedRectangleToCircleBorder) {
206206
return _RoundedRectangleToCircleBorder(
207207
side: BorderSide.lerp(a.side, side, t),
208208
borderRadius: BorderRadiusGeometry.lerp(a.borderRadius, borderRadius, t)!,
209-
circleness: ui.lerpDouble(a.circleness, circleness, t)!,
209+
circularity: ui.lerpDouble(a.circularity, circularity, t)!,
210210
eccentricity: eccentricity,
211211
);
212212
}
@@ -219,36 +219,36 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
219219
return _RoundedRectangleToCircleBorder(
220220
side: BorderSide.lerp(side, b.side, t),
221221
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!,
222-
circleness: circleness * (1.0 - t),
222+
circularity: circularity * (1.0 - t),
223223
eccentricity: eccentricity,
224224
);
225225
}
226226
if (b is CircleBorder) {
227227
return _RoundedRectangleToCircleBorder(
228228
side: BorderSide.lerp(side, b.side, t),
229229
borderRadius: borderRadius,
230-
circleness: circleness + (1.0 - circleness) * t,
230+
circularity: circularity + (1.0 - circularity) * t,
231231
eccentricity: b.eccentricity,
232232
);
233233
}
234234
if (b is _RoundedRectangleToCircleBorder) {
235235
return _RoundedRectangleToCircleBorder(
236236
side: BorderSide.lerp(side, b.side, t),
237237
borderRadius: BorderRadiusGeometry.lerp(borderRadius, b.borderRadius, t)!,
238-
circleness: ui.lerpDouble(circleness, b.circleness, t)!,
238+
circularity: ui.lerpDouble(circularity, b.circularity, t)!,
239239
eccentricity: eccentricity,
240240
);
241241
}
242242
return super.lerpTo(b, t);
243243
}
244244

245245
Rect _adjustRect(Rect rect) {
246-
if (circleness == 0.0 || rect.width == rect.height) {
246+
if (circularity == 0.0 || rect.width == rect.height) {
247247
return rect;
248248
}
249249
if (rect.width < rect.height) {
250250
final double partialDelta = (rect.height - rect.width) / 2;
251-
final double delta = circleness * partialDelta * (1.0 - eccentricity);
251+
final double delta = circularity * partialDelta * (1.0 - eccentricity);
252252
return Rect.fromLTRB(
253253
rect.left,
254254
rect.top + delta,
@@ -257,7 +257,7 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
257257
);
258258
} else {
259259
final double partialDelta = (rect.width - rect.height) / 2;
260-
final double delta = circleness * partialDelta * (1.0 - eccentricity);
260+
final double delta = circularity * partialDelta * (1.0 - eccentricity);
261261
return Rect.fromLTRB(
262262
rect.left + delta,
263263
rect.top,
@@ -269,25 +269,25 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
269269

270270
BorderRadius? _adjustBorderRadius(Rect rect, TextDirection? textDirection) {
271271
final BorderRadius resolvedRadius = borderRadius.resolve(textDirection);
272-
if (circleness == 0.0) {
272+
if (circularity == 0.0) {
273273
return resolvedRadius;
274274
}
275275
if (eccentricity != 0.0) {
276276
if (rect.width < rect.height) {
277277
return BorderRadius.lerp(
278278
resolvedRadius,
279279
BorderRadius.all(Radius.elliptical(rect.width / 2, (0.5 + eccentricity / 2) * rect.height / 2)),
280-
circleness,
280+
circularity,
281281
)!;
282282
} else {
283283
return BorderRadius.lerp(
284284
resolvedRadius,
285285
BorderRadius.all(Radius.elliptical((0.5 + eccentricity / 2) * rect.width / 2, rect.height / 2)),
286-
circleness,
286+
circularity,
287287
)!;
288288
}
289289
}
290-
return BorderRadius.lerp(resolvedRadius, BorderRadius.circular(rect.shortestSide / 2), circleness);
290+
return BorderRadius.lerp(resolvedRadius, BorderRadius.circular(rect.shortestSide / 2), circularity);
291291
}
292292

293293
@override
@@ -318,11 +318,11 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
318318
bool get preferPaintInterior => true;
319319

320320
@override
321-
_RoundedRectangleToCircleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius, double? circleness, double? eccentricity }) {
321+
_RoundedRectangleToCircleBorder copyWith({ BorderSide? side, BorderRadiusGeometry? borderRadius, double? circularity, double? eccentricity }) {
322322
return _RoundedRectangleToCircleBorder(
323323
side: side ?? this.side,
324324
borderRadius: borderRadius ?? this.borderRadius,
325-
circleness: circleness ?? this.circleness,
325+
circularity: circularity ?? this.circularity,
326326
eccentricity: eccentricity ?? this.eccentricity,
327327
);
328328
}
@@ -347,17 +347,17 @@ class _RoundedRectangleToCircleBorder extends OutlinedBorder {
347347
return other is _RoundedRectangleToCircleBorder
348348
&& other.side == side
349349
&& other.borderRadius == borderRadius
350-
&& other.circleness == circleness;
350+
&& other.circularity == circularity;
351351
}
352352

353353
@override
354-
int get hashCode => Object.hash(side, borderRadius, circleness);
354+
int get hashCode => Object.hash(side, borderRadius, circularity);
355355

356356
@override
357357
String toString() {
358358
if (eccentricity != 0.0) {
359-
return 'RoundedRectangleBorder($side, $borderRadius, ${(circleness * 100).toStringAsFixed(1)}% of the way to being a CircleBorder that is ${(eccentricity * 100).toStringAsFixed(1)}% oval)';
359+
return 'RoundedRectangleBorder($side, $borderRadius, ${(circularity * 100).toStringAsFixed(1)}% of the way to being a CircleBorder that is ${(eccentricity * 100).toStringAsFixed(1)}% oval)';
360360
}
361-
return 'RoundedRectangleBorder($side, $borderRadius, ${(circleness * 100).toStringAsFixed(1)}% of the way to being a CircleBorder)';
361+
return 'RoundedRectangleBorder($side, $borderRadius, ${(circularity * 100).toStringAsFixed(1)}% of the way to being a CircleBorder)';
362362
}
363363
}

0 commit comments

Comments
 (0)