bounce functions

master
Evan Hemsley 2019-10-30 20:14:08 -07:00
parent d7e49ead3e
commit 328a88fadd
2 changed files with 121 additions and 0 deletions

View File

@ -822,5 +822,70 @@ namespace MoonTools.Core.Easing
return InBack((t * 2) - d, b + c / 2, c / 2, d, s);
}
}
// OUT BOUNCE
public static double OutBounce(double t) => NormalizedTime(OutBounce, t);
public static double OutBounce(double time, double start, double end) => TimeRange(OutBounce, time, start, end);
public static double OutBounce(double t, double b, double c, double d)
{
CheckTime(t, d);
t = t / d;
if (t < 1 / 2.75)
{
return c * (7.5625 * t * t) + b;
}
else if (t < 2 / 2.75)
{
t = t - (1.5 / 2.75);
return c * (7.5625 * t * t + 0.75) + b;
}
else if (t < 2.5 / 2.75)
{
t = t - (2.25 / 2.75);
return c * (7.5625 * t * t + 0.9375) + b;
}
else
{
t = t - (2.625 / 2.75);
return c * (7.5625 * t * t + 0.984375) + b;
}
}
// IN BOUNCE
public static double InBounce(double t) => NormalizedTime(InBounce, t);
public static double InBounce(double time, double start, double end) => TimeRange(InBounce, time, start, end);
public static double InBounce(double t, double b, double c, double d)
{
CheckTime(t, d);
return c - OutBounce(d - t, 0, c, d) + b;
}
// IN OUT BOUNCE
public static double InOutBounce(double t) => NormalizedTime(InOutBounce, t);
public static double InOutBounce(double time, double start, double end) => TimeRange(InOutBounce, time, start, end);
public static double InOutBounce(double t, double b, double c, double d)
{
CheckTime(t, d);
if (t < d / 2)
{
return InBounce(t * 2, 0, c, d) * 0.5 + b;
}
else
{
return OutBounce(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
}
}
// OUT IN BOUNCE
public static double OutInBounce(double t) => NormalizedTime(OutInBounce, t);
public static double OutInBounce(double time, double start, double end) => TimeRange(OutInBounce, time, start, end);
public static double OutInBounce(double t, double b, double c, double d) => OutIn(OutBounce, InBounce, t, b, c, d);
}
}

View File

@ -1146,6 +1146,62 @@ namespace Test
Easing.OutInBackTimeRange(4, 2, 6, 3).Should().BeApproximately(4, 0.001);
Easing.OutInBackTimeRange(5, 2, 6, 3).Should().BeApproximately(3.5, 0.001);
}
[Test]
public void OutBounce()
{
Easing.OutBounce(0.25).Should().BeApproximately(0.47265625, 0.001);
Easing.OutBounce(0.5).Should().BeApproximately(0.765625, 0.001);
Easing.OutBounce(0.75).Should().BeApproximately(0.97265625, 0.001);
Easing.OutBounce(3, 2, 6).Should().BeApproximately(3.890625, 0.001);
Easing.OutBounce(4, 2, 6).Should().BeApproximately(5.0625, 0.001);
Easing.OutBounce(5, 2, 6).Should().BeApproximately(5.890625, 0.001);
CheckDoubleArguments(Easing.OutBounce, Easing.OutBounce);
}
[Test]
public void InBounce()
{
Easing.InBounce(0.25).Should().BeApproximately(0.02734375, 0.001);
Easing.InBounce(0.5).Should().BeApproximately(0.234375, 0.001);
Easing.InBounce(0.75).Should().BeApproximately(0.52734375, 0.001);
Easing.InBounce(3, 2, 6).Should().BeApproximately(2.109375, 0.001);
Easing.InBounce(4, 2, 6).Should().BeApproximately(2.9375, 0.001);
Easing.InBounce(5, 2, 6).Should().BeApproximately(4.109375, 0.001);
CheckDoubleArguments(Easing.InBounce, Easing.InBounce);
}
[Test]
public void InOutBounce()
{
Easing.InOutBounce(0.25).Should().BeApproximately(0.1171875, 0.001);
Easing.InOutBounce(0.5).Should().BeApproximately(0.5, 0.001);
Easing.InOutBounce(0.75).Should().BeApproximately(0.8828125, 0.001);
Easing.InOutBounce(3, 2, 6).Should().BeApproximately(2.46875, 0.001);
Easing.InOutBounce(4, 2, 6).Should().BeApproximately(4, 0.001);
Easing.InOutBounce(5, 2, 6).Should().BeApproximately(5.53125, 0.001);
CheckDoubleArguments(Easing.InOutBounce, Easing.InOutBounce);
}
[Test]
public void OutInBounce()
{
Easing.OutInBounce(0.25).Should().BeApproximately(0.3828125, 0.001);
Easing.OutInBounce(0.5).Should().BeApproximately(0.5, 0.001);
Easing.OutInBounce(0.75).Should().BeApproximately(0.6171875, 0.001);
Easing.OutInBounce(3, 2, 6).Should().BeApproximately(3.53125, 0.001);
Easing.OutInBounce(4, 2, 6).Should().BeApproximately(4, 0.001);
Easing.OutInBounce(5, 2, 6).Should().BeApproximately(4.46875, 0.001);
CheckDoubleArguments(Easing.OutInBounce, Easing.OutInBounce);
}
}
}
}