forked from bit/DotRecastNetSim
refactor: RcVec3f.Lerp
This commit is contained in:
parent
93b6b52b8f
commit
21b3cd6caa
|
@ -228,13 +228,14 @@ namespace DotRecast.Core.Numerics
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public static RcVec3f Lerp(RcVec3f v1, RcVec3f v2, float t)
|
public static RcVec3f Lerp(RcVec3f value1, RcVec3f value2, float amount)
|
||||||
{
|
{
|
||||||
return new RcVec3f(
|
return (value1 * (1f - amount)) + (value2 * amount);
|
||||||
v1.X + (v2.X - v1.X) * t,
|
// return new RcVec3f(
|
||||||
v1.Y + (v2.Y - v1.Y) * t,
|
// value1.X + (value2.X - value1.X) * amount,
|
||||||
v1.Z + (v2.Z - v1.Z) * t
|
// value1.Y + (value2.Y - value1.Y) * amount,
|
||||||
);
|
// value1.Z + (value2.Z - value1.Z) * amount
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the distance between two points.
|
/// Returns the distance between two points.
|
||||||
|
|
|
@ -99,13 +99,18 @@ public class Vector3Tests
|
||||||
{
|
{
|
||||||
var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
|
var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
|
||||||
var array1 = new float[3];
|
var array1 = new float[3];
|
||||||
|
var array2 = new float[3];
|
||||||
v1.CopyTo(array1);
|
v1.CopyTo(array1);
|
||||||
|
v1.CopyTo(array2, 0);
|
||||||
|
|
||||||
var v11 = new RcVec3f(v1.X, v1.Y, v1.Z);
|
var v11 = new RcVec3f(v1.X, v1.Y, v1.Z);
|
||||||
var array11 = new float[3];
|
var array11 = new float[3];
|
||||||
|
var array22 = new float[3];
|
||||||
v11.CopyTo(array11);
|
v11.CopyTo(array11);
|
||||||
|
v11.CopyTo(array22, 0);
|
||||||
|
|
||||||
Assert.That(array1, Is.EqualTo(array11));
|
Assert.That(array1, Is.EqualTo(array11));
|
||||||
|
Assert.That(array2, Is.EqualTo(array22));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -167,26 +172,19 @@ public class Vector3Tests
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Repeat(100000)]
|
[Repeat(100000)]
|
||||||
public void TestVectorIsFinite()
|
public void TestVectorLerp()
|
||||||
{
|
{
|
||||||
// IsFinite
|
var amt = Random.Shared.NextSingle();
|
||||||
}
|
var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
|
||||||
|
var v2 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
|
||||||
|
var v3 = Vector3.Lerp(v1, v2, amt);
|
||||||
|
|
||||||
// [Test]
|
var v11 = new RcVec3f(v1.X, v1.Y, v1.Z);
|
||||||
// [Repeat(100000)]
|
var v22 = new RcVec3f(v2.X, v2.Y, v2.Z);
|
||||||
// public void TestVectorLerp()
|
var v33 = RcVec3f.Lerp(v11, v22, amt);
|
||||||
// {
|
|
||||||
// var amt = Random.Shared.NextSingle();
|
Assert.That(v3.X, Is.EqualTo(v33.X));
|
||||||
// var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
|
Assert.That(v3.Y, Is.EqualTo(v33.Y));
|
||||||
// var v2 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
|
Assert.That(v3.Z, Is.EqualTo(v33.Z));
|
||||||
// var v3 = Vector3.Lerp(v1, v2, amt);
|
}
|
||||||
//
|
|
||||||
// var v11 = new RcVec3f(v1.X, v1.Y, v1.Z);
|
|
||||||
// var v22 = new RcVec3f(v2.X, v2.Y, v2.Z);
|
|
||||||
// var v33 = RcVec3f.Lerp(v11, v22, amt);
|
|
||||||
//
|
|
||||||
// Assert.That(v3.X, Is.EqualTo(v33.X));
|
|
||||||
// Assert.That(v3.Y, Is.EqualTo(v33.Y));
|
|
||||||
// Assert.That(v3.Z, Is.EqualTo(v33.Z));
|
|
||||||
// }
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue