public bool Collides(IBBox <T> bbox) { var node = _data; if (!node.Intersects(bbox)) { return(false); } var nodesToSearch = new Stack <Node>(); while (node != null) { for (int i = 0, len = node.Children.Count; i < len; i++) { Node child = node.Children[i]; BBox <T> childBBox = child; if (childBBox.Intersects(bbox)) { if (node.Leaf || BBox <T> .Contains(bbox, childBBox)) { return(true); } nodesToSearch.Push(child); } } node = nodesToSearch.Count > 0 ? nodesToSearch.Pop() : null; } return(false); }
public List <IBBox <T> > SearchOrNull(IBBox <T> bbox) { var node = _data; //_cacheListResult.Clear(); //var result = _cacheListResult; var result = new List <IBBox <T> >(); if (!node.Intersects(bbox)) { return(null); } var nodesToSearch = new Stack <Node>(); while (node != null) { for (int i = 0, len = node.Children.Count; i < len; i++) { Node child = node.Children[i]; BBox <T> childBBox = child; if (childBBox.Intersects(bbox)) { if (node.Leaf) { result.Add(child.ExternalObject); } else if (BBox <T> .Contains(bbox, childBBox)) { AllCombine(child, ref result); } else { nodesToSearch.Push(child); } } } node = nodesToSearch.Count > 0 ? nodesToSearch.Pop() : null; } return(result.Count == 0 ? null : result.ToList()); }