From 93b6b52b8fa93f77ae0d09ba736b5acc372f9912 Mon Sep 17 00:00:00 2001 From: ikpil Date: Fri, 27 Oct 2023 00:01:52 +0900 Subject: [PATCH] refactor RcVec3f.IsFinite --- src/DotRecast.Core/Numerics/RcVecUtils.cs | 6 ++--- src/DotRecast.Detour/DtNavMeshQuery.cs | 30 +++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/DotRecast.Core/Numerics/RcVecUtils.cs b/src/DotRecast.Core/Numerics/RcVecUtils.cs index 7e82f77..caddbc5 100644 --- a/src/DotRecast.Core/Numerics/RcVecUtils.cs +++ b/src/DotRecast.Core/Numerics/RcVecUtils.cs @@ -225,7 +225,7 @@ namespace DotRecast.Core.Numerics /// @return True if all of the point's components are finite, i.e. not NaN /// or any of the infinities. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsFinite(RcVec3f v) + public static bool IsFinite(this RcVec3f v) { return float.IsFinite(v.X) && float.IsFinite(v.Y) && float.IsFinite(v.Z); } @@ -233,7 +233,7 @@ namespace DotRecast.Core.Numerics /// Checks that the specified vector's 2D components are finite. /// @param[in] v A point. [(x, y, z)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsFinite2D(RcVec3f v) + public static bool IsFinite2D(this RcVec3f v) { return float.IsFinite(v.X) && float.IsFinite(v.Z); } @@ -259,7 +259,7 @@ namespace DotRecast.Core.Numerics verts[v1 + 2] + (verts[v2 + 2] - verts[v1 + 2]) * t ); } - + /// Performs a scaled vector addition. (@p v1 + (@p v2 * @p s)) /// @param[out] dest The result vector. [(x, y, z)] /// @param[in] v1 The base vector. [(x, y, z)] diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index eae3a56..7bfa234 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -205,7 +205,7 @@ namespace DotRecast.Detour randomPt = centerPos; // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVecUtils.IsFinite(centerPos) || maxRadius < 0 + if (!m_nav.IsValidPolyRef(startRef) || !centerPos.IsFinite() || maxRadius < 0 || !float.IsFinite(maxRadius) || null == filter || null == frand) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; @@ -406,7 +406,7 @@ namespace DotRecast.Detour closest = pos; posOverPoly = false; - if (!m_nav.IsValidPolyRef(refs) || !RcVecUtils.IsFinite(pos)) + if (!m_nav.IsValidPolyRef(refs) || !pos.IsFinite()) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } @@ -441,7 +441,7 @@ namespace DotRecast.Detour return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } - if (tile == null || !RcVecUtils.IsFinite(pos)) + if (tile == null || !pos.IsFinite()) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } @@ -502,7 +502,7 @@ namespace DotRecast.Detour return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } - if (!RcVecUtils.IsFinite2D(pos)) + if (!pos.IsFinite2D()) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } @@ -673,7 +673,7 @@ namespace DotRecast.Detour */ public DtStatus QueryPolygons(RcVec3f center, RcVec3f halfExtents, IDtQueryFilter filter, IDtPolyQuery query) { - if (!RcVecUtils.IsFinite(center) || !RcVecUtils.IsFinite(halfExtents) || null == filter) + if (!center.IsFinite() || !halfExtents.IsFinite() || null == filter) { return DtStatus.DT_INVALID_PARAM; } @@ -694,7 +694,7 @@ namespace DotRecast.Detour */ public IList QueryTiles(RcVec3f center, RcVec3f halfExtents) { - if (!RcVecUtils.IsFinite(center) || !RcVecUtils.IsFinite(halfExtents)) + if (!center.IsFinite() || !halfExtents.IsFinite()) { return RcImmutableArray.Empty; } @@ -744,7 +744,7 @@ namespace DotRecast.Detour path.Clear(); // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !RcVecUtils.IsFinite(startPos) || !RcVecUtils.IsFinite(endPos) || null == filter) + if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !startPos.IsFinite() || !endPos.IsFinite() || null == filter) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } @@ -1020,7 +1020,7 @@ namespace DotRecast.Detour m_query.raycastLimitSqr = RcMath.Sqr(raycastLimit); // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !RcVecUtils.IsFinite(startPos) || !RcVecUtils.IsFinite(endPos) || null == filter) + if (!m_nav.IsValidPolyRef(startRef) || !m_nav.IsValidPolyRef(endRef) || !startPos.IsFinite() || !endPos.IsFinite() || null == filter) { return DtStatus.DT_INVALID_PARAM; } @@ -1514,7 +1514,7 @@ namespace DotRecast.Detour ref List straightPath, int maxStraightPath, int options) { - if (!RcVecUtils.IsFinite(startPos) || !RcVecUtils.IsFinite(endPos) || null == straightPath + if (!startPos.IsFinite() || !endPos.IsFinite() || null == straightPath || null == path || 0 == path.Count || path[0] == 0 || maxStraightPath <= 0) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; @@ -1779,8 +1779,8 @@ namespace DotRecast.Detour visited.Clear(); // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVecUtils.IsFinite(startPos) - || !RcVecUtils.IsFinite(endPos) || null == filter) + if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite() + || !endPos.IsFinite() || null == filter) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; } @@ -2165,7 +2165,7 @@ namespace DotRecast.Detour hit = null; // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVecUtils.IsFinite(startPos) || !RcVecUtils.IsFinite(endPos) + if (!m_nav.IsValidPolyRef(startRef) || !startPos.IsFinite() || !endPos.IsFinite() || null == filter || (prevRef != 0 && !m_nav.IsValidPolyRef(prevRef))) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; @@ -2434,7 +2434,7 @@ namespace DotRecast.Detour } // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVecUtils.IsFinite(centerPos) || radius < 0 + if (!m_nav.IsValidPolyRef(startRef) || !centerPos.IsFinite() || radius < 0 || !float.IsFinite(radius) || null == filter) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; @@ -2777,7 +2777,7 @@ namespace DotRecast.Detour ref List resultRef, ref List resultParent) { // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVecUtils.IsFinite(centerPos) || radius < 0 + if (!m_nav.IsValidPolyRef(startRef) || !centerPos.IsFinite() || radius < 0 || !float.IsFinite(radius) || null == filter || null == resultRef || null == resultParent) { @@ -3109,7 +3109,7 @@ namespace DotRecast.Detour hitNormal = RcVec3f.Zero; // Validate input - if (!m_nav.IsValidPolyRef(startRef) || !RcVecUtils.IsFinite(centerPos) || maxRadius < 0 + if (!m_nav.IsValidPolyRef(startRef) || !centerPos.IsFinite() || maxRadius < 0 || !float.IsFinite(maxRadius) || null == filter) { return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM;