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