remove new int[] in GetPolyMergeValue

This commit is contained in:
ikpil 2023-06-06 12:12:39 +09:00
parent 1d46fe20f1
commit 695fe15a6e
1 changed files with 12 additions and 22 deletions

View File

@ -461,16 +461,16 @@ namespace DotRecast.Recast
- (verts[c + 0] - verts[a + 0]) * (verts[b + 2] - verts[a + 2]) < 0; - (verts[c + 0] - verts[a + 0]) * (verts[b + 2] - verts[a + 2]) < 0;
} }
private static int[] GetPolyMergeValue(int[] polys, int pa, int pb, int[] verts, int nvp) private static int GetPolyMergeValue(int[] polys, int pa, int pb, int[] verts, out int ea, out int eb, int nvp)
{ {
int ea = -1; ea = -1;
int eb = -1; eb = -1;
int na = CountPolyVerts(polys, pa, nvp); int na = CountPolyVerts(polys, pa, nvp);
int nb = CountPolyVerts(polys, pb, nvp); int nb = CountPolyVerts(polys, pb, nvp);
// If the merged polygon would be too big, do not merge. // If the merged polygon would be too big, do not merge.
if (na + nb - 2 > nvp) if (na + nb - 2 > nvp)
return new int[] { -1, ea, eb }; return -1;
// Check if the polygons share an edge. // Check if the polygons share an edge.
@ -480,9 +480,7 @@ namespace DotRecast.Recast
int va1 = polys[pa + (i + 1) % na]; int va1 = polys[pa + (i + 1) % na];
if (va0 > va1) if (va0 > va1)
{ {
int temp = va0; (va0, va1) = (va1, va0);
va0 = va1;
va1 = temp;
} }
for (int j = 0; j < nb; ++j) for (int j = 0; j < nb; ++j)
@ -491,9 +489,7 @@ namespace DotRecast.Recast
int vb1 = polys[pb + (j + 1) % nb]; int vb1 = polys[pb + (j + 1) % nb];
if (vb0 > vb1) if (vb0 > vb1)
{ {
int temp = vb0; (vb0, vb1) = (vb1, vb0);
vb0 = vb1;
vb1 = temp;
} }
if (va0 == vb0 && va1 == vb1) if (va0 == vb0 && va1 == vb1)
@ -507,7 +503,7 @@ namespace DotRecast.Recast
// No common edge, cannot merge. // No common edge, cannot merge.
if (ea == -1 || eb == -1) if (ea == -1 || eb == -1)
return new int[] { -1, ea, eb }; return -1;
// Check to see if the merged polygon would be convex. // Check to see if the merged polygon would be convex.
int va, vb, vc; int va, vb, vc;
@ -516,13 +512,13 @@ namespace DotRecast.Recast
vb = polys[pa + ea]; vb = polys[pa + ea];
vc = polys[pb + (eb + 2) % nb]; vc = polys[pb + (eb + 2) % nb];
if (!Uleft(verts, va * 3, vb * 3, vc * 3)) if (!Uleft(verts, va * 3, vb * 3, vc * 3))
return new int[] { -1, ea, eb }; return -1;
va = polys[pb + (eb + nb - 1) % nb]; va = polys[pb + (eb + nb - 1) % nb];
vb = polys[pb + eb]; vb = polys[pb + eb];
vc = polys[pa + (ea + 2) % na]; vc = polys[pa + (ea + 2) % na];
if (!Uleft(verts, va * 3, vb * 3, vc * 3)) if (!Uleft(verts, va * 3, vb * 3, vc * 3))
return new int[] { -1, ea, eb }; return -1;
va = polys[pa + ea]; va = polys[pa + ea];
vb = polys[pa + (ea + 1) % na]; vb = polys[pa + (ea + 1) % na];
@ -530,7 +526,7 @@ namespace DotRecast.Recast
int dx = verts[va * 3 + 0] - verts[vb * 3 + 0]; int dx = verts[va * 3 + 0] - verts[vb * 3 + 0];
int dy = verts[va * 3 + 2] - verts[vb * 3 + 2]; int dy = verts[va * 3 + 2] - verts[vb * 3 + 2];
return new int[] { dx * dx + dy * dy, ea, eb }; return (dx * dx) + (dy * dy);
} }
private static void MergePolyVerts(int[] polys, int pa, int pb, int ea, int eb, int tmp, int nvp) private static void MergePolyVerts(int[] polys, int pa, int pb, int ea, int eb, int tmp, int nvp)
@ -901,10 +897,7 @@ namespace DotRecast.Recast
for (int k = j + 1; k < npolys; ++k) for (int k = j + 1; k < npolys; ++k)
{ {
int pk = k * nvp; int pk = k * nvp;
int[] veaeb = GetPolyMergeValue(polys, pj, pk, mesh.verts, nvp); var v = GetPolyMergeValue(polys, pj, pk, mesh.verts, out var ea, out var eb, nvp);
int v = veaeb[0];
int ea = veaeb[1];
int eb = veaeb[2];
if (v > bestMergeVal) if (v > bestMergeVal)
{ {
bestMergeVal = v; bestMergeVal = v;
@ -1087,10 +1080,7 @@ namespace DotRecast.Recast
for (int k = j + 1; k < npolys; ++k) for (int k = j + 1; k < npolys; ++k)
{ {
int pk = k * nvp; int pk = k * nvp;
int[] veaeb = GetPolyMergeValue(polys, pj, pk, mesh.verts, nvp); var v = GetPolyMergeValue(polys, pj, pk, mesh.verts, out var ea, out var eb, nvp);
int v = veaeb[0];
int ea = veaeb[1];
int eb = veaeb[2];
if (v > bestMergeVal) if (v > bestMergeVal)
{ {
bestMergeVal = v; bestMergeVal = v;