InOutCubic and OutInCubic
parent
251391216f
commit
71a269c36f
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue