From 5aac44c44067f6ea81682f1e440f27c85a3338b2 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 14 Oct 2023 19:30:33 +0900 Subject: [PATCH] refactor: remove RcVec3f.Of(float[] f, int idx) --- src/DotRecast.Core/RcVec3f.cs | 5 ----- .../Unity/Astar/OffMeshLinkCreator.cs | 3 ++- src/DotRecast.Detour/DtNavMesh.cs | 4 ++-- src/DotRecast.Detour/DtNavMeshBuilder.cs | 4 ++-- src/DotRecast.Detour/DtNavMeshQuery.cs | 6 +++--- src/DotRecast.Detour/DtUtils.cs | 4 ++-- src/DotRecast.Recast/RcAreas.cs | 6 +++--- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/DotRecast.Core/RcVec3f.cs b/src/DotRecast.Core/RcVec3f.cs index eb47601..c6c360f 100644 --- a/src/DotRecast.Core/RcVec3f.cs +++ b/src/DotRecast.Core/RcVec3f.cs @@ -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) { diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs index 9ac0f6a..1151a94 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs @@ -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) { diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 5df8d3e..ff3ec30 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -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; } diff --git a/src/DotRecast.Detour/DtNavMeshBuilder.cs b/src/DotRecast.Detour/DtNavMeshBuilder.cs index 5371618..0b64949 100644 --- a/src/DotRecast.Detour/DtNavMeshBuilder.cs +++ b/src/DotRecast.Detour/DtNavMeshBuilder.cs @@ -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); diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 3a00a1c..c9d630d 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -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) diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index 75ced43..0c5e585 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -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); } diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index 70cb044..e544bee 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -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);