private IEnumerable <Pair <T> > GetOverlapsImpl(AdaptiveAabbTree <T> otherTree) { #if !POOL_ENUMERABLES var stack = DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Obtain(); stack.Push(new Pair <Node, Node>(_root, otherTree._root)); while (stack.Count > 0) { var nodePair = stack.Pop(); var nodeA = nodePair.First; var nodeB = nodePair.Second; nodeA.IsActive = true; nodeB.IsActive = true; if (nodeA == nodeB) { if (!nodeA.IsLeaf) { SplitIfNecessary(nodeA); stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeA.RightChild)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeA.RightChild)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeA.LeftChild)); } } else if (GeometryHelper.HaveContact(nodeA.Aabb, nodeB.Aabb)) { if (!nodeA.IsLeaf) { if (!nodeB.IsLeaf) { SplitIfNecessary(nodeA); SplitIfNecessary(nodeB); stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.RightChild)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.RightChild)); stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB.LeftChild)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB.LeftChild)); } else { SplitIfNecessary(nodeA); stack.Push(new Pair <Node, Node>(nodeA.RightChild, nodeB)); stack.Push(new Pair <Node, Node>(nodeA.LeftChild, nodeB)); } } else { if (!nodeB.IsLeaf) { SplitIfNecessary(nodeB); stack.Push(new Pair <Node, Node>(nodeA, nodeB.RightChild)); stack.Push(new Pair <Node, Node>(nodeA, nodeB.LeftChild)); } else { // Leaf overlap. var overlap = new Pair <T>(nodeA.Item, nodeB.Item); if (Filter == null || Filter.Filter(overlap)) { yield return(overlap); } } } } } DigitalRune.ResourcePools <Pair <Node, Node> > .Stacks.Recycle(stack); #else // Avoiding garbage: return(GetOverlapsWithTreeWork.Create(this, otherTree)); #endif }
private IEnumerable<Pair<T>> GetOverlapsImpl(DynamicAabbTree<T> otherTree) { var stack = DigitalRune.ResourcePools<Pair<Node, Node>>.Stacks.Obtain(); stack.Push(new Pair<Node, Node>(_root, otherTree._root)); while (stack.Count > 0) { var nodePair = stack.Pop(); var nodeA = nodePair.First; var nodeB = nodePair.Second; if (nodeA == nodeB) { if (!nodeA.IsLeaf) { stack.Push(new Pair<Node, Node>(nodeA.RightChild, nodeA.RightChild)); stack.Push(new Pair<Node, Node>(nodeA.LeftChild, nodeA.RightChild)); stack.Push(new Pair<Node, Node>(nodeA.LeftChild, nodeA.LeftChild)); } } else if (GeometryHelper.HaveContact(nodeA.Aabb, nodeB.Aabb)) { if (!nodeA.IsLeaf) { if (!nodeB.IsLeaf) { stack.Push(new Pair<Node, Node>(nodeA.RightChild, nodeB.RightChild)); stack.Push(new Pair<Node, Node>(nodeA.LeftChild, nodeB.RightChild)); stack.Push(new Pair<Node, Node>(nodeA.RightChild, nodeB.LeftChild)); stack.Push(new Pair<Node, Node>(nodeA.LeftChild, nodeB.LeftChild)); } else { stack.Push(new Pair<Node, Node>(nodeA.RightChild, nodeB)); stack.Push(new Pair<Node, Node>(nodeA.LeftChild, nodeB)); } } else { if (!nodeB.IsLeaf) { stack.Push(new Pair<Node, Node>(nodeA, nodeB.RightChild)); stack.Push(new Pair<Node, Node>(nodeA, nodeB.LeftChild)); } else { // Leaf overlap. var overlap = new Pair<T>(nodeA.Item, nodeB.Item); if (Filter == null || Filter.Filter(overlap)) yield return overlap; } } } } DigitalRune.ResourcePools<Pair<Node, Node>>.Stacks.Recycle(stack); #else // Avoiding garbage: return GetOverlapsWithTreeWork.Create(this, otherTree); }