Add Point.lerp

This commit is contained in:
Adam Barth 2015-12-03 11:04:15 -08:00
parent ad63ba0fb3
commit b8f159145d

View File

@ -18,9 +18,27 @@ class Point {
Point operator +(Offset other) => new Point(x + other.dx, y + other.dy);
Rect operator &(Size other) => new Rect.fromLTWH(x, y, other.width, other.height);
Point operator *(double operand) => new Point(x * operand, y * operand);
Point operator /(double operand) => new Point(x / operand, y / operand);
Point operator ~/(double operand) => new Point((x ~/ operand).toDouble(), (y ~/ operand).toDouble());
Point operator %(double operand) => new Point(x % operand, y % operand);
// does the equivalent of "return this - Point.origin"
Offset toOffset() => new Offset(x, y);
/// Linearly interpolate between two points
///
/// If either point is null, this function interpolates from [Point.origin].
static Point lerp(Point a, Point 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 Point(lerpDouble(a.x, b.x, t), lerpDouble(a.y, b.y, t));
}
bool operator ==(dynamic other) {
if (other is! Point)
return false;