Added MinBy, MaxBy, MinByOrDefault and MaxByOrDefault methods and replaced calls of the style OrderBy[Descending]().First[OrDefault]() which is not as performant.

This commit is contained in:
RoosterDragon
2014-05-22 01:30:48 +01:00
parent db08357e36
commit 0ea3509ee4
16 changed files with 90 additions and 47 deletions

View File

@@ -35,13 +35,12 @@ namespace OpenRA
public static Actor ClosestTo(this IEnumerable<Actor> actors, Actor a)
{
var pos = a.CenterPosition;
return actors.OrderBy(b => (b.CenterPosition - pos).LengthSquared).FirstOrDefault();
return actors.ClosestTo(a.CenterPosition);
}
public static Actor ClosestTo(this IEnumerable<Actor> actors, WPos pos)
{
return actors.OrderBy(a => (a.CenterPosition - pos).LengthSquared).FirstOrDefault();
return actors.MinByOrDefault(a => (a.CenterPosition - pos).LengthSquared);
}
public static IEnumerable<Actor> FindActorsInCircle(this World world, WPos origin, WRange r)