forked from mirror/DotRecast
added RcMath.Lerp()
This commit is contained in:
parent
2acbdf8c53
commit
17ecdb1cc7
|
@ -29,5 +29,11 @@ namespace DotRecast.Core
|
||||||
{
|
{
|
||||||
return f * f;
|
return f * f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public static float Lerp(float value1, float value2, float amount)
|
||||||
|
{
|
||||||
|
return (value1 * (1.0f - amount)) + (value2 * amount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
using System;
|
||||||
|
using NUnit.Framework;
|
||||||
|
|
||||||
|
namespace DotRecast.Core.Test;
|
||||||
|
|
||||||
|
public class RcMathTest
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestSqr()
|
||||||
|
{
|
||||||
|
Assert.That(RcMath.Sqr(0), Is.EqualTo(0));
|
||||||
|
Assert.That(RcMath.Sqr(5), Is.EqualTo(25));
|
||||||
|
Assert.That(RcMath.Sqr(-5), Is.EqualTo(25));
|
||||||
|
Assert.That(RcMath.Sqr(float.PositiveInfinity), Is.EqualTo(float.PositiveInfinity));
|
||||||
|
Assert.That(RcMath.Sqr(float.NegativeInfinity), Is.EqualTo(float.PositiveInfinity));
|
||||||
|
Assert.That(RcMath.Sqr(float.NaN), Is.EqualTo(float.NaN));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestLerp()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, 2f), Is.EqualTo(30));
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, 1f), Is.EqualTo(10));
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, 0.5f), Is.EqualTo(0));
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, 0.25f), Is.EqualTo(-5));
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, 0), Is.EqualTo(-10));
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, -0.5f), Is.EqualTo(-20));
|
||||||
|
Assert.That(RcMath.Lerp(-10, 10, -1f), Is.EqualTo(-30));
|
||||||
|
|
||||||
|
//
|
||||||
|
Assert.That(RcMath.Lerp(10, 10, 0.5f), Is.EqualTo(10));
|
||||||
|
Assert.That(RcMath.Lerp(10, 10, 0.8f), Is.EqualTo(10));
|
||||||
|
|
||||||
|
//
|
||||||
|
Assert.That(RcMath.Lerp(10, -10, 0.75f), Is.EqualTo(-5));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue