forked from bit/DotRecastNetSim
add shared comparer
This commit is contained in:
parent
eb077a4e6d
commit
b384133553
|
@ -4,6 +4,12 @@ namespace DotRecast.Detour
|
|||
{
|
||||
public class BVItemXComparer : IComparer<BVItem>
|
||||
{
|
||||
public static readonly BVItemXComparer Shared = new BVItemXComparer();
|
||||
|
||||
private BVItemXComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(BVItem a, BVItem b)
|
||||
{
|
||||
return a.bmin[0].CompareTo(b.bmin[0]);
|
||||
|
|
|
@ -4,6 +4,12 @@ namespace DotRecast.Detour
|
|||
{
|
||||
public class BVItemYComparer : IComparer<BVItem>
|
||||
{
|
||||
public static readonly BVItemYComparer Shared = new BVItemYComparer();
|
||||
|
||||
private BVItemYComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(BVItem a, BVItem b)
|
||||
{
|
||||
return a.bmin[1].CompareTo(b.bmin[1]);
|
||||
|
|
|
@ -4,6 +4,12 @@ namespace DotRecast.Detour
|
|||
{
|
||||
public class BVItemZComparer : IComparer<BVItem>
|
||||
{
|
||||
public static readonly BVItemZComparer Shared = new BVItemZComparer();
|
||||
|
||||
private BVItemZComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(BVItem a, BVItem b)
|
||||
{
|
||||
return a.bmin[2].CompareTo(b.bmin[2]);
|
||||
|
|
|
@ -116,17 +116,17 @@ namespace DotRecast.Detour
|
|||
if (axis == 0)
|
||||
{
|
||||
// Sort along x-axis
|
||||
Array.Sort(items, imin, inum, new BVItemXComparer());
|
||||
Array.Sort(items, imin, inum, BVItemXComparer.Shared);
|
||||
}
|
||||
else if (axis == 1)
|
||||
{
|
||||
// Sort along y-axis
|
||||
Array.Sort(items, imin, inum, new BVItemYComparer());
|
||||
Array.Sort(items, imin, inum, BVItemYComparer.Shared);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Sort along z-axis
|
||||
Array.Sort(items, imin, inum, new BVItemZComparer());
|
||||
Array.Sort(items, imin, inum, BVItemZComparer.Shared);
|
||||
}
|
||||
|
||||
int isplit = imin + inum / 2;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Recast.Geom
|
||||
{
|
||||
public class BoundsItemXComparer : IComparer<BoundsItem>
|
||||
{
|
||||
public static readonly BoundsItemXComparer Shared = new BoundsItemXComparer();
|
||||
|
||||
private BoundsItemXComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(BoundsItem a, BoundsItem b)
|
||||
{
|
||||
return a.bmin.x.CompareTo(b.bmin.x);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Recast.Geom
|
||||
{
|
||||
public class BoundsItemYComparer : IComparer<BoundsItem>
|
||||
{
|
||||
public static readonly BoundsItemYComparer Shared = new BoundsItemYComparer();
|
||||
|
||||
private BoundsItemYComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(BoundsItem a, BoundsItem b)
|
||||
{
|
||||
return a.bmin.y.CompareTo(b.bmin.y);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Recast.Geom
|
||||
{
|
||||
public class CompareItemX : IComparer<BoundsItem>
|
||||
{
|
||||
public int Compare(BoundsItem a, BoundsItem b)
|
||||
{
|
||||
return a.bmin.x.CompareTo(b.bmin.x);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Recast.Geom
|
||||
{
|
||||
public class CompareItemY : IComparer<BoundsItem>
|
||||
{
|
||||
public int Compare(BoundsItem a, BoundsItem b)
|
||||
{
|
||||
return a.bmin.y.CompareTo(b.bmin.y);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -102,12 +102,12 @@ namespace DotRecast.Recast.Geom
|
|||
|
||||
if (axis == 0)
|
||||
{
|
||||
Array.Sort(items, imin, imax - imin, new CompareItemX());
|
||||
Array.Sort(items, imin, imax - imin, BoundsItemXComparer.Shared);
|
||||
// Sort along x-axis
|
||||
}
|
||||
else if (axis == 1)
|
||||
{
|
||||
Array.Sort(items, imin, imax - imin, new CompareItemY());
|
||||
Array.Sort(items, imin, imax - imin, BoundsItemYComparer.Shared);
|
||||
// Sort along y-axis
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,12 @@ namespace DotRecast.Recast
|
|||
{
|
||||
public class RcContourHoleComparer : IComparer<RcContourHole>
|
||||
{
|
||||
public static readonly RcContourHoleComparer Shared = new RcContourHoleComparer();
|
||||
|
||||
private RcContourHoleComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(RcContourHole a, RcContourHole b)
|
||||
{
|
||||
if (a.minx == b.minx)
|
||||
|
|
|
@ -4,6 +4,12 @@ namespace DotRecast.Recast
|
|||
{
|
||||
public class RcPotentialDiagonalComparer : IComparer<RcPotentialDiagonal>
|
||||
{
|
||||
public static readonly RcPotentialDiagonalComparer Shared = new RcPotentialDiagonalComparer();
|
||||
|
||||
private RcPotentialDiagonalComparer()
|
||||
{
|
||||
}
|
||||
|
||||
public int Compare(RcPotentialDiagonal va, RcPotentialDiagonal vb)
|
||||
{
|
||||
RcPotentialDiagonal a = va;
|
||||
|
|
|
@ -619,7 +619,7 @@ namespace DotRecast.Recast
|
|||
region.holes[i].leftmost = minleft[2];
|
||||
}
|
||||
|
||||
Array.Sort(region.holes, new RcContourHoleComparer());
|
||||
Array.Sort(region.holes, RcContourHoleComparer.Shared);
|
||||
|
||||
int maxVerts = region.outline.nverts;
|
||||
for (int i = 0; i < region.nholes; i++)
|
||||
|
@ -665,7 +665,7 @@ namespace DotRecast.Recast
|
|||
}
|
||||
|
||||
// Sort potential diagonals by distance, we want to make the connection as short as possible.
|
||||
Array.Sort(diags, 0, ndiags, new RcPotentialDiagonalComparer());
|
||||
Array.Sort(diags, 0, ndiags, RcPotentialDiagonalComparer.Shared);
|
||||
|
||||
// Find a diagonal that is not intersecting the outline not the remaining holes.
|
||||
index = -1;
|
||||
|
|
Loading…
Reference in New Issue