forked from mirror/DotRecast
changed insert sort
This commit is contained in:
parent
f78b377d26
commit
7f10d5814d
|
@ -5,6 +5,28 @@ namespace DotRecast.Core
|
||||||
{
|
{
|
||||||
public static class CollectionExtensions
|
public static class CollectionExtensions
|
||||||
{
|
{
|
||||||
|
/// Sorts the given data in-place using insertion sort.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @param data The data to sort
|
||||||
|
/// @param dataLength The number of elements in @p data
|
||||||
|
public static void InsertSort(this int[] data)
|
||||||
|
{
|
||||||
|
for (int valueIndex = 1; valueIndex < data.Length; valueIndex++)
|
||||||
|
{
|
||||||
|
int value = data[valueIndex];
|
||||||
|
int insertionIndex;
|
||||||
|
for (insertionIndex = valueIndex - 1; insertionIndex >= 0 && data[insertionIndex] > value; insertionIndex--)
|
||||||
|
{
|
||||||
|
// Shift over values
|
||||||
|
data[insertionIndex + 1] = data[insertionIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Insert the value in sorted order.
|
||||||
|
data[insertionIndex + 1] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
|
public static void ForEach<T>(this IEnumerable<T> collection, Action<T> action)
|
||||||
{
|
{
|
||||||
foreach (var item in collection)
|
foreach (var item in collection)
|
||||||
|
|
|
@ -319,7 +319,8 @@ namespace DotRecast.Recast
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.Sort(neighborAreas);
|
//Array.Sort(neighborAreas);
|
||||||
|
neighborAreas.InsertSort();
|
||||||
areas[spanIndex] = neighborAreas[4];
|
areas[spanIndex] = neighborAreas[4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue