Add UnionRectangles extension method.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -219,31 +219,6 @@ namespace OpenRA.Traits
|
||||
return partitionedRenderableFrozenActors[p].InBox(RectWithCorners(a, b)).Where(frozenActorIsValid);
|
||||
}
|
||||
|
||||
Rectangle AggregateBounds(IEnumerable<Rectangle> screenBounds)
|
||||
{
|
||||
if (!screenBounds.Any())
|
||||
return Rectangle.Empty;
|
||||
|
||||
var bounds = screenBounds.First();
|
||||
foreach (var b in screenBounds.Skip(1))
|
||||
bounds = Rectangle.Union(bounds, b);
|
||||
|
||||
return bounds;
|
||||
}
|
||||
|
||||
Rectangle AggregateBounds(IEnumerable<int2> vertices)
|
||||
{
|
||||
if (!vertices.Any())
|
||||
return Rectangle.Empty;
|
||||
|
||||
var first = vertices.First();
|
||||
var rect = new Rectangle(first.X, first.Y, 0, 0);
|
||||
foreach (var v in vertices.Skip(1))
|
||||
rect = Rectangle.Union(rect, new Rectangle(v.X, v.Y, 0, 0));
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
public void TickRender()
|
||||
{
|
||||
foreach (var a in addOrUpdateActors)
|
||||
@@ -261,7 +236,7 @@ namespace OpenRA.Traits
|
||||
else
|
||||
partitionedMouseActors.Remove(a);
|
||||
|
||||
var screenBounds = AggregateBounds(a.ScreenBounds(worldRenderer));
|
||||
var screenBounds = a.ScreenBounds(worldRenderer).Union();
|
||||
if (!screenBounds.Size.IsEmpty)
|
||||
{
|
||||
if (partitionedRenderableActors.Contains(a))
|
||||
@@ -298,7 +273,7 @@ namespace OpenRA.Traits
|
||||
else
|
||||
partitionedMouseFrozenActors[kv.Key].Remove(fa);
|
||||
|
||||
var screenBounds = AggregateBounds(fa.ScreenBounds);
|
||||
var screenBounds = fa.ScreenBounds.Union();
|
||||
if (!screenBounds.Size.IsEmpty)
|
||||
{
|
||||
if (partitionedRenderableFrozenActors[kv.Key].Contains(fa))
|
||||
|
||||
Reference in New Issue
Block a user