Commit d0ad775e authored by Adam Barth's avatar Adam Barth

Remove lerp.dart

These functions are now in sky:dart.
parent 11ee06dd
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/base/lerp.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/theme/typography.dart' as typography;
import 'package:sky/widgets.dart';
......@@ -34,7 +33,7 @@ class CardCollectionApp extends App {
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
cardModels = new List.generate(cardHeights.length, (i) {
Color color = lerpColor(colors.Red[300], colors.Blue[900], i / cardHeights.length);
Color color = Color.lerp(colors.Red[300], colors.Blue[900], i / cardHeights.length);
return new CardModel(i, cardHeights[i], color);
});
super.initState();
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/base/lerp.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
......@@ -34,7 +33,7 @@ class EnsureVisibleApp extends App {
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
cardModels = new List.generate(cardHeights.length, (i) {
Color color = lerpColor(colors.Red[300], colors.Blue[900], i / cardHeights.length);
Color color = Color.lerp(colors.Red[300], colors.Blue[900], i / cardHeights.length);
return new CardModel(i, cardHeights[i], color);
});
......
......@@ -4,7 +4,6 @@
import 'dart:sky' as sky;
import 'package:sky/base/lerp.dart';
import 'package:sky/rendering.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
......@@ -83,7 +82,7 @@ class OverlayGeometryApp extends App {
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0
];
cardModels = new List.generate(cardHeights.length, (i) {
Color color = lerpColor(colors.Red[300], colors.Blue[900], i / cardHeights.length);
Color color = Color.lerp(colors.Red[300], colors.Blue[900], i / cardHeights.length);
return new CardModel(i, cardHeights[i], color);
});
super.initState();
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/base/lerp.dart';
import 'package:sky/theme/colors.dart';
import 'package:sky/widgets.dart';
......@@ -33,7 +32,7 @@ class PageableListApp extends App {
.toList();
cardModels = new List.generate(cardSizes.length, (i) {
Color color = lerpColor(Red[300], Blue[900], i / cardSizes.length);
Color color = Color.lerp(Red[300], Blue[900], i / cardSizes.length);
return new CardModel(i, cardSizes[i], color);
});
......
......@@ -6,7 +6,6 @@ import "dart:sky";
import 'package:sky/animation/curves.dart';
import 'package:sky/animation/direction.dart';
import 'package:sky/base/lerp.dart';
export 'package:sky/animation/curves.dart' show Interval;
......@@ -89,12 +88,12 @@ class AnimatedColorValue extends AnimatedValue<Color> {
AnimatedColorValue(Color begin, { Color end, Curve curve })
: super(begin, end: end, curve: curve);
Color lerp(double t) => lerpColor(begin, end, t);
Color lerp(double t) => Color.lerp(begin, end, t);
}
class AnimatedRect extends AnimatedValue<Rect> {
AnimatedRect(Rect begin, { Rect end, Curve curve })
: super(begin, end: end, curve: curve);
Rect lerp(double t) => lerpRect(begin, end, t);
Rect lerp(double t) => Rect.lerp(begin, end, t);
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:sky';
/// Linearly interpolate between two numbers.
num lerpNum(num a, num b, double t) {
if (a == null && b == null)
return null;
if (a == null)
a = 0.0;
if (b == null)
b = 0.0;
return a + (b - a) * t;
}
Color _scaleAlpha(Color a, double factor) {
return a.withAlpha((a.alpha * factor).round());
}
/// Linearly interpolate between two [Color] objects.
///
/// If either color is null, this function linearly interpolates from a
/// transparent instance of othe other color.
Color lerpColor(Color a, Color b, double t) {
if (a == null && b == null)
return null;
if (a == null)
return _scaleAlpha(b, t);
if (b == null)
return _scaleAlpha(a, 1.0 - t);
return new Color.fromARGB(
lerpNum(a.alpha, b.alpha, t).toInt(),
lerpNum(a.red, b.red, t).toInt(),
lerpNum(a.green, b.green, t).toInt(),
lerpNum(a.blue, b.blue, t).toInt()
);
}
/// Linearly interpolate between two [Offset] objects.
///
/// If either offset is null, this function interpolates from [Offset.zero].
Offset lerpOffset(Offset a, Offset b, double t) {
if (a == null && b == null)
return null;
if (a == null)
return b * t;
if (b == null)
return a * (1.0 - t);
return new Offset(lerpNum(a.dx, b.dx, t), lerpNum(a.dy, b.dy, t));
}
/// Linearly interpolate between two [Rect] objects.
///
/// If either rect is null, this function interpolates from 0x0x0x0.
Rect lerpRect(Rect a, Rect b, double t) {
if (a == null && b == null)
return null;
if (a == null)
return new Rect.fromLTRB(b.left * t, b.top * t, b.right * t, b.bottom * t);
if (b == null) {
double k = 1.0 - t;
return new Rect.fromLTRB(b.left * k, b.top * k, b.right * k, b.bottom * k);
}
return new Rect.fromLTRB(
lerpNum(a.left, b.left, t),
lerpNum(a.top, b.top, t),
lerpNum(a.right, b.right, t),
lerpNum(a.bottom, b.bottom, t)
);
}
......@@ -7,7 +7,6 @@ import 'dart:sky' as sky;
import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path;
import 'package:sky/base/image_resource.dart';
import 'package:sky/base/lerp.dart';
import 'package:sky/painting/shadows.dart';
/// An immutable set of offsets in each of the four cardinal directions
......@@ -197,9 +196,9 @@ class BoxShadow {
if (b == null)
return a.scale(1.0 - t);
return new BoxShadow(
color: lerpColor(a.color, b.color, t),
offset: lerpOffset(a.offset, b.offset, t),
blur: lerpNum(a.blur, b.blur, t)
color: Color.lerp(a.color, b.color, t),
offset: Offset.lerp(a.offset, b.offset, t),
blur: sky.lerpDouble(a.blur, b.blur, t)
);
}
......@@ -521,10 +520,10 @@ class BoxDecoration {
BoxDecoration scale(double factor) {
// TODO(abarth): Scale ALL the things.
return new BoxDecoration(
backgroundColor: lerpColor(null, backgroundColor, factor),
backgroundColor: Color.lerp(null, backgroundColor, factor),
backgroundImage: backgroundImage,
border: border,
borderRadius: lerpNum(null, borderRadius, factor),
borderRadius: sky.lerpDouble(null, borderRadius, factor),
boxShadow: BoxShadow.lerpList(null, boxShadow, factor),
gradient: gradient,
shape: shape
......@@ -543,10 +542,10 @@ class BoxDecoration {
return a.scale(1.0 - t);
// TODO(abarth): lerp ALL the fields.
return new BoxDecoration(
backgroundColor: lerpColor(a.backgroundColor, b.backgroundColor, t),
backgroundColor: Color.lerp(a.backgroundColor, b.backgroundColor, t),
backgroundImage: b.backgroundImage,
border: b.border,
borderRadius: lerpNum(a.borderRadius, b.borderRadius, t),
borderRadius: sky.lerpDouble(a.borderRadius, b.borderRadius, t),
boxShadow: BoxShadow.lerpList(a.boxShadow, b.boxShadow, t),
gradient: b.gradient,
shape: b.shape
......
......@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:vector_math/vector_math.dart';
import 'dart:sky' as sky;
import 'package:vector_math/vector_math.dart';
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart';
import 'package:sky/painting/box_painter.dart';
import 'package:sky/src/widgets/animated_component.dart';
import 'package:sky/src/widgets/basic.dart';
......@@ -34,10 +34,10 @@ class AnimatedEdgeDimsValue extends AnimatedValue<EdgeDims> {
EdgeDims lerp(double t) {
return new EdgeDims(
lerpNum(begin.top, end.top, t),
lerpNum(begin.right, end.right, t),
lerpNum(begin.bottom, end.bottom, t),
lerpNum(begin.bottom, end.left, t)
sky.lerpDouble(begin.top, end.top, t),
sky.lerpDouble(begin.right, end.right, t),
sky.lerpDouble(begin.bottom, end.bottom, t),
sky.lerpDouble(begin.bottom, end.left, t)
);
}
}
......
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