def min_depth(node, region): if not region.intersects(QRectF(*node.brect)): return np.inf elif node.is_leaf: return 1 elif node.is_empty: return 1 else: xs, xe, ys, ye = bindices(node, region) children = node.children[xs:xe, ys:ye].ravel() contingency = node.contingencies[xs:xe, ys:ye] if contingency.ndim == 3: contingency = contingency.reshape(-1, contingency.shape[2]) if any(ch is None and np.any(val) for ch, val in zip(children, contingency)): return 1 else: ch_depth = [min_depth(ch, region) + 1 for ch in filter(is_not_none, children.flat)] return min(ch_depth if ch_depth else [1])
def min_depth(node, region): if not region.intersects(QRectF(*node.brect)): return np.inf elif node.is_leaf: return 1 elif node.is_empty: return 1 else: xs, xe, ys, ye = bindices(node, region) children = node.children[xs: xe, ys: ye].ravel() contingency = node.contingencies[xs: xe, ys: ye] if contingency.ndim == 3: contingency = contingency.reshape(-1, contingency.shape[2]) if any(ch is None and np.any(val) for ch, val in zip(children, contingency)): return 1 else: ch_depth = [min_depth(ch, region) + 1 for ch in filter(is_not_none, children.flat)] return min(ch_depth if ch_depth else [1])