Skip to content

Commit

Permalink
Replace LINQ with simple loop in hot path (#337)
Browse files Browse the repository at this point in the history
- fix typo
  • Loading branch information
FroggieFrog committed Jun 11, 2021
1 parent 330ceba commit 25d93d9
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions AnnoDesigner.Core/DataStructures/QuadTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public Quadrant(Rect extent)
isDirty = false;

var w = Extent.Width / 2;
var h = Extent.Width / 2;
var h = Extent.Height / 2;

topRightBounds = new Rect(Extent.Left + w, Extent.Top, w, h);
topLeftBounds = new Rect(Extent.Left, Extent.Top, w, h);
Expand Down Expand Up @@ -152,20 +152,35 @@ public void GetItemsIntersecting(List<T> items, Rect bounds)
{
topRight.GetItemsIntersecting(items, bounds);
}

if (topLeft != null && topLeft.Extent.IntersectsWith(bounds))
{
topLeft.GetItemsIntersecting(items, bounds);
}

if (bottomRight != null && bottomRight.Extent.IntersectsWith(bounds))
{
bottomRight.GetItemsIntersecting(items, bounds);
}

if (bottomLeft != null && bottomLeft.Extent.IntersectsWith(bounds))
{
bottomLeft.GetItemsIntersecting(items, bounds);
}

//add all the items in this quadrant that intersect the given bounds
items.AddRange(ItemsInQuadrant.Where(_ => _.Bounds.IntersectsWith(bounds)).Select(_ => _.Item));
items.AddRange(GetIntersectingItmesInQuadrant(bounds));
}

private IEnumerable<T> GetIntersectingItmesInQuadrant(Rect boundsToCheck)
{
foreach (var (Item, Bounds) in ItemsInQuadrant)
{
if (Bounds.IntersectsWith(boundsToCheck))
{
yield return Item;
}
}
}

/// <summary>
Expand Down

0 comments on commit 25d93d9

Please sign in to comment.