refactor: added test RcVec3f.CopyTo

This commit is contained in:
ikpil 2023-10-23 22:51:09 +09:00
parent e4dc81b027
commit a9888bd281
3 changed files with 28 additions and 5 deletions

View File

@ -454,13 +454,19 @@ namespace DotRecast.Core.Numerics
@out[n + 1] = @in[m + 1];
@out[n + 2] = @in[m + 2];
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(float[] array)
{
CopyTo(array, 0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Copy(float[] @out, int n, RcVec3f @in)
public readonly void CopyTo(float[] array, int n)
{
@out[n + 0] = @in.X;
@out[n + 1] = @in.Y;
@out[n + 2] = @in.Z;
array[n + 0] = X;
array[n + 1] = Y;
array[n + 2] = Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View File

@ -1088,7 +1088,7 @@ namespace DotRecast.Recast
// Mark sample as added.
samples[besti * 4 + 3] = 1;
// Add the new sample point.
RcVec3f.Copy(verts, nverts * 3, bestpt);
bestpt.CopyTo(verts, nverts * 3);
nverts++;
// Create new triangulation.

View File

@ -91,5 +91,22 @@ public class Vector3Tests
Assert.That(v3.X, Is.EqualTo(v33.X));
Assert.That(v3.Y, Is.EqualTo(v33.Y));
Assert.That(v3.Z, Is.EqualTo(v33.Z));
}
[Test]
[Repeat(100000)]
public void TestVectorCopyTo()
{
var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());
var array1 = new float[3];
v1.CopyTo(array1);
var v11 = new RcVec3f(v1.X, v1.Y, v1.Z);
var array11 = new float[3];
v11.CopyTo(array11);
Assert.That(array1, Is.EqualTo(array11));
}
}