From 71a269c36fc47bcd9cfc95e28369db6742b2400e Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Tue, 29 Oct 2019 19:45:08 -0700 Subject: [PATCH] InOutCubic and OutInCubic --- Easing/Easing.cs | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ Test/Easing.cs | 58 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) diff --git a/Easing/Easing.cs b/Easing/Easing.cs index b0a08bc..f679a48 100644 --- a/Easing/Easing.cs +++ b/Easing/Easing.cs @@ -202,5 +202,77 @@ namespace MoonTools.Core.Easing t = t / d - 1; return c * (t * t * t + 1) + b; } + + // IN OUT CUBIC + + public static float InOutCubic(float t) => NormalizedTime(InOutCubic, t); + public static float InOutCubic(float time, float start, float end) => TimeRange(InOutCubic, time, start, end); + + public static float InOutCubic(float t, float b, float c, float d) + { + CheckTime(t, d); + t = t / d * 2; + if (t < 1) + { + return c / 2 * t * t * t + b; + } + else + { + t = t - 2; + return c / 2 * (t * t * t + 2) + b; + } + } + + // IN OUT CUBIC + + public static double InOutCubic(double t) => NormalizedTime(InOutCubic, t); + public static double InOutCubic(double time, double start, double end) => TimeRange(InOutCubic, time, start, end); + + public static double InOutCubic(double t, double b, double c, double d) + { + CheckTime(t, d); + t = t / d * 2; + if (t < 1) + { + return c / 2 * t * t * t + b; + } + else + { + t = t - 2; + return c / 2 * (t * t * t + 2) + b; + } + } + + // OUT IN CUBIC + + public static float OutInCubic(float t) => NormalizedTime(OutInCubic, t); + public static float OutInCubic(float time, float start, float end) => TimeRange(OutInCubic, time, start, end); + + public static float OutInCubic(float t, float b, float c, float d) + { + if (t < d / 2) + { + return OutCubic(t * 2, b, c / 2, d); + } + else + { + return InCubic((t * 2) - d, b + c / 2, c / 2, d); + } + } + + public static double OutInCubic(double t) => NormalizedTime(OutInCubic, t); + public static double OutInCubic(double time, double start, double end) => TimeRange(OutInCubic, time, start, end); + + public static double OutInCubic(double t, double b, double c, double d) + { + if (t < d / 2) + { + return OutCubic(t * 2, b, c / 2, d); + } + else + { + return InCubic((t * 2) - d, b + c / 2, c / 2, d); + } + } } } diff --git a/Test/Easing.cs b/Test/Easing.cs index 80ee1c7..c404daa 100644 --- a/Test/Easing.cs +++ b/Test/Easing.cs @@ -122,6 +122,36 @@ namespace Test Easing.OutCubic(3, 2, 6).Should().Be(4.3125f); Easing.OutCubic(4, 2, 6).Should().Be(5.5f); Easing.OutCubic(5, 2, 6).Should().Be(5.9375f); + + CheckFloatArguments(Easing.OutCubic, Easing.OutCubic); + } + + [Test] + public void InOutCubic() + { + Easing.InOutCubic(0.25f).Should().Be(0.0625f); + Easing.InOutCubic(0.5f).Should().Be(0.5f); + Easing.InOutCubic(0.75f).Should().Be(0.9375f); + + Easing.InOutCubic(3, 2, 6).Should().Be(2.25f); + Easing.InOutCubic(4, 2, 6).Should().Be(4f); + Easing.InOutCubic(5, 2, 6).Should().Be(5.75f); + + CheckFloatArguments(Easing.InOutCubic, Easing.InOutCubic); + } + + [Test] + public void OutInCubic() + { + Easing.OutInCubic(0.25f).Should().Be(0.4375f); + Easing.OutInCubic(0.5f).Should().Be(0.5f); + Easing.OutInCubic(0.75f).Should().Be(0.5625f); + + Easing.OutInCubic(3, 2, 6).Should().Be(3.75f); + Easing.OutInCubic(4, 2, 6).Should().Be(4f); + Easing.OutInCubic(5, 2, 6).Should().Be(4.25f); + + CheckFloatArguments(Easing.OutInCubic, Easing.OutInCubic); } } @@ -224,6 +254,34 @@ namespace Test CheckDoubleArguments(Easing.OutCubic, Easing.OutCubic); } + + [Test] + public void InOutCubic() + { + Easing.InOutCubic(0.25).Should().Be(0.0625); + Easing.InOutCubic(0.5).Should().Be(0.5); + Easing.InOutCubic(0.75).Should().Be(0.9375); + + Easing.InOutCubic(3.0, 2, 6).Should().Be(2.25); + Easing.InOutCubic(4.0, 2, 6).Should().Be(4); + Easing.InOutCubic(5.0, 2, 6).Should().Be(5.75); + + CheckDoubleArguments(Easing.InOutCubic, Easing.InOutCubic); + } + + [Test] + public void OutInCubic() + { + Easing.OutInCubic(0.25).Should().Be(0.4375); + Easing.OutInCubic(0.5).Should().Be(0.5); + Easing.OutInCubic(0.75).Should().Be(0.5625); + + Easing.OutInCubic(3.0, 2, 6).Should().Be(3.75); + Easing.OutInCubic(4.0, 2, 6).Should().Be(4); + Easing.OutInCubic(5.0, 2, 6).Should().Be(4.25); + + CheckDoubleArguments(Easing.OutInCubic, Easing.OutInCubic); + } } } } \ No newline at end of file