Commit 0873f3e1 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Move maxBy into the MaterialArc file (#5905)

As per our style guide, if you can't explain something, refactor it. I
studied this function for a while and still can't explain it, so...
parent 10e4f520
......@@ -243,21 +243,3 @@ class _LazyListIterator<E> implements Iterator<E> {
return true;
}
}
// COLLECTION UTILITIES
typedef dynamic KeyFunc<T>(T input);
/// Select the element for which the key function returns the maximum value.
dynamic/*=T*/ maxBy/*<T>*/(Iterable<dynamic/*=T*/> input, KeyFunc/*<T>*/ keyFunc) {
dynamic/*=T*/ maxValue;
dynamic maxKey;
for (dynamic/*=T*/ value in input) {
dynamic key = keyFunc(value);
if (maxKey == null || key > maxKey) {
maxValue = value;
maxKey = key;
}
}
return maxValue;
}
......@@ -5,7 +5,6 @@
import 'dart:math' as math;
import 'dart:ui' show hashValues, lerpDouble;
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
......@@ -160,6 +159,22 @@ const List<_Diagonal> _allDiagonals = const <_Diagonal>[
const _Diagonal(_CornerId.bottomLeft, _CornerId.topRight),
];
typedef dynamic _KeyFunc<T>(T input);
// Select the element for which the key function returns the maximum value.
dynamic/*=T*/ _maxBy/*<T>*/(Iterable<dynamic/*=T*/> input, _KeyFunc/*<T>*/ keyFunc) {
dynamic/*=T*/ maxValue;
dynamic maxKey;
for (dynamic/*=T*/ value in input) {
dynamic key = keyFunc(value);
if (maxKey == null || key > maxKey) {
maxValue = value;
maxKey = key;
}
}
return maxValue;
}
/// A [Tween] that animates a [Rect] from [begin] to [end].
///
/// The rectangle corners whose diagonal is closest to the overall direction of
......@@ -184,7 +199,7 @@ class MaterialRectArcTween extends RectTween {
assert(begin != null);
assert(end != null);
final Offset centersVector = end.center - begin.center;
_diagonal = maxBy(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d));
_diagonal = _maxBy/*<_Diagonal>*/(_allDiagonals, (_Diagonal d) => _diagonalSupport(centersVector, d));
_beginArc = new MaterialPointArcTween(
begin: _cornerFor(begin, _diagonal.beginId),
end: _cornerFor(end, _diagonal.beginId)
......
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