remove nullable float in GetPolyHeight

This commit is contained in:
ikpil 2023-08-02 23:43:56 +09:00
parent bc3e8cd7bd
commit dab3a9e020
3 changed files with 21 additions and 18 deletions

View File

@ -1221,13 +1221,15 @@ namespace DotRecast.Detour
return RcVec3f.Lerp(pmin, pmax, tmin);
}
public float? GetPolyHeight(DtMeshTile tile, DtPoly poly, RcVec3f pos)
public bool GetPolyHeight(DtMeshTile tile, DtPoly poly, RcVec3f pos, out float height)
{
height = 0;
// Off-mesh connections do not have detail polys and getting height
// over them does not make sense.
if (poly.GetPolyType() == DtPoly.DT_POLYTYPE_OFFMESH_CONNECTION)
{
return null;
return false;
}
int ip = poly.index;
@ -1241,7 +1243,7 @@ namespace DotRecast.Detour
if (!DtUtils.PointInPolygon(pos, verts, nv))
{
return null;
return false;
}
// Find height at the location.
@ -1278,7 +1280,8 @@ namespace DotRecast.Detour
if (DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2], out var h))
{
return h;
height = h;
return true;
}
}
}
@ -1299,7 +1302,8 @@ namespace DotRecast.Detour
if (DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2], out var h))
{
return h;
height = h;
return true;
}
}
}
@ -1309,7 +1313,8 @@ namespace DotRecast.Detour
// closest. This should almost never happen so the extra iteration here is
// ok.
var closest = ClosestPointOnDetailEdges(tile, poly, pos, false);
return closest.y;
height = closest.y;
return true;
}
public void ClosestPointOnPoly(long refs, RcVec3f pos, out RcVec3f closest, out bool posOverPoly)
@ -1317,10 +1322,9 @@ namespace DotRecast.Detour
GetTileAndPolyByRefUnsafe(refs, out var tile, out var poly);
closest = pos;
float? h = GetPolyHeight(tile, poly, pos);
if (null != h)
if (GetPolyHeight(tile, poly, pos, out var h))
{
closest.y = h.Value;
closest.y = h;
posOverPoly = true;
return;
}

View File

@ -551,11 +551,12 @@ namespace DotRecast.Detour
return DtStatus.DT_SUCCSESS;
}
float? h = m_nav.GetPolyHeight(tile, poly, pos);
if (!h.HasValue)
if (!m_nav.GetPolyHeight(tile, poly, pos, out var h))
{
return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;
}
height = h.Value;
height = h;
return DtStatus.DT_SUCCSESS;
}
@ -3424,6 +3425,7 @@ namespace DotRecast.Detour
curNode = nextNode;
} while (curNode != null);
path.Reverse();
return DtStatus.DT_SUCCSESS;
}

View File

@ -365,8 +365,7 @@ namespace DotRecast.Recast
return s;
}
private static float[] SlabsCylinderIntersection(float[] rectangle, RcVec3f start, RcVec3f end, RcVec3f axis, float radiusSqr,
float[] s)
private static float[] SlabsCylinderIntersection(float[] rectangle, RcVec3f start, RcVec3f end, RcVec3f axis, float radiusSqr, float[] s)
{
if (Math.Min(start.x, end.x) < rectangle[0])
{
@ -702,8 +701,7 @@ namespace DotRecast.Recast
return null;
}
private static float? XSlabSegmentIntersection(float[] rectangle, float x, float y, float z, float dx, float dy, float dz,
float slabX)
private static float? XSlabSegmentIntersection(float[] rectangle, float x, float y, float z, float dx, float dy, float dz, float slabX)
{
float x2 = x + dx;
if ((x < slabX && x2 > slabX) || (x > slabX && x2 < slabX))
@ -719,8 +717,7 @@ namespace DotRecast.Recast
return null;
}
private static float? ZSlabSegmentIntersection(float[] rectangle, float x, float y, float z, float dx, float dy, float dz,
float slabZ)
private static float? ZSlabSegmentIntersection(float[] rectangle, float x, float y, float z, float dx, float dy, float dz, float slabZ)
{
float z2 = z + dz;
if ((z < slabZ && z2 > slabZ) || (z > slabZ && z2 < slabZ))