rename DetourCommon to DtUtils

This commit is contained in:
ikpil 2023-07-31 10:34:20 +09:00
parent 47a93f7ab3
commit 71838af06c
13 changed files with 58 additions and 58 deletions

View File

@ -1141,7 +1141,7 @@ namespace DotRecast.Detour.Crowd
RcVec3f[] s = ag.boundary.GetSegment(j);
RcVec3f s3 = s[1];
//Array.Copy(s, 3, s3, 0, 3);
if (DetourCommon.TriArea2D(ag.npos, s[0], s3) < 0.0f)
if (DtUtils.TriArea2D(ag.npos, s[0], s3) < 0.0f)
{
continue;
}

View File

@ -122,7 +122,7 @@ namespace DotRecast.Detour.Crowd
var s3 = s.vmax;
// Skip too distant segments.
var distSqr = DetourCommon.DistancePtSegSqr2D(pos, s0, s3, out var tseg);
var distSqr = DtUtils.DistancePtSegSqr2D(pos, s0, s3, out var tseg);
if (distSqr > Sqr(collisionQueryRange))
{
continue;

View File

@ -131,7 +131,7 @@ namespace DotRecast.Detour.Crowd
cir.dp.Normalize();
dv = cir.dvel.Subtract(dvel);
float a = DetourCommon.TriArea2D(orig, cir.dp, dv);
float a = DtUtils.TriArea2D(orig, cir.dp, dv);
if (a < 0.01f)
{
cir.np.x = -cir.dp.z;
@ -150,7 +150,7 @@ namespace DotRecast.Detour.Crowd
// Precalc if the agent is really close to the segment.
float r = 0.01f;
var distSqr = DetourCommon.DistancePtSegSqr2D(pos, seg.p, seg.q, out var t);
var distSqr = DtUtils.DistancePtSegSqr2D(pos, seg.p, seg.q, out var t);
seg.touch = distSqr < Sqr(r);
}
}

View File

@ -120,7 +120,7 @@ namespace DotRecast.Detour.TileCache
m_tcomp = tcomp;
m_tmproc = tmprocs;
m_tileLutSize = DetourCommon.NextPow2(m_params.maxTiles / 4);
m_tileLutSize = DtUtils.NextPow2(m_params.maxTiles / 4);
if (m_tileLutSize == 0)
{
m_tileLutSize = 1;
@ -136,7 +136,7 @@ namespace DotRecast.Detour.TileCache
m_nextFreeTile = m_tiles[i];
}
m_tileBits = DetourCommon.Ilog2(DetourCommon.NextPow2(m_params.maxTiles));
m_tileBits = DtUtils.Ilog2(DtUtils.NextPow2(m_params.maxTiles));
m_saltBits = Math.Min(31, 32 - m_tileBits);
if (m_saltBits < 10)
{
@ -458,7 +458,7 @@ namespace DotRecast.Detour.TileCache
RcVec3f tbmin = new RcVec3f();
RcVec3f tbmax = new RcVec3f();
CalcTightTileBounds(tile.header, ref tbmin, ref tbmax);
if (DetourCommon.OverlapBounds(bmin, bmax, tbmin, tbmax))
if (DtUtils.OverlapBounds(bmin, bmax, tbmin, tbmax))
{
results.Add(i);
}

View File

@ -61,8 +61,8 @@ namespace DotRecast.Detour
RcVec3f B = b.Subtract(b1);
float cross = B.x * A.z - A.x * B.z; // TriArea2D({0, 0}, A, B);
float aHB = DetourCommon.TriArea2D(b1, b, a);
float bHA = DetourCommon.TriArea2D(a1, a, b);
float aHB = DtUtils.TriArea2D(b1, b, a);
float bHA = DtUtils.TriArea2D(a1, a, b);
if (Math.Abs(cross) < EPSILON)
{
cross = 0f;
@ -233,7 +233,7 @@ namespace DotRecast.Detour
private static Intersection SegSegInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q)
{
if (DetourCommon.IntersectSegSeg2D(a, b, c, d, out var s, out var t))
if (DtUtils.IntersectSegSeg2D(a, b, c, d, out var s, out var t))
{
if (s >= 0.0f && s <= 1.0f && t >= 0.0f && t <= 1.0f)
{

View File

@ -95,7 +95,7 @@ namespace DotRecast.Detour
// Init tiles
m_maxTiles = option.maxTiles;
m_maxVertPerPoly = maxVertsPerPoly;
m_tileLutMask = Math.Max(1, DetourCommon.NextPow2(option.maxTiles)) - 1;
m_tileLutMask = Math.Max(1, DtUtils.NextPow2(option.maxTiles)) - 1;
m_tiles = new DtMeshTile[m_maxTiles];
for (int i = 0; i < m_maxTiles; i++)
{
@ -366,7 +366,7 @@ namespace DotRecast.Detour
while (nodeIndex < end)
{
DtBVNode node = tile.data.bvTree[nodeIndex];
bool overlap = DetourCommon.OverlapQuantBounds(bmin, bmax, node.bmin, node.bmax);
bool overlap = DtUtils.OverlapQuantBounds(bmin, bmax, node.bmin, node.bmax);
bool isLeafNode = node.i >= 0;
if (isLeafNode && overlap)
@ -412,7 +412,7 @@ namespace DotRecast.Detour
bmax.Max(tile.data.verts, v);
}
if (DetourCommon.OverlapBounds(qmin, qmax, bmin, bmax))
if (DtUtils.OverlapBounds(qmin, qmax, bmin, bmax))
{
polys.Add(@base | (long)i);
}
@ -549,9 +549,9 @@ namespace DotRecast.Detour
for (int j = 0; j < neis.Count; ++j)
{
ConnectExtLinks(tile, neis[j], i);
ConnectExtLinks(neis[j], tile, DetourCommon.OppositeTile(i));
ConnectExtLinks(neis[j], tile, DtUtils.OppositeTile(i));
ConnectExtOffMeshLinks(tile, neis[j], i);
ConnectExtOffMeshLinks(neis[j], tile, DetourCommon.OppositeTile(i));
ConnectExtOffMeshLinks(neis[j], tile, DtUtils.OppositeTile(i));
}
}
@ -755,7 +755,7 @@ namespace DotRecast.Detour
// Create new links
int va = poly.verts[j] * 3;
int vb = poly.verts[(j + 1) % nv] * 3;
int nnei = FindConnectingPolys(tile.data.verts, va, vb, target, DetourCommon.OppositeTile(dir), ref connectPolys);
int nnei = FindConnectingPolys(tile.data.verts, va, vb, target, DtUtils.OppositeTile(dir), ref connectPolys);
foreach (var connectPoly in connectPolys)
{
int idx = AllocLink(tile);
@ -814,7 +814,7 @@ namespace DotRecast.Detour
// Connect off-mesh links.
// We are interested on links which land from target tile to this tile.
int oppositeSide = (side == -1) ? 0xff : DetourCommon.OppositeTile(side);
int oppositeSide = (side == -1) ? 0xff : DtUtils.OppositeTile(side);
for (int i = 0; i < target.data.header.offMeshConCount; ++i)
{
@ -1183,7 +1183,7 @@ namespace DotRecast.Detour
continue;
}
var d = DetourCommon.DistancePtSegSqr2D(pos, v[j], v[k], out var t);
var d = DtUtils.DistancePtSegSqr2D(pos, v[j], v[k], out var t);
if (d < dmin)
{
dmin = d;
@ -1207,7 +1207,7 @@ namespace DotRecast.Detour
v[1].y = tile.data.verts[poly.verts[k] * 3 + 1];
v[1].z = tile.data.verts[poly.verts[k] * 3 + 2];
var d = DetourCommon.DistancePtSegSqr2D(pos, v[0], v[1], out var t);
var d = DtUtils.DistancePtSegSqr2D(pos, v[0], v[1], out var t);
if (d < dmin)
{
dmin = d;
@ -1239,7 +1239,7 @@ namespace DotRecast.Detour
Array.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3);
}
if (!DetourCommon.PointInPolygon(pos, verts, nv))
if (!DtUtils.PointInPolygon(pos, verts, nv))
{
return null;
}
@ -1276,7 +1276,7 @@ namespace DotRecast.Detour
}
}
float? h = DetourCommon.ClosestHeightPointTriangle(pos, v[0], v[1], v[2]);
float? h = DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2]);
if (null != h)
{
return h;
@ -1298,7 +1298,7 @@ namespace DotRecast.Detour
v[k + 1].z = tile.data.verts[poly.verts[j + k] * 3 + 2];
}
float? h = DetourCommon.ClosestHeightPointTriangle(pos, v[0], v[1], v[2]);
float? h = DtUtils.ClosestHeightPointTriangle(pos, v[0], v[1], v[2]);
if (null != h)
{
return h;
@ -1336,7 +1336,7 @@ namespace DotRecast.Detour
var v0 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
i = poly.verts[1] * 3;
var v1 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var t);
DtUtils.DistancePtSegSqr2D(pos, v0, v1, out var t);
closest = RcVec3f.Lerp(v0, v1, t);
return;
}

View File

@ -144,7 +144,7 @@ namespace DotRecast.Detour
int va = p.verts[0] * 3;
int vb = p.verts[j - 1] * 3;
int vc = p.verts[j] * 3;
polyArea += DetourCommon.TriArea2D(tile.data.verts, va, vb, vc);
polyArea += DtUtils.TriArea2D(tile.data.verts, va, vb, vc);
}
// Choose random polygon weighted by area, using reservoi sampling.
@ -174,7 +174,7 @@ namespace DotRecast.Detour
float s = frand.Next();
float t = frand.Next();
var pt = DetourCommon.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t);
var pt = DtUtils.RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t);
ClosestPointOnPoly(polyRef, pt, out var closest, out var _);
randomRef = polyRef;
@ -297,7 +297,7 @@ namespace DotRecast.Detour
int va = 0;
int vb = (j - 1) * 3;
int vc = j * 3;
polyArea += DetourCommon.TriArea2D(constrainedVerts, va, vb, vc);
polyArea += DtUtils.TriArea2D(constrainedVerts, va, vb, vc);
}
// Choose random polygon weighted by area, using reservoi sampling.
@ -347,7 +347,7 @@ namespace DotRecast.Detour
}
// If the circle is not touching the next polygon, skip it.
var distSqr = DetourCommon.DistancePtSegSqr2D(centerPos, va, vb, out var tesg);
var distSqr = DtUtils.DistancePtSegSqr2D(centerPos, va, vb, out var tesg);
if (distSqr > radiusSqr)
{
continue;
@ -406,7 +406,7 @@ namespace DotRecast.Detour
float t = frand.Next();
float[] areas = new float[randomPolyVerts.Length / 3];
RcVec3f pt = DetourCommon.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);
RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);
ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _);
randomRef = randomPolyRef;
@ -485,7 +485,7 @@ namespace DotRecast.Detour
Array.Copy(tile.data.verts, poly.verts[i] * 3, verts, i * 3, 3);
}
if (DetourCommon.DistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
if (DtUtils.DistancePtPolyEdgesSqr(pos, verts, nv, edged, edget))
{
closest = pos;
}
@ -545,7 +545,7 @@ namespace DotRecast.Detour
var v0 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
i = poly.verts[1] * 3;
var v1 = new RcVec3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
DetourCommon.DistancePtSegSqr2D(pos, v0, v1, out var t);
DtUtils.DistancePtSegSqr2D(pos, v0, v1, out var t);
height = v0.y + (v1.y - v0.y) * t;
return DtStatus.DT_SUCCSESS;
@ -624,7 +624,7 @@ namespace DotRecast.Detour
while (nodeIndex < end)
{
DtBVNode node = tile.data.bvTree[nodeIndex];
bool overlap = DetourCommon.OverlapQuantBounds(bmin, bmax, node.bmin, node.bmax);
bool overlap = DtUtils.OverlapQuantBounds(bmin, bmax, node.bmin, node.bmax);
bool isLeafNode = node.i >= 0;
if (isLeafNode && overlap)
@ -678,7 +678,7 @@ namespace DotRecast.Detour
bmax.Max(tile.data.verts, v);
}
if (DetourCommon.OverlapBounds(qmin, qmax, bmin, bmax))
if (DtUtils.OverlapBounds(qmin, qmax, bmin, bmax))
{
query.Process(tile, p, refs);
}
@ -1435,7 +1435,7 @@ namespace DotRecast.Detour
protected DtStatus AppendVertex(RcVec3f pos, int flags, long refs, ref List<StraightPathItem> straightPath,
int maxStraightPath)
{
if (straightPath.Count > 0 && DetourCommon.VEqual(straightPath[straightPath.Count - 1].pos, pos))
if (straightPath.Count > 0 && DtUtils.VEqual(straightPath[straightPath.Count - 1].pos, pos))
{
// The vertices are equal, update flags and poly.
straightPath[straightPath.Count - 1] = new StraightPathItem(straightPath[straightPath.Count - 1].pos, flags, refs);
@ -1497,7 +1497,7 @@ namespace DotRecast.Detour
}
// Append intersection
if (DetourCommon.IntersectSegSeg2D(startPos, endPos, left, right, out var _, out var t))
if (DtUtils.IntersectSegSeg2D(startPos, endPos, left, right, out var _, out var t))
{
var pt = RcVec3f.Lerp(left, right, t);
stat = AppendVertex(pt, 0, path[i + 1], ref straightPath, maxStraightPath);
@ -1622,7 +1622,7 @@ namespace DotRecast.Detour
// If starting really close the portal, advance.
if (i == 0)
{
var distSqr = DetourCommon.DistancePtSegSqr2D(portalApex, left, right, out var t);
var distSqr = DtUtils.DistancePtSegSqr2D(portalApex, left, right, out var t);
if (distSqr < Sqr(0.001f))
{
continue;
@ -1638,9 +1638,9 @@ namespace DotRecast.Detour
}
// Right vertex.
if (DetourCommon.TriArea2D(portalApex, portalRight, right) <= 0.0f)
if (DtUtils.TriArea2D(portalApex, portalRight, right) <= 0.0f)
{
if (DetourCommon.VEqual(portalApex, portalRight) || DetourCommon.TriArea2D(portalApex, portalLeft, right) > 0.0f)
if (DtUtils.VEqual(portalApex, portalRight) || DtUtils.TriArea2D(portalApex, portalLeft, right) > 0.0f)
{
portalRight = right;
rightPolyRef = (i + 1 < path.Count) ? path[i + 1] : 0;
@ -1694,9 +1694,9 @@ namespace DotRecast.Detour
}
// Left vertex.
if (DetourCommon.TriArea2D(portalApex, portalLeft, left) >= 0.0f)
if (DtUtils.TriArea2D(portalApex, portalLeft, left) >= 0.0f)
{
if (DetourCommon.VEqual(portalApex, portalLeft) || DetourCommon.TriArea2D(portalApex, portalRight, left) < 0.0f)
if (DtUtils.VEqual(portalApex, portalLeft) || DtUtils.TriArea2D(portalApex, portalRight, left) < 0.0f)
{
portalLeft = left;
leftPolyRef = (i + 1 < path.Count) ? path[i + 1] : 0;
@ -1853,7 +1853,7 @@ namespace DotRecast.Detour
}
// If target is inside the poly, stop search.
if (DetourCommon.PointInPolygon(endPos, verts, nverts))
if (DtUtils.PointInPolygon(endPos, verts, nverts))
{
bestNode = curNode;
bestPos = endPos;
@ -1906,7 +1906,7 @@ namespace DotRecast.Detour
// Wall edge, calc distance.
int vj = j * 3;
int vi = i * 3;
var distSqr = DetourCommon.DistancePtSegSqr2D(endPos, verts, vj, vi, out var tseg);
var distSqr = DtUtils.DistancePtSegSqr2D(endPos, verts, vj, vi, out var tseg);
if (distSqr < bestDist)
{
// Update nearest distance.
@ -1930,7 +1930,7 @@ namespace DotRecast.Detour
// TODO: Maybe should use GetPortalPoints(), but this one is way faster.
int vj = j * 3;
int vi = i * 3;
var distSqr = DetourCommon.DistancePtSegSqr2D(searchPos, verts, vj, vi, out var _);
var distSqr = DtUtils.DistancePtSegSqr2D(searchPos, verts, vj, vi, out var _);
if (distSqr > searchRadSqr)
{
continue;
@ -2124,7 +2124,7 @@ namespace DotRecast.Detour
}
float t = 0.5f;
if (DetourCommon.IntersectSegSeg2D(fromPos, toPos, left, right, out var _, out var t2))
if (DtUtils.IntersectSegSeg2D(fromPos, toPos, left, right, out var _, out var t2))
{
t = Clamp(t2, 0.1f, 0.9f);
}
@ -2233,7 +2233,7 @@ namespace DotRecast.Detour
nv++;
}
bool intersects = DetourCommon.IntersectSegmentPoly2D(startPos, endPos, verts, nv, out var tmin, out var tmax, out var segMin, out var segMax);
bool intersects = DtUtils.IntersectSegmentPoly2D(startPos, endPos, verts, nv, out var tmin, out var tmax, out var segMin, out var segMax);
if (!intersects)
{
// Could not hit the polygon, keep the old t and report hit.
@ -2541,7 +2541,7 @@ namespace DotRecast.Detour
}
// If the circle is not touching the next polygon, skip it.
var distSqr = DetourCommon.DistancePtSegSqr2D(centerPos, va, vb, out var _);
var distSqr = DtUtils.DistancePtSegSqr2D(centerPos, va, vb, out var _);
if (distSqr > radiusSqr)
{
continue;
@ -2718,7 +2718,7 @@ namespace DotRecast.Detour
}
// If the poly is not touching the edge to the next polygon, skip the connection it.
bool intersects = DetourCommon.IntersectSegmentPoly2D(va, vb, verts, nverts, out var tmin, out var tmax, out var segMin, out var segMax);
bool intersects = DtUtils.IntersectSegmentPoly2D(va, vb, verts, nverts, out var tmin, out var tmax, out var segMin, out var segMax);
if (!intersects)
{
continue;
@ -2886,7 +2886,7 @@ namespace DotRecast.Detour
}
// If the circle is not touching the next polygon, skip it.
var distSqr = DetourCommon.DistancePtSegSqr2D(centerPos, va, vb, out var _);
var distSqr = DtUtils.DistancePtSegSqr2D(centerPos, va, vb, out var _);
if (distSqr > radiusSqr)
{
continue;
@ -2937,7 +2937,7 @@ namespace DotRecast.Detour
Array.Copy(pastTile.data.verts, pastPoly.verts[k] * 3, pb, k * 3, 3);
}
if (DetourCommon.OverlapPolyPoly2D(pa, npa, pb, npb))
if (DtUtils.OverlapPolyPoly2D(pa, npa, pb, npb))
{
overlap = true;
break;
@ -3227,7 +3227,7 @@ namespace DotRecast.Detour
// Calc distance to the edge.
int vj = bestPoly.verts[j] * 3;
int vi = bestPoly.verts[i] * 3;
var distSqr = DetourCommon.DistancePtSegSqr2D(centerPos, bestTile.data.verts, vj, vi, out var tseg);
var distSqr = DtUtils.DistancePtSegSqr2D(centerPos, bestTile.data.verts, vj, vi, out var tseg);
// Edge is too far, skip.
if (distSqr > radiusSqr)
@ -3268,7 +3268,7 @@ namespace DotRecast.Detour
// Calc distance to the edge.
int va = bestPoly.verts[link.edge] * 3;
int vb = bestPoly.verts[(link.edge + 1) % bestPoly.vertCount] * 3;
var distSqr = DetourCommon.DistancePtSegSqr2D(centerPos, bestTile.data.verts, va, vb, out var tseg);
var distSqr = DtUtils.DistancePtSegSqr2D(centerPos, bestTile.data.verts, va, vb, out var tseg);
// If the circle is not touching the next polygon, skip it.
if (distSqr > radiusSqr)
{

View File

@ -3,7 +3,7 @@ using DotRecast.Core;
namespace DotRecast.Detour
{
public static class DetourCommon
public static class DtUtils
{
private static readonly float EQUAL_THRESHOLD = RcMath.Sqr(1.0f / 16384.0f);

View File

@ -137,8 +137,8 @@ namespace DotRecast.Detour.Io
private long Convert32BitRef(int refs, DtNavMeshParams option)
{
int m_tileBits = DetourCommon.Ilog2(DetourCommon.NextPow2(option.maxTiles));
int m_polyBits = DetourCommon.Ilog2(DetourCommon.NextPow2(option.maxPolys));
int m_tileBits = DtUtils.Ilog2(DtUtils.NextPow2(option.maxTiles));
int m_polyBits = DtUtils.Ilog2(DtUtils.NextPow2(option.maxPolys));
// Only allow 31 salt bits, since the salt mask is calculated using 32bit uint and it will overflow.
int m_saltBits = Math.Min(31, 32 - m_tileBits - m_polyBits);
int saltMask = (1 << m_saltBits) - 1;

View File

@ -52,7 +52,7 @@ namespace DotRecast.Detour
float[] qCircle = Circle(center, radius);
float[] intersection = ConvexConvexIntersection.Intersect(verts, qCircle);
if (intersection == null && DetourCommon.PointInPolygon(center, verts, verts.Length / 3))
if (intersection == null && DtUtils.PointInPolygon(center, verts, verts.Length / 3))
{
// circle inside polygon
return qCircle;

View File

@ -480,7 +480,7 @@ public class CrowdTool : IRcTool
RcVec3f[] s = ag.boundary.GetSegment(j);
RcVec3f s0 = s[0];
RcVec3f s3 = s[1];
if (DetourCommon.TriArea2D(pos, s0, s3) < 0.0f)
if (DtUtils.TriArea2D(pos, s0, s3) < 0.0f)
col = DuDarkenCol(col);
dd.AppendArrow(s[0].x, s[0].y + 0.2f, s[0].z, s[1].x, s[1].z + 0.2f, s[1].z, 0.0f, 0.3f, col);

View File

@ -681,7 +681,7 @@ public class TestNavmeshTool : IRcTool
var v0 = s.vmin;
var s3 = s.vmax;
// Skip too distant segments.
var distSqr = DetourCommon.DistancePtSegSqr2D(m_spos, v0, s3, out var tseg);
var distSqr = DtUtils.DistancePtSegSqr2D(m_spos, v0, s3, out var tseg);
if (distSqr > RcMath.Sqr(m_neighbourhoodRadius))
{
continue;
@ -702,7 +702,7 @@ public class TestNavmeshTool : IRcTool
else
{
int col = DuRGBA(192, 32, 16, 192);
if (DetourCommon.TriArea2D(m_spos, s.vmin, s3) < 0.0f)
if (DtUtils.TriArea2D(m_spos, s.vmin, s3) < 0.0f)
{
col = DuRGBA(96, 32, 16, 192);
}

View File

@ -131,7 +131,7 @@ namespace DotRecast.Recast.DemoTool.Builder
RcUtils.CalcGridSize(geom.GetMeshBoundsMin(), geom.GetMeshBoundsMax(), cellSize, out var gw, out var gh);
int tw = (gw + tileSize - 1) / tileSize;
int th = (gh + tileSize - 1) / tileSize;
int tileBits = Math.Min(DetourCommon.Ilog2(DetourCommon.NextPow2(tw * th)), 14);
int tileBits = Math.Min(DtUtils.Ilog2(DtUtils.NextPow2(tw * th)), 14);
return tileBits;
}