This commit is contained in:
ikpil 2024-04-30 00:11:09 +09:00
parent f81975d97a
commit 29fab9f5b2
3 changed files with 7 additions and 9 deletions

View File

@ -137,12 +137,12 @@ namespace DotRecast.Detour
} }
// Randomly pick point on polygon. // Randomly pick point on polygon.
float[] verts = new float[3 * m_nav.GetMaxVertsPerPoly()]; Span<float> verts = stackalloc float[3 * m_nav.GetMaxVertsPerPoly()];
float[] areas = new float[m_nav.GetMaxVertsPerPoly()]; Span<float> areas = stackalloc float[m_nav.GetMaxVertsPerPoly()];
RcArrays.Copy(tile.data.verts, poly.verts[0] * 3, verts, 0, 3); RcSpans.Copy(tile.data.verts, poly.verts[0] * 3, verts, 0, 3);
for (int j = 1; j < poly.vertCount; ++j) 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(); float s = frand.Next();

View File

@ -145,7 +145,7 @@ namespace DotRecast.Detour
/// @param[in] b Vertex B. [(x, y, z)] /// @param[in] b Vertex B. [(x, y, z)]
/// @param[in] c Vertex C. [(x, y, z)] /// @param[in] c Vertex C. [(x, y, z)]
/// @return The signed xz-plane area of the triangle. /// @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<float> verts, int a, int b, int c)
{ {
float abx = verts[b] - verts[a]; float abx = verts[b] - verts[a];
float abz = verts[b + 2] - verts[a + 2]; float abz = verts[b + 2] - verts[a + 2];
@ -165,7 +165,7 @@ namespace DotRecast.Detour
// Returns a random point in a convex polygon. // Returns a random point in a convex polygon.
// Adapted from Graphics Gems article. // Adapted from Graphics Gems article.
public static RcVec3f RandomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t) public static RcVec3f RandomPointInConvexPoly(Span<float> pts, int npts, Span<float> areas, float s, float t)
{ {
// Calc triangle araes // Calc triangle araes
float areasum = 0.0f; float areasum = 0.0f;

View File

@ -19,13 +19,11 @@ freely, subject to the following restrictions:
using System; using System;
using DotRecast.Core; using DotRecast.Core;
using DotRecast.Core.Numerics; using DotRecast.Core.Numerics;
using NUnit.Framework; using NUnit.Framework;
namespace DotRecast.Detour.Test; namespace DotRecast.Detour.Test;
public class RandomPointTest : AbstractDetourTest public class RandomPointTest : AbstractDetourTest
{ {
[Test] [Test]