def _kd_search(node: _Node, rectangle: Rectangle, frames: Optional[List[VisualizingFrame]] = None) -> List[Point]: if node.is_leaf: if rectangle.point_inside(node.points[0]): if frames is not None: frames.append((node.points, node.get_lines_from_node()[0])) return node.points else: if frames is not None: frames.append(([], node.get_lines_from_node()[0])) return [] result = [] if frames is not None: frames.append(([], node.get_lines_from_node()[0])) def search_child(child: _Node) -> List[Point]: if child.region <= rectangle: if frames is not None: frames.append((child.points, child.get_lines_from_node()[0])) return child.points elif child.region & rectangle is not None: return _kd_search(child, rectangle, frames=frames) else: return [] if node.right is not None: result.extend(search_child(node.left)) if node.left is not None: result.extend(search_child(node.right)) if frames is not None: frames.append((result, node.get_lines_from_node()[0])) return result
def __find(self, node: _Node, rect: Rectangle, res: List[Point], view): if rect.min_x > node.max_x or rect.max_x < node.min_x or rect.min_y > node.max_y or rect.max_y < node.min_y: return if view is not None: view.visited_quadrants.extend(node.boundary.get_lines()) if node.children is None: if node.pos is not None and rect.point_inside(node.pos): res.append(node.pos) if view is not None: view.points_inside.append(node.pos) view.gen_scene() return if view is not None: view.gen_scene() for ch in node.children: self.__find(ch, rect, res, view)