diff --git a/src/DotRecast.Core/Numerics/RcVec3f.cs b/src/DotRecast.Core/Numerics/RcVec3f.cs index 44f5867..6963d65 100644 --- a/src/DotRecast.Core/Numerics/RcVec3f.cs +++ b/src/DotRecast.Core/Numerics/RcVec3f.cs @@ -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)] diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index 4415716..d9dae57 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -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. diff --git a/test/DotRecast.Core.Test/Vector3Tests.cs b/test/DotRecast.Core.Test/Vector3Tests.cs index 5fdd4e8..bc9a155 100644 --- a/test/DotRecast.Core.Test/Vector3Tests.cs +++ b/test/DotRecast.Core.Test/Vector3Tests.cs @@ -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)); + } + } \ No newline at end of file