refactor: RcVec3f.Copy -> RcVecUtils.Copy

This commit is contained in:
ikpil 2023-10-23 23:11:47 +09:00
parent a9888bd281
commit 0d805b5d07
7 changed files with 31 additions and 52 deletions

View File

@ -438,23 +438,6 @@ namespace DotRecast.Core.Numerics
return float.IsFinite(v.X) && float.IsFinite(v.Z); 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)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly void CopyTo(float[] array) public readonly void CopyTo(float[] array)
{ {

View File

@ -96,5 +96,13 @@ namespace DotRecast.Core.Numerics
dest[1] = v1[2] * v2[0] - v1[0] * v2[2]; dest[1] = v1[2] * v2[0] - v1[0] * v2[2];
dest[2] = v1[0] * v2[1] - v1[1] * v2[0]; 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];
}
} }
} }

View File

@ -57,10 +57,8 @@ namespace DotRecast.Recast.Toolset.Geom
this.faces = faces; this.faces = faces;
normals = new float[faces.Length]; normals = new float[faces.Length];
CalculateNormals(); CalculateNormals();
bmin = RcVec3f.Zero; bmin = new RcVec3f(vertices);
bmax = RcVec3f.Zero; bmax = new RcVec3f(vertices);
RcVec3f.Copy(ref bmin, vertices, 0);
RcVec3f.Copy(ref bmax, vertices, 0);
for (int i = 1; i < vertices.Length / 3; i++) for (int i = 1; i < vertices.Length / 3; i++)
{ {
bmin.Min(vertices, i * 3); bmin.Min(vertices, i * 3);

View File

@ -77,10 +77,8 @@ namespace DotRecast.Recast.Geom
this.faces = faces; this.faces = faces;
normals = new float[faces.Length]; normals = new float[faces.Length];
CalculateNormals(); CalculateNormals();
bmin = RcVec3f.Zero; bmin = new RcVec3f(vertices);
bmax = RcVec3f.Zero; bmax = new RcVec3f(vertices);
RcVec3f.Copy(ref bmin, vertices, 0);
RcVec3f.Copy(ref bmax, vertices, 0);
for (int i = 1; i < vertices.Length / 3; i++) for (int i = 1; i < vertices.Length / 3; i++)
{ {
bmin.Min(vertices, i * 3); bmin.Min(vertices, i * 3);

View File

@ -457,10 +457,8 @@ namespace DotRecast.Recast
int zStride = xSize; // For readability int zStride = xSize; // For readability
// Compute the bounding box of the polygon // Compute the bounding box of the polygon
RcVec3f bmin = new RcVec3f(); RcVec3f bmin = new RcVec3f(verts);
RcVec3f bmax = new RcVec3f(); RcVec3f bmax = new RcVec3f(verts);
RcVec3f.Copy(ref bmin, verts, 0);
RcVec3f.Copy(ref bmax, verts, 0);
for (int i = 3; i < verts.Length; i += 3) for (int i = 3; i < verts.Length; i += 3)
{ {
bmin.Min(verts, i); bmin.Min(verts, i);

View File

@ -178,7 +178,7 @@ namespace DotRecast.Recast
return true; return true;
} }
RcVec3f.Copy(ref c, verts, p1); c = new RcVec3f(verts.AsSpan(p1));
r.Exchange(0f); r.Exchange(0f);
return false; return false;
} }
@ -842,7 +842,7 @@ namespace DotRecast.Recast
for (int i = 0; i < nin; ++i) 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(); tris.Clear();
@ -961,7 +961,7 @@ namespace DotRecast.Recast
{ {
for (int k = nidx - 2; k > 0; --k) 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; hull[nhull++] = nverts;
nverts++; nverts++;
} }
@ -970,7 +970,7 @@ namespace DotRecast.Recast
{ {
for (int k = 1; k < nidx - 1; ++k) 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; hull[nhull++] = nverts;
nverts++; nverts++;
} }
@ -1000,10 +1000,8 @@ namespace DotRecast.Recast
if (sampleDist > 0) if (sampleDist > 0)
{ {
// Create sample locations in a grid. // Create sample locations in a grid.
RcVec3f bmin = new RcVec3f(); RcVec3f bmin = new RcVec3f(@in);
RcVec3f bmax = new RcVec3f(); RcVec3f bmax = new RcVec3f(@in);
RcVec3f.Copy(ref bmin, @in, 0);
RcVec3f.Copy(ref bmax, @in, 0);
for (int i = 1; i < nin; ++i) for (int i = 1; i < nin; ++i)
{ {
bmin.Min(@in, i * 3); bmin.Min(@in, i * 3);
@ -1662,7 +1660,7 @@ namespace DotRecast.Recast
for (int k = 0; k < dm.nverts; ++k) 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++; mesh.nverts++;
} }

View File

@ -25,8 +25,6 @@ using static DotRecast.Recast.RcConstants;
namespace DotRecast.Recast namespace DotRecast.Recast
{ {
public static class RcRasterizations public static class RcRasterizations
{ {
/** /**
@ -179,19 +177,19 @@ namespace DotRecast.Recast
(inVerts[inVertsOffset + inVertA * 3 + 1] - inVerts[inVertsOffset + inVertB * 3 + 1]) * s; (inVerts[inVertsOffset + inVertA * 3 + 1] - inVerts[inVertsOffset + inVertB * 3 + 1]) * s;
inVerts[outVerts1 + poly1Vert * 3 + 2] = inVerts[inVertsOffset + inVertB * 3 + 2] + inVerts[outVerts1 + poly1Vert * 3 + 2] = inVerts[inVertsOffset + inVertB * 3 + 2] +
(inVerts[inVertsOffset + inVertA * 3 + 2] - inVerts[inVertsOffset + inVertB * 3 + 2]) * s; (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++; poly1Vert++;
poly2Vert++; poly2Vert++;
// add the i'th point to the right polygon. Do NOT add points that are on the dividing line // 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 // since these were already added above
if (d[inVertA] > 0) 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++; poly1Vert++;
} }
else if (d[inVertA] < 0) 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++; 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 // add the i'th point to the right polygon. Addition is done even for points on the dividing line
if (d[inVertA] >= 0) 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++; poly1Vert++;
if (d[inVertA] != 0) if (d[inVertA] != 0)
continue; continue;
} }
RcVec3f.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, inVertsOffset + inVertA * 3); RcVecUtils.Copy(inVerts, outVerts2 + poly2Vert * 3, inVerts, inVertsOffset + inVertA * 3);
poly2Vert++; poly2Vert++;
} }
} }
@ -236,13 +234,11 @@ namespace DotRecast.Recast
float cellSize, float inverseCellSize, float inverseCellHeight, float cellSize, float inverseCellSize, float inverseCellHeight,
int flagMergeThreshold) int flagMergeThreshold)
{ {
RcVec3f tmin = new RcVec3f();
RcVec3f tmax = new RcVec3f();
float by = heightfieldBBMax.Y - heightfieldBBMin.Y; float by = heightfieldBBMax.Y - heightfieldBBMin.Y;
// Calculate the bounding box of the triangle. // Calculate the bounding box of the triangle.
RcVec3f.Copy(ref tmin, verts, v0 * 3); RcVec3f tmin = new RcVec3f(verts.AsSpan(v0 * 3));
RcVec3f.Copy(ref tmax, verts, v0 * 3); RcVec3f tmax = new RcVec3f(verts.AsSpan(v0 * 3));
tmin.Min(verts, v1 * 3); tmin.Min(verts, v1 * 3);
tmin.Min(verts, v2 * 3); tmin.Min(verts, v2 * 3);
tmax.Max(verts, v1 * 3); tmax.Max(verts, v1 * 3);
@ -269,9 +265,9 @@ namespace DotRecast.Recast
int p1 = inRow + 7 * 3; int p1 = inRow + 7 * 3;
int p2 = p1 + 7 * 3; int p2 = p1 + 7 * 3;
RcVec3f.Copy(buf, 0, verts, v0 * 3); RcVecUtils.Copy(buf, 0, verts, v0 * 3);
RcVec3f.Copy(buf, 3, verts, v1 * 3); RcVecUtils.Copy(buf, 3, verts, v1 * 3);
RcVec3f.Copy(buf, 6, verts, v2 * 3); RcVecUtils.Copy(buf, 6, verts, v2 * 3);
int nvRow, nvIn = 3; int nvRow, nvIn = 3;
for (int z = z0; z <= z1; ++z) for (int z = z0; z <= z1; ++z)