docs: def merge_vertical_lines(lines, tol=TOLERANCE):
      """
      This function merges lines segment when they are vertically aligned
      :param lines: list of lines coordinates (top, left, bottom, right)
      :return: list of merged lines coordinates
      """
      if len(lines) == 0:
          return []
      merged_lines = [lines[0]]
      for line in lines[1:]:
          last_line = merged_lines[-1]
          if line[1] == last_line[1]:  # lines are vertically aligned
              if line[0] <= last_line[2] + tol:  # lines intersect
                  y0, x0, y1, x1 = merged_lines[-1]
                  merged_lines[-1] = (y0, x0, line[2], x1)
              else:
                  merged_lines.append(
                      line
                  )  # lines are vertically aligned but do not intersect
          else:
              merged_lines.append(line)
      return merged_lines