From 707d91afeadfc4691ff6af118a2bd3f9e217c845 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 23 Sep 2023 07:38:46 +0900 Subject: [PATCH] refactor: clamp --- src/DotRecast.Core/RcMath.cs | 12 ----------- src/DotRecast.Detour.Crowd/DtCrowd.cs | 2 +- .../DtObstacleAvoidanceQuery.cs | 6 +++--- .../Tracking/DtObstacleAvoidanceDebugData.cs | 2 +- src/DotRecast.Detour.Extras/BVTreeBuilder.cs | 13 ++++++------ src/DotRecast.Detour/DtNavMesh.cs | 20 +++++++++---------- src/DotRecast.Detour/DtNavMeshBuilder.cs | 12 +++++------ src/DotRecast.Detour/DtNavMeshQuery.cs | 14 ++++++------- src/DotRecast.Recast.Demo/RecastDemo.cs | 16 +++++++-------- .../Tools/GizmoRenderer.cs | 7 ++++--- .../Gizmos/RcCapsuleGizmo.cs | 3 ++- .../Gizmos/RcCylinderGizmo.cs | 3 ++- src/DotRecast.Recast/RcCompacts.cs | 4 ++-- .../RcFilledVolumeRasterization.cs | 16 +++++++-------- src/DotRecast.Recast/RcMeshDetails.cs | 4 ++-- src/DotRecast.Recast/RcRasterizations.cs | 12 +++++------ 16 files changed, 69 insertions(+), 77 deletions(-) diff --git a/src/DotRecast.Core/RcMath.cs b/src/DotRecast.Core/RcMath.cs index 474ff54..f57d7b1 100644 --- a/src/DotRecast.Core/RcMath.cs +++ b/src/DotRecast.Core/RcMath.cs @@ -30,17 +30,5 @@ namespace DotRecast.Core { return f * f; } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Clamp(float v, float min, float max) - { - return Math.Max(Math.Min(v, max), min); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static int Clamp(int v, int min, int max) - { - return Math.Max(Math.Min(v, max), min); - } } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index 01ad284..ac035c6 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -1351,7 +1351,7 @@ namespace DotRecast.Detour.Crowd private float Tween(float t, float t0, float t1) { - return RcMath.Clamp((t - t0) / (t1 - t0), 0.0f, 1.0f); + return Math.Clamp((t - t0) / (t1 - t0), 0.0f, 1.0f); } } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs b/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs index 97d72b2..9322835 100644 --- a/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs +++ b/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs @@ -243,7 +243,7 @@ namespace DotRecast.Detour.Crowd vab = vab.Subtract(cir.vel); // Side - side += RcMath.Clamp(Math.Min(cir.dp.Dot2D(vab) * 0.5f + 0.5f, cir.np.Dot2D(vab) * 2), 0.0f, 1.0f); + side += Math.Clamp(Math.Min(cir.dp.Dot2D(vab) * 0.5f + 0.5f, cir.np.Dot2D(vab) * 2), 0.0f, 1.0f); nside++; if (!SweepCircleCircle(pos, rad, vab, cir.p, cir.rad, out var htmin, out var htmax)) @@ -410,8 +410,8 @@ namespace DotRecast.Detour.Crowd int nrings = m_params.adaptiveRings; int depth = m_params.adaptiveDepth; - int nd = RcMath.Clamp(ndivs, 1, DT_MAX_PATTERN_DIVS); - int nr = RcMath.Clamp(nrings, 1, DT_MAX_PATTERN_RINGS); + int nd = Math.Clamp(ndivs, 1, DT_MAX_PATTERN_DIVS); + int nr = Math.Clamp(nrings, 1, DT_MAX_PATTERN_RINGS); float da = (1.0f / nd) * DT_PI * 2; float ca = (float)Math.Cos(da); float sa = (float)Math.Sin(da); diff --git a/src/DotRecast.Detour.Crowd/Tracking/DtObstacleAvoidanceDebugData.cs b/src/DotRecast.Detour.Crowd/Tracking/DtObstacleAvoidanceDebugData.cs index 535a72a..7c25954 100644 --- a/src/DotRecast.Detour.Crowd/Tracking/DtObstacleAvoidanceDebugData.cs +++ b/src/DotRecast.Detour.Crowd/Tracking/DtObstacleAvoidanceDebugData.cs @@ -68,7 +68,7 @@ namespace DotRecast.Detour.Crowd.Tracking float penRange = maxPen - minPen; float s = penRange > 0.001f ? (1.0f / penRange) : 1; for (int i = 0; i < n; ++i) - arr[i] = RcMath.Clamp((arr[i] - minPen) * s, 0.0f, 1.0f); + arr[i] = Math.Clamp((arr[i] - minPen) * s, 0.0f, 1.0f); } public void NormalizeSamples() diff --git a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs index 1f2d1e7..bc4e3dc 100644 --- a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs +++ b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: 3. This notice may not be removed or altered from any source distribution. */ +using System; using DotRecast.Core; @@ -50,12 +51,12 @@ namespace DotRecast.Detour.Extras bmax.Max(data.verts, data.polys[i].verts[j] * 3); } - it.bmin[0] = RcMath.Clamp((int)((bmin.x - data.header.bmin.x) * quantFactor), 0, 0x7fffffff); - it.bmin[1] = RcMath.Clamp((int)((bmin.y - data.header.bmin.y) * quantFactor), 0, 0x7fffffff); - it.bmin[2] = RcMath.Clamp((int)((bmin.z - data.header.bmin.z) * quantFactor), 0, 0x7fffffff); - it.bmax[0] = RcMath.Clamp((int)((bmax.x - data.header.bmin.x) * quantFactor), 0, 0x7fffffff); - it.bmax[1] = RcMath.Clamp((int)((bmax.y - data.header.bmin.y) * quantFactor), 0, 0x7fffffff); - it.bmax[2] = RcMath.Clamp((int)((bmax.z - data.header.bmin.z) * quantFactor), 0, 0x7fffffff); + it.bmin[0] = Math.Clamp((int)((bmin.x - data.header.bmin.x) * quantFactor), 0, 0x7fffffff); + it.bmin[1] = Math.Clamp((int)((bmin.y - data.header.bmin.y) * quantFactor), 0, 0x7fffffff); + it.bmin[2] = Math.Clamp((int)((bmin.z - data.header.bmin.z) * quantFactor), 0, 0x7fffffff); + it.bmax[0] = Math.Clamp((int)((bmax.x - data.header.bmin.x) * quantFactor), 0, 0x7fffffff); + it.bmax[1] = Math.Clamp((int)((bmax.y - data.header.bmin.y) * quantFactor), 0, 0x7fffffff); + it.bmax[2] = Math.Clamp((int)((bmax.z - data.header.bmin.z) * quantFactor), 0, 0x7fffffff); } return DtNavMeshBuilder.Subdivide(items, data.header.polyCount, 0, data.header.polyCount, 0, nodes); diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 3117080..da3991a 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -346,12 +346,12 @@ namespace DotRecast.Detour int[] bmin = new int[3]; int[] bmax = new int[3]; // dtClamp query box to world box. - float minx = RcMath.Clamp(qmin.x, tbmin.x, tbmax.x) - tbmin.x; - float miny = RcMath.Clamp(qmin.y, tbmin.y, tbmax.y) - tbmin.y; - float minz = RcMath.Clamp(qmin.z, tbmin.z, tbmax.z) - tbmin.z; - float maxx = RcMath.Clamp(qmax.x, tbmin.x, tbmax.x) - tbmin.x; - float maxy = RcMath.Clamp(qmax.y, tbmin.y, tbmax.y) - tbmin.y; - float maxz = RcMath.Clamp(qmax.z, tbmin.z, tbmax.z) - tbmin.z; + float minx = Math.Clamp(qmin.x, tbmin.x, tbmax.x) - tbmin.x; + float miny = Math.Clamp(qmin.y, tbmin.y, tbmax.y) - tbmin.y; + float minz = Math.Clamp(qmin.z, tbmin.z, tbmax.z) - tbmin.z; + float maxx = Math.Clamp(qmax.x, tbmin.x, tbmax.x) - tbmin.x; + float maxy = Math.Clamp(qmax.y, tbmin.y, tbmax.y) - tbmin.y; + float maxz = Math.Clamp(qmax.z, tbmin.z, tbmax.z) - tbmin.z; // Quantize bmin[0] = (int)(qfac * minx) & 0x7ffffffe; bmin[1] = (int)(qfac * miny) & 0x7ffffffe; @@ -781,8 +781,8 @@ namespace DotRecast.Detour tmax = temp; } - link.bmin = (int)Math.Round(RcMath.Clamp(tmin, 0.0f, 1.0f) * 255.0f); - link.bmax = (int)Math.Round(RcMath.Clamp(tmax, 0.0f, 1.0f) * 255.0f); + link.bmin = (int)Math.Round(Math.Clamp(tmin, 0.0f, 1.0f) * 255.0f); + link.bmax = (int)Math.Round(Math.Clamp(tmax, 0.0f, 1.0f) * 255.0f); } else if (dir == 2 || dir == 6) { @@ -797,8 +797,8 @@ namespace DotRecast.Detour tmax = temp; } - link.bmin = (int)Math.Round(RcMath.Clamp(tmin, 0.0f, 1.0f) * 255.0f); - link.bmax = (int)Math.Round(RcMath.Clamp(tmax, 0.0f, 1.0f) * 255.0f); + link.bmin = (int)Math.Round(Math.Clamp(tmin, 0.0f, 1.0f) * 255.0f); + link.bmax = (int)Math.Round(Math.Clamp(tmax, 0.0f, 1.0f) * 255.0f); } } } diff --git a/src/DotRecast.Detour/DtNavMeshBuilder.cs b/src/DotRecast.Detour/DtNavMeshBuilder.cs index 18762c7..1cedec7 100644 --- a/src/DotRecast.Detour/DtNavMeshBuilder.cs +++ b/src/DotRecast.Detour/DtNavMeshBuilder.cs @@ -171,13 +171,13 @@ namespace DotRecast.Detour } // BV-tree uses cs for all dimensions - it.bmin[0] = RcMath.Clamp((int)((bmin.x - option.bmin.x) * quantFactor), 0, int.MaxValue); - it.bmin[1] = RcMath.Clamp((int)((bmin.y - option.bmin.y) * quantFactor), 0, int.MaxValue); - it.bmin[2] = RcMath.Clamp((int)((bmin.z - option.bmin.z) * quantFactor), 0, int.MaxValue); + it.bmin[0] = Math.Clamp((int)((bmin.x - option.bmin.x) * quantFactor), 0, int.MaxValue); + it.bmin[1] = Math.Clamp((int)((bmin.y - option.bmin.y) * quantFactor), 0, int.MaxValue); + it.bmin[2] = Math.Clamp((int)((bmin.z - option.bmin.z) * quantFactor), 0, int.MaxValue); - it.bmax[0] = RcMath.Clamp((int)((bmax.x - option.bmin.x) * quantFactor), 0, int.MaxValue); - it.bmax[1] = RcMath.Clamp((int)((bmax.y - option.bmin.y) * quantFactor), 0, int.MaxValue); - it.bmax[2] = RcMath.Clamp((int)((bmax.z - option.bmin.z) * quantFactor), 0, int.MaxValue); + it.bmax[0] = Math.Clamp((int)((bmax.x - option.bmin.x) * quantFactor), 0, int.MaxValue); + it.bmax[1] = Math.Clamp((int)((bmax.y - option.bmin.y) * quantFactor), 0, int.MaxValue); + it.bmax[2] = Math.Clamp((int)((bmax.z - option.bmin.z) * quantFactor), 0, int.MaxValue); } else { diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index 2111cbf..4827a6e 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -603,12 +603,12 @@ namespace DotRecast.Detour int[] bmin = new int[3]; int[] bmax = new int[3]; // dtClamp query box to world box. - float minx = RcMath.Clamp(qmin.x, tbmin.x, tbmax.x) - tbmin.x; - float miny = RcMath.Clamp(qmin.y, tbmin.y, tbmax.y) - tbmin.y; - float minz = RcMath.Clamp(qmin.z, tbmin.z, tbmax.z) - tbmin.z; - float maxx = RcMath.Clamp(qmax.x, tbmin.x, tbmax.x) - tbmin.x; - float maxy = RcMath.Clamp(qmax.y, tbmin.y, tbmax.y) - tbmin.y; - float maxz = RcMath.Clamp(qmax.z, tbmin.z, tbmax.z) - tbmin.z; + float minx = Math.Clamp(qmin.x, tbmin.x, tbmax.x) - tbmin.x; + float miny = Math.Clamp(qmin.y, tbmin.y, tbmax.y) - tbmin.y; + float minz = Math.Clamp(qmin.z, tbmin.z, tbmax.z) - tbmin.z; + float maxx = Math.Clamp(qmax.x, tbmin.x, tbmax.x) - tbmin.x; + float maxy = Math.Clamp(qmax.y, tbmin.y, tbmax.y) - tbmin.y; + float maxz = Math.Clamp(qmax.z, tbmin.z, tbmax.z) - tbmin.z; // Quantize bmin[0] = (int)(qfac * minx) & 0x7ffffffe; bmin[1] = (int)(qfac * miny) & 0x7ffffffe; @@ -2125,7 +2125,7 @@ namespace DotRecast.Detour float t = 0.5f; if (DtUtils.IntersectSegSeg2D(fromPos, toPos, left, right, out var _, out var t2)) { - t = RcMath.Clamp(t2, 0.1f, 0.9f); + t = Math.Clamp(t2, 0.1f, 0.9f); } pt = RcVec3f.Lerp(left, right, t); diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index d87306a..df8fa82 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -433,13 +433,13 @@ public class RecastDemo : IRecastDemoChannel _modState |= 0 < tempMoveAccel ? (int)KeyModState.Shift : (int)KeyModState.None; //Logger.Information($"{_modState}"); - _moveFront = RcMath.Clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f); - _moveLeft = RcMath.Clamp(_moveLeft + tempMoveLeft * dt * 4.0f, 0, 2.0f); - _moveBack = RcMath.Clamp(_moveBack + tempMoveBack * dt * 4.0f, 0, 2.0f); - _moveRight = RcMath.Clamp(_moveRight + tempMoveRight * dt * 4.0f, 0, 2.0f); - _moveUp = RcMath.Clamp(_moveUp + tempMoveUp * dt * 4.0f, 0, 2.0f); - _moveDown = RcMath.Clamp(_moveDown + tempMoveDown * dt * 4.0f, 0, 2.0f); - _moveAccel = RcMath.Clamp(_moveAccel + tempMoveAccel * dt * 4.0f, 0, 2.0f); + _moveFront = Math.Clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f); + _moveLeft = Math.Clamp(_moveLeft + tempMoveLeft * dt * 4.0f, 0, 2.0f); + _moveBack = Math.Clamp(_moveBack + tempMoveBack * dt * 4.0f, 0, 2.0f); + _moveRight = Math.Clamp(_moveRight + tempMoveRight * dt * 4.0f, 0, 2.0f); + _moveUp = Math.Clamp(_moveUp + tempMoveUp * dt * 4.0f, 0, 2.0f); + _moveDown = Math.Clamp(_moveDown + tempMoveDown * dt * 4.0f, 0, 2.0f); + _moveAccel = Math.Clamp(_moveAccel + tempMoveAccel * dt * 4.0f, 0, 2.0f); } } @@ -490,7 +490,7 @@ public class RecastDemo : IRecastDemoChannel // Update sample simulation. float SIM_RATE = 20; float DELTA_TIME = 1.0f / SIM_RATE; - timeAcc = RcMath.Clamp((float)(timeAcc + dt), -1.0f, 1.0f); + timeAcc = Math.Clamp((float)(timeAcc + dt), -1.0f, 1.0f); int simIter = 0; while (timeAcc > DELTA_TIME) { diff --git a/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs b/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs index 8a85489..e2acf46 100644 --- a/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs +++ b/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs @@ -1,4 +1,5 @@ -using DotRecast.Core; +using System; +using DotRecast.Core; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset.Gizmos; @@ -50,7 +51,7 @@ public static class GizmoRenderer normal.y = e0.z * e1.x - e0.x * e1.z; normal.z = e0.x * e1.y - e0.y * e1.x; RcVec3f.Normalize(ref normal); - float c = RcMath.Clamp(0.57735026f * (normal.x + normal.y + normal.z), -1, 1); + float c = Math.Clamp(0.57735026f * (normal.x + normal.y + normal.z), -1, 1); int col = DebugDraw.DuLerpCol( DebugDraw.DuRGBA(32, 32, 0, 160), DebugDraw.DuRGBA(220, 220, 0, 160), @@ -139,7 +140,7 @@ public static class GizmoRenderer for (int j = 0; j < 3; j++) { int v = sphere.triangles[i + j] * 3; - float c = RcMath.Clamp(0.57735026f * (sphere.vertices[v] + sphere.vertices[v + 1] + sphere.vertices[v + 2]), -1, 1); + float c = Math.Clamp(0.57735026f * (sphere.vertices[v] + sphere.vertices[v + 1] + sphere.vertices[v + 2]), -1, 1); int col = DebugDraw.DuLerpCol(DebugDraw.DuRGBA(32, 32, 0, 160), DebugDraw.DuRGBA(220, 220, 0, 160), (int)(127 * (1 + c))); debugDraw.Vertex( diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs index 0029338..7025b4c 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs @@ -1,3 +1,4 @@ +using System; using DotRecast.Core; using static DotRecast.Recast.Toolset.Gizmos.RcGizmoHelper; @@ -48,7 +49,7 @@ namespace DotRecast.Recast.Toolset.Gizmos v.y = vertices[i + 1] - center[1]; v.z = vertices[i + 2] - center[2]; RcVec3f.Normalize(ref v); - gradient[i / 3] = RcMath.Clamp(0.57735026f * (v.x + v.y + v.z), -1, 1); + gradient[i / 3] = Math.Clamp(0.57735026f * (v.x + v.y + v.z), -1, 1); } } diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs index 6c37cbf..8161b8d 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs @@ -1,3 +1,4 @@ +using System; using DotRecast.Core; using static DotRecast.Recast.Toolset.Gizmos.RcGizmoHelper; @@ -53,7 +54,7 @@ namespace DotRecast.Recast.Toolset.Gizmos v.y = vertices[i + 1] - center.y; v.z = vertices[i + 2] - center.z; RcVec3f.Normalize(ref v); - gradient[i / 3] = RcMath.Clamp(0.57735026f * (v.x + v.y + v.z), -1, 1); + gradient[i / 3] = Math.Clamp(0.57735026f * (v.x + v.y + v.z), -1, 1); } } } diff --git a/src/DotRecast.Recast/RcCompacts.cs b/src/DotRecast.Recast/RcCompacts.cs index c0a32d1..358b0b7 100644 --- a/src/DotRecast.Recast/RcCompacts.cs +++ b/src/DotRecast.Recast/RcCompacts.cs @@ -93,8 +93,8 @@ namespace DotRecast.Recast { int bot = s.smax; int top = s.next != null ? (int)s.next.smin : MAX_HEIGHT; - chf.spans[idx].y = RcMath.Clamp(bot, 0, MAX_HEIGHT); - chf.spans[idx].h = RcMath.Clamp(top - bot, 0, MAX_HEIGHT); + chf.spans[idx].y = Math.Clamp(bot, 0, MAX_HEIGHT); + chf.spans[idx].h = Math.Clamp(top - bot, 0, MAX_HEIGHT); chf.areas[idx] = s.area; idx++; tmpCount++; diff --git a/src/DotRecast.Recast/RcFilledVolumeRasterization.cs b/src/DotRecast.Recast/RcFilledVolumeRasterization.cs index 268094d..cae3355 100644 --- a/src/DotRecast.Recast/RcFilledVolumeRasterization.cs +++ b/src/DotRecast.Recast/RcFilledVolumeRasterization.cs @@ -222,8 +222,8 @@ namespace DotRecast.Recast int smax = (int)Math.Ceiling((h[1] - hf.bmin.y) * ich); if (smin != smax) { - int ismin = RcMath.Clamp(smin, 0, SPAN_MAX_HEIGHT); - int ismax = RcMath.Clamp(smax, ismin + 1, SPAN_MAX_HEIGHT); + int ismin = Math.Clamp(smin, 0, SPAN_MAX_HEIGHT); + int ismax = Math.Clamp(smax, ismin + 1, SPAN_MAX_HEIGHT); RcRasterizations.AddSpan(hf, x, z, ismin, ismax, area, flagMergeThr); } } @@ -282,12 +282,12 @@ namespace DotRecast.Recast { float[] s = MergeIntersections( RayCylinderIntersection(RcVec3f.Of( - RcMath.Clamp(start.x, rectangle[0], rectangle[2]), rectangle[4], - RcMath.Clamp(start.z, rectangle[1], rectangle[3]) + Math.Clamp(start.x, rectangle[0], rectangle[2]), rectangle[4], + Math.Clamp(start.z, rectangle[1], rectangle[3]) ), start, axis, radiusSqr), RayCylinderIntersection(RcVec3f.Of( - RcMath.Clamp(end.x, rectangle[0], rectangle[2]), rectangle[4], - RcMath.Clamp(end.z, rectangle[1], rectangle[3]) + Math.Clamp(end.x, rectangle[0], rectangle[2]), rectangle[4], + Math.Clamp(end.z, rectangle[1], rectangle[3]) ), start, axis, radiusSqr)); float axisLen2dSqr = axis.x * axis.x + axis.z * axis.z; if (axisLen2dSqr > EPSILON) @@ -398,7 +398,7 @@ namespace DotRecast.Recast { // 2d intersection of plane and segment float t = (x - start.x) / direction.x; - float z = RcMath.Clamp(start.z + t * direction.z, rectangle[1], rectangle[3]); + float z = Math.Clamp(start.z + t * direction.z, rectangle[1], rectangle[3]); return RcVec3f.Of(x, rectangle[4], z); } @@ -411,7 +411,7 @@ namespace DotRecast.Recast { // 2d intersection of plane and segment float t = (z - start.z) / direction.z; - float x = RcMath.Clamp(start.x + t * direction.x, rectangle[0], rectangle[2]); + float x = Math.Clamp(start.x + t * direction.x, rectangle[0], rectangle[2]); return RcVec3f.Of(x, rectangle[4], z); } diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index 3ff77ad..9d05269 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -352,8 +352,8 @@ namespace DotRecast.Recast { int ix = (int)Math.Floor(fx * ics + 0.01f); int iz = (int)Math.Floor(fz * ics + 0.01f); - ix = RcMath.Clamp(ix - hp.xmin, 0, hp.width - 1); - iz = RcMath.Clamp(iz - hp.ymin, 0, hp.height - 1); + ix = Math.Clamp(ix - hp.xmin, 0, hp.width - 1); + iz = Math.Clamp(iz - hp.ymin, 0, hp.height - 1); int h = hp.data[ix + iz * hp.width]; if (h == RC_UNSET_HEIGHT) { diff --git a/src/DotRecast.Recast/RcRasterizations.cs b/src/DotRecast.Recast/RcRasterizations.cs index 151aee3..6c8cb12 100644 --- a/src/DotRecast.Recast/RcRasterizations.cs +++ b/src/DotRecast.Recast/RcRasterizations.cs @@ -258,8 +258,8 @@ namespace DotRecast.Recast int w = heightfield.width; int h = heightfield.height; // use -1 rather than 0 to cut the polygon properly at the start of the tile - z0 = RcMath.Clamp(z0, -1, h - 1); - z1 = RcMath.Clamp(z1, 0, h - 1); + z0 = Math.Clamp(z0, -1, h - 1); + z1 = Math.Clamp(z1, 0, h - 1); // Clip the triangle into all grid cells it touches. float[] buf = new float[7 * 3 * 4]; @@ -304,8 +304,8 @@ namespace DotRecast.Recast continue; } - x0 = RcMath.Clamp(x0, -1, w - 1); - x1 = RcMath.Clamp(x1, 0, w - 1); + x0 = Math.Clamp(x0, -1, w - 1); + x1 = Math.Clamp(x1, 0, w - 1); int nv, nv2 = nvRow; for (int x = x0; x <= x1; ++x) @@ -346,8 +346,8 @@ namespace DotRecast.Recast spanMax = by; // Snap the span to the heightfield height grid. - int spanMinCellIndex = RcMath.Clamp((int)Math.Floor(spanMin * inverseCellHeight), 0, SPAN_MAX_HEIGHT); - int spanMaxCellIndex = RcMath.Clamp((int)Math.Ceiling(spanMax * inverseCellHeight), spanMinCellIndex + 1, SPAN_MAX_HEIGHT); + int spanMinCellIndex = Math.Clamp((int)Math.Floor(spanMin * inverseCellHeight), 0, SPAN_MAX_HEIGHT); + int spanMaxCellIndex = Math.Clamp((int)Math.Ceiling(spanMax * inverseCellHeight), spanMinCellIndex + 1, SPAN_MAX_HEIGHT); AddSpan(heightfield, x, z, spanMinCellIndex, spanMaxCellIndex, area, flagMergeThreshold); }