remove nullable float at DtUtils.ClosestHeightPointTriangle

This commit is contained in:
ikpil 2023-07-31 10:38:14 +09:00
parent 71838af06c
commit 123640627a
2 changed files with 8 additions and 9 deletions

View File

@ -1276,8 +1276,7 @@ namespace DotRecast.Detour
} }
} }
float? h = DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2]); if (DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2], out var h))
if (null != h)
{ {
return h; return h;
} }
@ -1298,8 +1297,7 @@ namespace DotRecast.Detour
v[k + 1].z = tile.data.verts[poly.verts[j + k] * 3 + 2]; v[k + 1].z = tile.data.verts[poly.verts[j + k] * 3 + 2];
} }
float? h = DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2]); if (DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2], out var h))
if (null != h)
{ {
return h; return h;
} }

View File

@ -209,10 +209,11 @@ namespace DotRecast.Detour
}; };
} }
public static float? ClosestHeightPointTriangle(RcVec3f p, RcVec3f a, RcVec3f b, RcVec3f c) public static bool ClosestHeightPointTriangle(RcVec3f p, RcVec3f a, RcVec3f b, RcVec3f c, out float h)
{ {
const float EPS = 1e-6f; const float EPS = 1e-6f;
h = 0;
RcVec3f v0 = c.Subtract(a); RcVec3f v0 = c.Subtract(a);
RcVec3f v1 = b.Subtract(a); RcVec3f v1 = b.Subtract(a);
RcVec3f v2 = p.Subtract(a); RcVec3f v2 = p.Subtract(a);
@ -221,7 +222,7 @@ namespace DotRecast.Detour
float denom = v0.x * v1.z - v0.z * v1.x; float denom = v0.x * v1.z - v0.z * v1.x;
if (Math.Abs(denom) < EPS) if (Math.Abs(denom) < EPS)
{ {
return null; return false;
} }
float u = v1.z * v2.x - v1.x * v2.z; float u = v1.z * v2.x - v1.x * v2.z;
@ -237,11 +238,11 @@ namespace DotRecast.Detour
// If point lies inside the triangle, return interpolated ycoord. // If point lies inside the triangle, return interpolated ycoord.
if (u >= 0.0f && v >= 0.0f && (u + v) <= denom) if (u >= 0.0f && v >= 0.0f && (u + v) <= denom)
{ {
float h = a.y + (v0.y * u + v1.y * v) / denom; h = a.y + (v0.y * u + v1.y * v) / denom;
return h; return true;
} }
return null; return false;
} }
public static RcVec2f ProjectPoly(RcVec3f axis, float[] poly, int npoly) public static RcVec2f ProjectPoly(RcVec3f axis, float[] poly, int npoly)