diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index 980bb12153a..1983cde67e6 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -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(); diff --git a/examples/widgets/ensure_visible.dart b/examples/widgets/ensure_visible.dart index 1a07f084ce4..2aa92de572f 100644 --- a/examples/widgets/ensure_visible.dart +++ b/examples/widgets/ensure_visible.dart @@ -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); }); diff --git a/examples/widgets/overlay_geometry.dart b/examples/widgets/overlay_geometry.dart index b09abfb0803..c9fcd7627cc 100644 --- a/examples/widgets/overlay_geometry.dart +++ b/examples/widgets/overlay_geometry.dart @@ -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(); diff --git a/examples/widgets/pageable_list.dart b/examples/widgets/pageable_list.dart index 3f2085e9a13..881cff51071 100644 --- a/examples/widgets/pageable_list.dart +++ b/examples/widgets/pageable_list.dart @@ -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); }); diff --git a/packages/flutter/lib/animation/animated_value.dart b/packages/flutter/lib/animation/animated_value.dart index c469881cbba..02cc3b3b8c3 100644 --- a/packages/flutter/lib/animation/animated_value.dart +++ b/packages/flutter/lib/animation/animated_value.dart @@ -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 { 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 { 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); } diff --git a/packages/flutter/lib/base/lerp.dart b/packages/flutter/lib/base/lerp.dart deleted file mode 100644 index 33c25a45de5..00000000000 --- a/packages/flutter/lib/base/lerp.dart +++ /dev/null @@ -1,72 +0,0 @@ -// 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) - ); -} diff --git a/packages/flutter/lib/painting/box_painter.dart b/packages/flutter/lib/painting/box_painter.dart index 448a439c8f5..7fb94f5c715 100644 --- a/packages/flutter/lib/painting/box_painter.dart +++ b/packages/flutter/lib/painting/box_painter.dart @@ -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 diff --git a/packages/flutter/lib/src/widgets/animated_container.dart b/packages/flutter/lib/src/widgets/animated_container.dart index 0eb19b185e8..a2db6bb20a5 100644 --- a/packages/flutter/lib/src/widgets/animated_container.dart +++ b/packages/flutter/lib/src/widgets/animated_container.dart @@ -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 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) ); } }