From ecca198d6f7c288cda54c9aa72e6daffbd2f2db1 Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 6 Sep 2023 00:12:19 +0900 Subject: [PATCH] [Upstream] Minor refactor in RecastMesh.cpp (#661) - https://github.com/recastnavigation/recastnavigation/pull/661 --- src/DotRecast.Recast/RecastContour.cs | 4 ++-- src/DotRecast.Recast/RecastMesh.cs | 26 ++++++++++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/DotRecast.Recast/RecastContour.cs b/src/DotRecast.Recast/RecastContour.cs index 48488d9..93eb4f7 100644 --- a/src/DotRecast.Recast/RecastContour.cs +++ b/src/DotRecast.Recast/RecastContour.cs @@ -489,8 +489,8 @@ namespace DotRecast.Recast p0 = 8; p1 = 12; - if (RecastMesh.Vequal(pverts, d0, p0) || RecastMesh.Vequal(pverts, d1, p0) - || RecastMesh.Vequal(pverts, d0, p1) || RecastMesh.Vequal(pverts, d1, p1)) + if (RecastMesh.VEqual(pverts, d0, p0) || RecastMesh.VEqual(pverts, d1, p0) || + RecastMesh.VEqual(pverts, d0, p1) || RecastMesh.VEqual(pverts, d1, p1)) continue; if (RecastMesh.Intersect(pverts, d0, d1, p0, p1)) diff --git a/src/DotRecast.Recast/RecastMesh.cs b/src/DotRecast.Recast/RecastMesh.cs index d34d47a..6e6710f 100644 --- a/src/DotRecast.Recast/RecastMesh.cs +++ b/src/DotRecast.Recast/RecastMesh.cs @@ -204,13 +204,14 @@ namespace DotRecast.Recast { if (!Collinear(verts, a, b, c)) return false; + // If ab not vertical, check betweenness on x; else on y. if (verts[a + 0] != verts[b + 0]) - return ((verts[a + 0] <= verts[c + 0]) && (verts[c + 0] <= verts[b + 0])) - || ((verts[a + 0] >= verts[c + 0]) && (verts[c + 0] >= verts[b + 0])); - else - return ((verts[a + 2] <= verts[c + 2]) && (verts[c + 2] <= verts[b + 2])) - || ((verts[a + 2] >= verts[c + 2]) && (verts[c + 2] >= verts[b + 2])); + return ((verts[a + 0] <= verts[c + 0]) && (verts[c + 0] <= verts[b + 0])) || + ((verts[a + 0] >= verts[c + 0]) && (verts[c + 0] >= verts[b + 0])); + + return ((verts[a + 2] <= verts[c + 2]) && (verts[c + 2] <= verts[b + 2])) || + ((verts[a + 2] >= verts[c + 2]) && (verts[c + 2] >= verts[b + 2])); } // Returns true iff segments ab and cd intersect, properly or improperly. @@ -218,14 +219,15 @@ namespace DotRecast.Recast { if (IntersectProp(verts, a, b, c, d)) return true; - else if (Between(verts, a, b, c) || Between(verts, a, b, d) || Between(verts, c, d, a) - || Between(verts, c, d, b)) + + if (Between(verts, a, b, c) || Between(verts, a, b, d) || + Between(verts, c, d, a) || Between(verts, c, d, b)) return true; - else - return false; + + return false; } - public static bool Vequal(int[] verts, int a, int b) + public static bool VEqual(int[] verts, int a, int b) { return verts[a + 0] == verts[b + 0] && verts[a + 2] == verts[b + 2]; } @@ -247,7 +249,7 @@ namespace DotRecast.Recast int p0 = (indices[k] & 0x0fffffff) * 4; int p1 = (indices[k1] & 0x0fffffff) * 4; - if (Vequal(verts, d0, p0) || Vequal(verts, d1, p0) || Vequal(verts, d0, p1) || Vequal(verts, d1, p1)) + if (VEqual(verts, d0, p0) || VEqual(verts, d1, p0) || VEqual(verts, d0, p1) || VEqual(verts, d1, p1)) continue; if (Intersect(verts, d0, d1, p0, p1)) @@ -299,7 +301,7 @@ namespace DotRecast.Recast int p0 = (indices[k] & 0x0fffffff) * 4; int p1 = (indices[k1] & 0x0fffffff) * 4; - if (Vequal(verts, d0, p0) || Vequal(verts, d1, p0) || Vequal(verts, d0, p1) || Vequal(verts, d1, p1)) + if (VEqual(verts, d0, p0) || VEqual(verts, d1, p0) || VEqual(verts, d0, p1) || VEqual(verts, d1, p1)) continue; if (IntersectProp(verts, d0, d1, p0, p1))