diff --git a/src/DotRecast.Core/DistSeg.cs b/src/DotRecast.Core/DistSeg.cs new file mode 100644 index 0000000..bd27968 --- /dev/null +++ b/src/DotRecast.Core/DistSeg.cs @@ -0,0 +1,8 @@ +namespace DotRecast.Core +{ + public struct DistSeg + { + public float DistSqr; + public float Seg; + } +} \ No newline at end of file diff --git a/src/DotRecast.Core/RcMath.cs b/src/DotRecast.Core/RcMath.cs index 670d6e9..398848a 100644 --- a/src/DotRecast.Core/RcMath.cs +++ b/src/DotRecast.Core/RcMath.cs @@ -239,9 +239,9 @@ namespace DotRecast.Core c = !c; } - Tuple edet = DistancePtSegSqr2D(pt, verts, vj, vi); - ed[j] = edet.Item1; - et[j] = edet.Item2; + var edet = DistancePtSegSqr2D(pt, verts, vj, vi); + ed[j] = edet.DistSqr; + et[j] = edet.Seg; } return c; @@ -482,7 +482,7 @@ namespace DotRecast.Core } - public static Tuple DistancePtSegSqr2D(Vector3f pt, float[] verts, int p, int q) + public static DistSeg DistancePtSegSqr2D(Vector3f pt, float[] verts, int p, int q) { float pqx = verts[q + 0] - verts[p + 0]; float pqz = verts[q + 2] - verts[p + 2]; @@ -506,7 +506,12 @@ namespace DotRecast.Core dx = verts[p + 0] + t * pqx - pt.x; dz = verts[p + 2] + t * pqz - pt.z; - return Tuple.Create(dx * dx + dz * dz, t); + + return new DistSeg() + { + DistSqr = dx * dx + dz * dz, + Seg = t, + }; } public static int OppositeTile(int side) diff --git a/src/DotRecast.Detour/LegacyNavMeshQuery.cs b/src/DotRecast.Detour/LegacyNavMeshQuery.cs index 9908dab..24a3fd7 100644 --- a/src/DotRecast.Detour/LegacyNavMeshQuery.cs +++ b/src/DotRecast.Detour/LegacyNavMeshQuery.cs @@ -738,9 +738,9 @@ namespace DotRecast.Detour // Calc distance to the edge. int vj = bestPoly.verts[j] * 3; int vi = bestPoly.verts[i] * 3; - Tuple distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, vj, vi); - float distSqr = distseg.Item1; - float tseg = distseg.Item2; + var distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, vj, vi); + float distSqr = distseg.DistSqr; + float tseg = distseg.Seg; // Edge is too far, skip. if (distSqr > radiusSqr) @@ -784,8 +784,8 @@ namespace DotRecast.Detour // Calc distance to the edge. int va = bestPoly.verts[link.edge] * 3; int vb = bestPoly.verts[(link.edge + 1) % bestPoly.vertCount] * 3; - Tuple distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, va, vb); - float distSqr = distseg.Item1; + var distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, va, vb); + float distSqr = distseg.DistSqr; // If the circle is not touching the next polygon, skip it. if (distSqr > radiusSqr) { diff --git a/src/DotRecast.Detour/NavMeshQuery.cs b/src/DotRecast.Detour/NavMeshQuery.cs index 07b4a9d..e63a319 100644 --- a/src/DotRecast.Detour/NavMeshQuery.cs +++ b/src/DotRecast.Detour/NavMeshQuery.cs @@ -1906,9 +1906,9 @@ namespace DotRecast.Detour // Wall edge, calc distance. int vj = j * 3; int vi = i * 3; - Tuple distSeg = DistancePtSegSqr2D(endPos, verts, vj, vi); - float distSqr = distSeg.Item1; - float tseg = distSeg.Item2; + var distSeg = DistancePtSegSqr2D(endPos, verts, vj, vi); + float distSqr = distSeg.DistSqr; + float tseg = distSeg.Seg; if (distSqr < bestDist) { // Update nearest distance. @@ -1932,8 +1932,8 @@ namespace DotRecast.Detour // TODO: Maybe should use GetPortalPoints(), but this one is way faster. int vj = j * 3; int vi = i * 3; - Tuple distseg = DistancePtSegSqr2D(searchPos, verts, vj, vi); - float distSqr = distseg.Item1; + var distseg = DistancePtSegSqr2D(searchPos, verts, vj, vi); + float distSqr = distseg.DistSqr; if (distSqr > searchRadSqr) { continue; @@ -3261,9 +3261,9 @@ namespace DotRecast.Detour // Calc distance to the edge. int vj = bestPoly.verts[j] * 3; int vi = bestPoly.verts[i] * 3; - Tuple distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, vj, vi); - float distSqr = distseg.Item1; - float tseg = distseg.Item2; + var distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, vj, vi); + float distSqr = distseg.DistSqr; + float tseg = distseg.Seg; // Edge is too far, skip. if (distSqr > radiusSqr) @@ -3307,8 +3307,8 @@ namespace DotRecast.Detour // Calc distance to the edge. int va = bestPoly.verts[link.edge] * 3; int vb = bestPoly.verts[(link.edge + 1) % bestPoly.vertCount] * 3; - Tuple distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, va, vb); - float distSqr = distseg.Item1; + var distseg = DistancePtSegSqr2D(centerPos, bestTile.data.verts, va, vb); + float distSqr = distseg.DistSqr; // If the circle is not touching the next polygon, skip it. if (distSqr > radiusSqr) {