code: def recursive_xy_divide(elems, avg_font_size):
      
      log = logging.getLogger(__name__)
      log.info(avg_font_size)
      objects = list(elems.mentions)
      objects.extend(elems.segments)
      bboxes = []
  
      # A tree that is a list of its children
      # bboxes can be recursively reconstructed from
      # the leaves
      def divide(objs, bbox, h_split=True, is_single=False):
          """
          Recursive wrapper for splitting a list of objects
          with bounding boxes.
          h_split: whether to split along y axis, otherwise
          we split along x axis.
          """
          if not objs:
              return []
  
          # range start/end indices
          axis = 1 if h_split else 0
  
          intervals, groups = project_onto(objs, axis, avg_font_size)
  
          # base case where we can not actually divide
          single_child = len(groups) == 1
  
          # Can not divide in both X and Y, stop
          if is_single and single_child:
              bboxes.append(bbox)
              return objs
          else:
              children = []
  
              for interval, group in zip(intervals, groups):
                  # Create the bbox for the subgroup
                  sub_bbox = np.array(bbox)
                  sub_bbox[[axis, axis + 2]] = interval
                  # Append the sub-document tree
                  child = divide(group, sub_bbox, not h_split, single_child)
                  children.append(child)
              return children
  
      full_page_bbox = (0, 0, elems.layout.width, elems.layout.height)
      # Filter out invalid objects
      objects = [o for o in objects if inside(full_page_bbox, o.bbox)]
      log.info("avg_font_size for dividing", avg_font_size)
      tree = divide(objects, full_page_bbox) if objects else []
      return bboxes, tree
docs: Recursively group/divide the document by white stripes
      by projecting elements onto alternating axes as intervals.
  
      avg_font_size: the minimum gap size between elements below
      which we consider interval continuous.