diff --git a/src/DotRecast.Core/Numerics/RcVec3f.cs b/src/DotRecast.Core/Numerics/RcVec3f.cs index 6963d65..f558d4c 100644 --- a/src/DotRecast.Core/Numerics/RcVec3f.cs +++ b/src/DotRecast.Core/Numerics/RcVec3f.cs @@ -438,23 +438,6 @@ namespace DotRecast.Core.Numerics return float.IsFinite(v.X) && float.IsFinite(v.Z); } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy(ref RcVec3f @out, float[] @in, int i) - { - @out.X = @in[i + 0]; - @out.Y = @in[i + 1]; - @out.Z = @in[i + 2]; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Copy(float[] @out, int n, float[] @in, int m) - { - @out[n] = @in[m]; - @out[n + 1] = @in[m + 1]; - @out[n + 2] = @in[m + 2]; - } - [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly void CopyTo(float[] array) { diff --git a/src/DotRecast.Core/Numerics/RcVecUtils.cs b/src/DotRecast.Core/Numerics/RcVecUtils.cs index 3899f81..76b1f41 100644 --- a/src/DotRecast.Core/Numerics/RcVecUtils.cs +++ b/src/DotRecast.Core/Numerics/RcVecUtils.cs @@ -96,5 +96,13 @@ namespace DotRecast.Core.Numerics dest[1] = v1[2] * v2[0] - v1[0] * v2[2]; dest[2] = v1[0] * v2[1] - v1[1] * v2[0]; } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static void Copy(float[] @out, int n, float[] @in, int m) + { + @out[n + 0] = @in[m + 0]; + @out[n + 1] = @in[m + 1]; + @out[n + 2] = @in[m + 2]; + } } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 85ee692..12b7754 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -57,10 +57,8 @@ namespace DotRecast.Recast.Toolset.Geom this.faces = faces; normals = new float[faces.Length]; CalculateNormals(); - bmin = RcVec3f.Zero; - bmax = RcVec3f.Zero; - RcVec3f.Copy(ref bmin, vertices, 0); - RcVec3f.Copy(ref bmax, vertices, 0); + bmin = new RcVec3f(vertices); + bmax = new RcVec3f(vertices); for (int i = 1; i < vertices.Length / 3; i++) { bmin.Min(vertices, i * 3); diff --git a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs index 1567f9a..495445a 100644 --- a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs +++ b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs @@ -77,10 +77,8 @@ namespace DotRecast.Recast.Geom this.faces = faces; normals = new float[faces.Length]; CalculateNormals(); - bmin = RcVec3f.Zero; - bmax = RcVec3f.Zero; - RcVec3f.Copy(ref bmin, vertices, 0); - RcVec3f.Copy(ref bmax, vertices, 0); + bmin = new RcVec3f(vertices); + bmax = new RcVec3f(vertices); for (int i = 1; i < vertices.Length / 3; i++) { bmin.Min(vertices, i * 3); diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index c2b0c86..be1c3e2 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -457,10 +457,8 @@ namespace DotRecast.Recast int zStride = xSize; // For readability // Compute the bounding box of the polygon - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); - RcVec3f.Copy(ref bmin, verts, 0); - RcVec3f.Copy(ref bmax, verts, 0); + RcVec3f bmin = new RcVec3f(verts); + RcVec3f bmax = new RcVec3f(verts); for (int i = 3; i < verts.Length; i += 3) { bmin.Min(verts, i); diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index d9dae57..12bfa81 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -178,7 +178,7 @@ namespace DotRecast.Recast return true; } - RcVec3f.Copy(ref c, verts, p1); + c = new RcVec3f(verts.AsSpan(p1)); r.Exchange(0f); return false; } @@ -842,7 +842,7 @@ namespace DotRecast.Recast for (int i = 0; i < nin; ++i) { - RcVec3f.Copy(verts, i * 3, @in, i * 3); + RcVecUtils.Copy(verts, i * 3, @in, i * 3); } tris.Clear(); @@ -961,7 +961,7 @@ namespace DotRecast.Recast { for (int k = nidx - 2; k > 0; --k) { - RcVec3f.Copy(verts, nverts * 3, edge, idx[k] * 3); + RcVecUtils.Copy(verts, nverts * 3, edge, idx[k] * 3); hull[nhull++] = nverts; nverts++; } @@ -970,7 +970,7 @@ namespace DotRecast.Recast { for (int k = 1; k < nidx - 1; ++k) { - RcVec3f.Copy(verts, nverts * 3, edge, idx[k] * 3); + RcVecUtils.Copy(verts, nverts * 3, edge, idx[k] * 3); hull[nhull++] = nverts; nverts++; } @@ -1000,10 +1000,8 @@ namespace DotRecast.Recast if (sampleDist > 0) { // Create sample locations in a grid. - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); - RcVec3f.Copy(ref bmin, @in, 0); - RcVec3f.Copy(ref bmax, @in, 0); + RcVec3f bmin = new RcVec3f(@in); + RcVec3f bmax = new RcVec3f(@in); for (int i = 1; i < nin; ++i) { bmin.Min(@in, i * 3); @@ -1662,7 +1660,7 @@ namespace DotRecast.Recast for (int k = 0; k < dm.nverts; ++k) { - RcVec3f.Copy(mesh.verts, mesh.nverts * 3, dm.verts, k * 3); + RcVecUtils.Copy(mesh.verts, mesh.nverts * 3, dm.verts, k * 3); mesh.nverts++; } diff --git a/src/DotRecast.Recast/RcRasterizations.cs b/src/DotRecast.Recast/RcRasterizations.cs index c175b85..047be1e 100644 --- a/src/DotRecast.Recast/RcRasterizations.cs +++ b/src/DotRecast.Recast/RcRasterizations.cs @@ -25,8 +25,6 @@ using static DotRecast.Recast.RcConstants; namespace DotRecast.Recast { - - public static class RcRasterizations { /** @@ -179,19 +177,19 @@ namespace DotRecast.Recast (inVerts[inVertsOffset + inVertA * 3 + 1] - inVerts[inVertsOffset + inVertB * 3 + 1]) * s; inVerts[outVerts1 + poly1Vert * 3 + 2] = inVerts[inVertsOffset + inVertB * 3 + 2] + (inVerts[inVertsOffset + inVertA * 3 + 2] - inVerts[inVertsOffset + inVertB * 3 + 2]) * s; - RcVec3f.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, outVerts1 + poly1Vert * 3); + RcVecUtils.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, outVerts1 + poly1Vert * 3); poly1Vert++; poly2Vert++; // add the i'th point to the right polygon. Do NOT add points that are on the dividing line // since these were already added above if (d[inVertA] > 0) { - RcVec3f.Copy(inVerts, outVerts1 + poly1Vert * 3, inVerts, inVertsOffset + inVertA * 3); + RcVecUtils.Copy(inVerts, outVerts1 + poly1Vert * 3, inVerts, inVertsOffset + inVertA * 3); poly1Vert++; } else if (d[inVertA] < 0) { - RcVec3f.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, inVertsOffset + inVertA * 3); + RcVecUtils.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, inVertsOffset + inVertA * 3); poly2Vert++; } } @@ -200,13 +198,13 @@ namespace DotRecast.Recast // add the i'th point to the right polygon. Addition is done even for points on the dividing line if (d[inVertA] >= 0) { - RcVec3f.Copy(inVerts, outVerts1 + poly1Vert * 3, inVerts, inVertsOffset + inVertA * 3); + RcVecUtils.Copy(inVerts, outVerts1 + poly1Vert * 3, inVerts, inVertsOffset + inVertA * 3); poly1Vert++; if (d[inVertA] != 0) continue; } - RcVec3f.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, inVertsOffset + inVertA * 3); + RcVecUtils.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, inVertsOffset + inVertA * 3); poly2Vert++; } } @@ -236,13 +234,11 @@ namespace DotRecast.Recast float cellSize, float inverseCellSize, float inverseCellHeight, int flagMergeThreshold) { - RcVec3f tmin = new RcVec3f(); - RcVec3f tmax = new RcVec3f(); float by = heightfieldBBMax.Y - heightfieldBBMin.Y; // Calculate the bounding box of the triangle. - RcVec3f.Copy(ref tmin, verts, v0 * 3); - RcVec3f.Copy(ref tmax, verts, v0 * 3); + RcVec3f tmin = new RcVec3f(verts.AsSpan(v0 * 3)); + RcVec3f tmax = new RcVec3f(verts.AsSpan(v0 * 3)); tmin.Min(verts, v1 * 3); tmin.Min(verts, v2 * 3); tmax.Max(verts, v1 * 3); @@ -269,9 +265,9 @@ namespace DotRecast.Recast int p1 = inRow + 7 * 3; int p2 = p1 + 7 * 3; - RcVec3f.Copy(buf, 0, verts, v0 * 3); - RcVec3f.Copy(buf, 3, verts, v1 * 3); - RcVec3f.Copy(buf, 6, verts, v2 * 3); + RcVecUtils.Copy(buf, 0, verts, v0 * 3); + RcVecUtils.Copy(buf, 3, verts, v1 * 3); + RcVecUtils.Copy(buf, 6, verts, v2 * 3); int nvRow, nvIn = 3; for (int z = z0; z <= z1; ++z)