Skip to content

Commit

Permalink
refactor: remove RcVec3f.Of(float[] f, int idx)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikpil committed Oct 14, 2023
1 parent 51c0a23 commit 5aac44c
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
5 changes: 0 additions & 5 deletions src/DotRecast.Core/RcVec3f.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ public struct RcVec3f
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

using System;
using DotRecast.Core;

namespace DotRecast.Detour.Extras.Unity.Astar
Expand Down Expand Up @@ -54,7 +55,7 @@ public void Build(GraphMeshData graphData, NodeLink2[] links, int nodeOffset)
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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Detour/DtNavMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,8 +1568,8 @@ public DtStatus GetOffMeshConnectionPolyEndPoints(long prevRef, long polyRef, re
}
}

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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Detour/DtNavMeshBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ public static DtMeshData CreateNavMeshData(DtNavMeshCreateParams option)

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);
Expand Down
6 changes: 3 additions & 3 deletions src/DotRecast.Detour/DtNavMeshQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2202,7 +2202,7 @@ public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQuer
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++;
}

Expand Down Expand Up @@ -3215,8 +3215,8 @@ public virtual DtStatus FindDistanceToWall(long startRef, RcVec3f centerPos, flo
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)
Expand Down
4 changes: 2 additions & 2 deletions src/DotRecast.Detour/DtUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ public static bool DistancePtPolyEdgesSqr(RcVec3f pt, float[] verts, int nverts,

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);
}

Expand Down
6 changes: 3 additions & 3 deletions src/DotRecast.Recast/RcAreas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,9 +753,9 @@ public static int OffsetPoly(float[] verts, int numVerts, float offset, float[]
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);
Expand Down

0 comments on commit 5aac44c

Please sign in to comment.