Commit 69fcc408 authored by Hixie's avatar Hixie

Clean up animation-related files.

Surface all the constructor arguments of AnimationTiming in all its subclasses.
Remove some pointless casts.
Fix some typos.
Put constructors first in class declarations.
Remove some blank lines where they just confused the structure of the code.
parent 942d1fa6
......@@ -77,8 +77,8 @@ class AnimationTiming {
/// An animated variable with a concrete type
class AnimatedValue<T extends dynamic> extends AnimationTiming implements AnimatedVariable {
AnimatedValue(this.begin, { this.end, Interval interval, Curve curve, Curve reverseCurve })
: super(interval: interval, curve: curve, reverseCurve: reverseCurve) {
AnimatedValue(this.begin, { this.end, Interval interval, Interval reverseInterval, Curve curve, Curve reverseCurve })
: super(interval: interval, reverseInterval: reverseInterval, curve: curve, reverseCurve: reverseCurve) {
value = begin;
}
......@@ -110,8 +110,8 @@ class AnimatedList extends AnimationTiming implements AnimatedVariable {
/// The list of variables contained in the list
List<AnimatedVariable> variables;
AnimatedList(this.variables, { Interval interval, Curve curve, Curve reverseCurve })
: super(interval: interval, curve: curve, reverseCurve: reverseCurve);
AnimatedList(this.variables, { Interval interval, Interval reverseInterval, Curve curve, Curve reverseCurve })
: super(interval: interval, reverseInterval: reverseInterval, curve: curve, reverseCurve: reverseCurve);
// Updates the value of all the variables in the list according to the given animation clock value and direction
void setProgress(double t, Direction direction) {
......@@ -128,8 +128,8 @@ class AnimatedList extends AnimationTiming implements AnimatedVariable {
/// This class specializes the interpolation of AnimatedValue<Color> to be
/// appropriate for colors.
class AnimatedColorValue extends AnimatedValue<Color> {
AnimatedColorValue(Color begin, { Color end, Curve curve })
: super(begin, end: end, curve: curve);
AnimatedColorValue(Color begin, { Color end, Interval interval, Interval reverseInterval, Curve curve, Curve reverseCurve })
: super(begin, end: end, interval: interval, reverseInterval: reverseInterval, curve: curve, reverseCurve: reverseCurve);
Color lerp(double t) => Color.lerp(begin, end, t);
}
......@@ -139,8 +139,8 @@ class AnimatedColorValue extends AnimatedValue<Color> {
/// This class specializes the interpolation of AnimatedValue<Rect> to be
/// appropriate for rectangles.
class AnimatedRect extends AnimatedValue<Rect> {
AnimatedRect(Rect begin, { Rect end, Curve curve })
: super(begin, end: end, curve: curve);
AnimatedRect(Rect begin, { Rect end, Interval interval, Interval reverseInterval, Curve curve, Curve reverseCurve })
: super(begin, end: end, interval: interval, reverseInterval: reverseInterval, curve: curve, reverseCurve: reverseCurve);
Rect lerp(double t) => Rect.lerp(begin, end, t);
}
......@@ -32,7 +32,7 @@ enum AnimationStatus {
/// [fling] the timeline causing a physics-based simulation to take over the
/// progression.
class AnimationPerformance {
AnimationPerformance({AnimatedVariable variable, this.duration}) :
AnimationPerformance({ AnimatedVariable variable, this.duration }) :
_variable = variable {
_timeline = new Timeline(_tick);
}
......@@ -68,7 +68,8 @@ class AnimationPerformance {
if (variable == null) {
variable = newVariable;
} else if (variable is AnimatedList) {
(variable as AnimatedList).variables.add(newVariable);
final AnimatedList variable = this.variable; // TODO(ianh): Remove this line when the analyzer is cleverer
variable.variables.add(newVariable);
} else {
variable = new AnimatedList([variable, newVariable]);
}
......@@ -219,7 +220,7 @@ class AnimationPerformance {
/// An animation performance with an animated variable with a concrete type
class ValueAnimation<T> extends AnimationPerformance {
ValueAnimation({AnimatedValue<T> variable, Duration duration}) :
ValueAnimation({ AnimatedValue<T> variable, Duration duration }) :
super(variable: variable, duration: duration);
AnimatedValue<T> get variable => _variable as AnimatedValue<T>;
......
......@@ -21,23 +21,14 @@ abstract class Curve {
double transform(double t);
}
/// The idenity map over the unit interval
/// The identity map over the unit interval
class Linear implements Curve {
const Linear();
double transform(double t) {
return t;
}
double transform(double t) => t;
}
/// A curve that is initially 0.0, then linear, then 1.0
class Interval implements Curve {
/// The smallest value for which this interval is 0.0
final double start;
/// The smallest value for which this interval is 1.0
final double end;
Interval(this.start, this.end) {
assert(start >= 0.0);
assert(start <= 1.0);
......@@ -45,6 +36,12 @@ class Interval implements Curve {
assert(end <= 1.0);
}
/// The smallest value for which this interval is 0.0
final double start;
/// The smallest value for which this interval is 1.0
final double end;
double transform(double t) {
return ((t - start) / (end - start)).clamp(0.0, 1.0);
}
......@@ -52,23 +49,21 @@ class Interval implements Curve {
/// A cubic polynomial mapping of the unit interval
class Cubic implements Curve {
const Cubic(this.a, this.b, this.c, this.d);
final double a;
final double b;
final double c;
final double d;
const Cubic(this.a, this.b, this.c, this.d);
double transform(double t) {
double start = 0.0;
double end = 1.0;
while (true) {
double midpoint = (start + end) / 2;
double estimate = _evaluateCubic(a, c, midpoint);
if ((t - estimate).abs() < _kCubicErrorBound)
return _evaluateCubic(b, d, midpoint);
if (estimate < t)
start = midpoint;
else
......@@ -94,7 +89,6 @@ double _bounce(double t) {
/// An oscillating curve that grows in magnitude
class BounceInCurve implements Curve {
const BounceInCurve();
double transform(double t) {
return 1.0 - _bounce(1.0 - t);
}
......@@ -103,7 +97,6 @@ class BounceInCurve implements Curve {
/// An oscillating curve that shrink in magnitude
class BounceOutCurve implements Curve {
const BounceOutCurve();
double transform(double t) {
return _bounce(t);
}
......@@ -112,7 +105,6 @@ class BounceOutCurve implements Curve {
/// An oscillating curve that first grows and then shrink in magnitude
class BounceInOutCurve implements Curve {
const BounceInOutCurve();
double transform(double t) {
if (t < 0.5)
return (1.0 - _bounce(1.0 - t)) * 0.5;
......@@ -125,7 +117,6 @@ class BounceInOutCurve implements Curve {
class ElasticInCurve implements Curve {
const ElasticInCurve([this.period = 0.4]);
final double period;
double transform(double t) {
double s = period / 4.0;
t = t - 1.0;
......@@ -137,7 +128,6 @@ class ElasticInCurve implements Curve {
class ElasticOutCurve implements Curve {
const ElasticOutCurve([this.period = 0.4]);
final double period;
double transform(double t) {
double s = period / 4.0;
return math.pow(2.0, -10 * t) * math.sin((t - s) * (math.PI * 2.0) / period) + 1.0;
......@@ -148,7 +138,6 @@ class ElasticOutCurve implements Curve {
class ElasticInOutCurve implements Curve {
const ElasticInOutCurve([this.period = 0.4]);
final double period;
double transform(double t) {
double s = period / 4.0;
t = 2.0 * t - 1.0;
......
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