Add UnionRectangles extension method.

This commit is contained in:
RoosterDragon
2019-06-14 21:05:50 +01:00
committed by abcdefg30
parent 0e6c37d765
commit 31918e8712
7 changed files with 29 additions and 54 deletions

View File

@@ -151,6 +151,26 @@ namespace OpenRA
return xs.ElementAt(r.Next(xs.Count));
}
public static Rectangle Union(this IEnumerable<Rectangle> rects)
{
// PERF: Avoid LINQ.
var first = true;
var result = Rectangle.Empty;
foreach (var rect in rects)
{
if (first)
{
first = false;
result = rect;
continue;
}
result = Rectangle.Union(rect, result);
}
return result;
}
public static float Product(this IEnumerable<float> xs)
{
return xs.Aggregate(1f, (a, x) => a * x);