Unverified Commit 1bfba756 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Added identical(a,b) short circuit to rendering library lerp methods (#121566)

Added identical(a,b) short circuit to rendering library lerp methods
parent c4ef0723
......@@ -468,8 +468,8 @@ class BoxConstraints extends Constraints {
///
/// {@macro dart.ui.shadow.lerp}
static BoxConstraints? lerp(BoxConstraints? a, BoxConstraints? b, double t) {
if (a == null && b == null) {
return null;
if (identical(a, b)) {
return a;
}
if (a == null) {
return b! * t;
......
......@@ -165,8 +165,8 @@ class RelativeRect {
///
/// {@macro dart.ui.shadow.lerp}
static RelativeRect? lerp(RelativeRect? a, RelativeRect? b, double t) {
if (a == null && b == null) {
return null;
if (identical(a, b)) {
return a;
}
if (a == null) {
return RelativeRect.fromLTRB(b!.left * t, b.top * t, b.right * t, b.bottom * t);
......
......@@ -153,8 +153,8 @@ class TableBorder {
///
/// {@macro dart.ui.shadow.lerp}
static TableBorder? lerp(TableBorder? a, TableBorder? b, double t) {
if (a == null && b == null) {
return null;
if (identical(a, b)) {
return a;
}
if (a == null) {
return b!.scale(t);
......
......@@ -90,6 +90,12 @@ void main() {
expect(copy.maxHeight, moreOrLessEquals(97.0));
});
test('BoxConstraints.lerp identical a,b', () {
expect(BoxConstraints.lerp(null, null, 0), null);
const BoxConstraints constraints = BoxConstraints();
expect(identical(BoxConstraints.lerp(constraints, constraints, 0.5), constraints), true);
});
test('BoxConstraints lerp with unbounded width', () {
const BoxConstraints constraints1 = BoxConstraints(
minWidth: double.infinity,
......
......@@ -67,4 +67,9 @@ void main() {
final RelativeRect r3 = RelativeRect.lerp(r1, r2, 0.5)!;
expect(r3, const RelativeRect.fromLTRB(5.0, 10.0, 15.0, 20.0));
});
test('RelativeRect.lerp identical a,b', () {
expect(RelativeRect.lerp(null, null, 0), null);
const RelativeRect rect = RelativeRect.fill;
expect(identical(RelativeRect.lerp(rect, rect, 0.5), rect), true);
});
}
......@@ -108,6 +108,12 @@ void main() {
);
});
test('TableBorder.lerp identical a,b', () {
expect(TableBorder.lerp(null, null, 0), null);
const TableBorder border = TableBorder();
expect(identical(TableBorder.lerp(border, border, 0.5), border), true);
});
test('TableBorder.lerp with nulls', () {
final TableBorder table2 = TableBorder.all(width: 2.0);
final TableBorder table1 = TableBorder.all();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment