Merge pull request #5405 from RoosterDragon/min-max

Added MinBy, MaxBy, etc.
This commit is contained in:
Paul Chote
2014-06-09 17:42:01 +12:00
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)