refactor: remove RcVec3f.Of(float[] f, int idx)

This commit is contained in:
ikpil 2023-10-14 19:30:33 +09:00
parent 51c0a23d7e
commit 5aac44c440
7 changed files with 14 additions and 18 deletions

View File

@ -33,11 +33,6 @@ namespace DotRecast.Core
public static RcVec3f UnitY { get; } = new RcVec3f(0.0f, 1.0f, 0.0f);
public static RcVec3f UnitZ { get; } = new RcVec3f(0.0f, 0.0f, 1.0f);
public static RcVec3f Of(float[] f, int idx)
{
return new RcVec3f(f[idx + 0], f[idx + 1], f[idx + 2]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RcVec3f(float x, float y, float z)
{

View File

@ -16,6 +16,7 @@ freely, subject to the following restrictions:
3. This notice may not be removed or altered from any source distribution.
*/
using System;
using DotRecast.Core;
namespace DotRecast.Detour.Extras.Unity.Astar
@ -54,7 +55,7 @@ namespace DotRecast.Detour.Extras.Unity.Astar
connection.rad = 0.1f;
connection.side = startTile == endTile
? 0xFF
: DtNavMeshBuilder.ClassifyOffMeshPoint(RcVec3f.Of(connection.pos, 3), startTile.header.bmin, startTile.header.bmax);
: DtNavMeshBuilder.ClassifyOffMeshPoint(new RcVec3f(connection.pos.AsSpan(3)), startTile.header.bmin, startTile.header.bmax);
connection.userId = (int)l.linkID;
if (startTile.offMeshCons == null)
{

View File

@ -1568,8 +1568,8 @@ namespace DotRecast.Detour
}
}
startPos = RcVec3f.Of(tile.data.verts, poly.verts[idx0] * 3);
endPos = RcVec3f.Of(tile.data.verts, poly.verts[idx1] * 3);
startPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx0] * 3));
endPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx1] * 3));
return DtStatus.DT_SUCCSESS;
}

View File

@ -319,8 +319,8 @@ namespace DotRecast.Detour
for (int i = 0; i < option.offMeshConCount; ++i)
{
var p0 = RcVec3f.Of(option.offMeshConVerts, (i * 2 + 0) * 3);
var p1 = RcVec3f.Of(option.offMeshConVerts, (i * 2 + 1) * 3);
var p0 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 0) * 3));
var p1 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 1) * 3));
offMeshConClass[i * 2 + 0] = ClassifyOffMeshPoint(p0, bmin, bmax);
offMeshConClass[i * 2 + 1] = ClassifyOffMeshPoint(p1, bmin, bmax);

View File

@ -2202,7 +2202,7 @@ namespace DotRecast.Detour
int nv = 0;
for (int i = 0; i < poly.vertCount; ++i)
{
verts[nv] = RcVec3f.Of(tile.data.verts, poly.verts[i] * 3);
verts[nv] = new RcVec3f(tile.data.verts.AsSpan(poly.verts[i] * 3));
nv++;
}
@ -3215,8 +3215,8 @@ namespace DotRecast.Detour
hitPos.Y = bestTile.data.verts[vj + 1] + (bestTile.data.verts[vi + 1] - bestTile.data.verts[vj + 1]) * tseg;
hitPos.Z = bestTile.data.verts[vj + 2] + (bestTile.data.verts[vi + 2] - bestTile.data.verts[vj + 2]) * tseg;
hasBestV = true;
bestvj = RcVec3f.Of(bestTile.data.verts, vj);
bestvi = RcVec3f.Of(bestTile.data.verts, vi);
bestvj = new RcVec3f(bestTile.data.verts.AsSpan(vj));
bestvi = new RcVec3f(bestTile.data.verts.AsSpan(vi));
}
for (int i = bestTile.polyLinks[bestPoly.index]; i != DtNavMesh.DT_NULL_LINK; i = bestTile.links[i].next)

View File

@ -308,8 +308,8 @@ namespace DotRecast.Detour
public static float DistancePtSegSqr2D(RcVec3f pt, float[] verts, int p, int q, out float t)
{
var vp = RcVec3f.Of(verts, p);
var vq = RcVec3f.Of(verts, q);
var vp = new RcVec3f(verts.AsSpan(p));
var vq = new RcVec3f(verts.AsSpan(q));
return DistancePtSegSqr2D(pt, vp, vq, out t);
}

View File

@ -753,9 +753,9 @@ namespace DotRecast.Recast
int vertIndexB = vertIndex;
int vertIndexC = (vertIndex + 1) % numVerts;
RcVec3f vertA = RcVec3f.Of(verts, vertIndexA * 3);
RcVec3f vertB = RcVec3f.Of(verts, vertIndexB * 3);
RcVec3f vertC = RcVec3f.Of(verts, vertIndexC * 3);
RcVec3f vertA = new RcVec3f(verts.AsSpan(vertIndexA * 3));
RcVec3f vertB = new RcVec3f(verts.AsSpan(vertIndexB * 3));
RcVec3f vertC = new RcVec3f(verts.AsSpan(vertIndexC * 3));
// From A to B on the x/z plane
RcVec3f prevSegmentDir = vertB.Subtract(vertA);