public CoverNode <T> FindContainingField(SpatialObj <T> rect, CoverNode <T> starting_node) { if (starting_node.IsPointInNode(rect.boundingBox.Center)) { bool contained_in_node = starting_node.IsObjectInNode(rect); if (contained_in_node && !starting_node.CanSink(rect)) { return(starting_node); } foreach (CoverNode <T> child in starting_node.GetChildren()) { var potential_node = FindContainingField(rect, child); if (potential_node != null) { return(potential_node); } } if (contained_in_node) { return(starting_node); } } return(null); }