diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index c4dd060..678c05a 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -137,12 +137,12 @@ namespace DotRecast.Detour } // Randomly pick point on polygon. - float[] verts = new float[3 * m_nav.GetMaxVertsPerPoly()]; - float[] areas = new float[m_nav.GetMaxVertsPerPoly()]; - RcArrays.Copy(tile.data.verts, poly.verts[0] * 3, verts, 0, 3); + Span verts = stackalloc float[3 * m_nav.GetMaxVertsPerPoly()]; + Span areas = stackalloc float[m_nav.GetMaxVertsPerPoly()]; + RcSpans.Copy(tile.data.verts, poly.verts[0] * 3, verts, 0, 3); for (int j = 1; j < poly.vertCount; ++j) { - RcArrays.Copy(tile.data.verts, poly.verts[j] * 3, verts, j * 3, 3); + RcSpans.Copy(tile.data.verts, poly.verts[j] * 3, verts, j * 3, 3); } float s = frand.Next(); diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index 91644e5..adb6e9f 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -145,7 +145,7 @@ namespace DotRecast.Detour /// @param[in] b Vertex B. [(x, y, z)] /// @param[in] c Vertex C. [(x, y, z)] /// @return The signed xz-plane area of the triangle. - public static float TriArea2D(float[] verts, int a, int b, int c) + public static float TriArea2D(Span verts, int a, int b, int c) { float abx = verts[b] - verts[a]; float abz = verts[b + 2] - verts[a + 2]; @@ -165,7 +165,7 @@ namespace DotRecast.Detour // Returns a random point in a convex polygon. // Adapted from Graphics Gems article. - public static RcVec3f RandomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t) + public static RcVec3f RandomPointInConvexPoly(Span pts, int npts, Span areas, float s, float t) { // Calc triangle araes float areasum = 0.0f; diff --git a/test/DotRecast.Detour.Test/RandomPointTest.cs b/test/DotRecast.Detour.Test/RandomPointTest.cs index dccaf0f..c8dc58f 100644 --- a/test/DotRecast.Detour.Test/RandomPointTest.cs +++ b/test/DotRecast.Detour.Test/RandomPointTest.cs @@ -19,13 +19,11 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; - using NUnit.Framework; namespace DotRecast.Detour.Test; - public class RandomPointTest : AbstractDetourTest { [Test] @@ -78,7 +76,7 @@ public class RandomPointTest : AbstractDetourTest randomPt = nextRandomPt; status = navmesh.GetTileAndPolyByRef(randomRef, out var tile, out var poly); - + float[] bmin = new float[2]; float[] bmax = new float[2]; for (int j = 0; j < poly.vertCount; j++)