nodes: 0, module; 1, function_definition; 2, function_name:_process; 3, parameters; 4, block; 5, identifier:self; 6, identifier:segments; 7, expression_statement; 8, comment:# sort_f= lambda r: max_line_width*(r[1]/max_line_height)+r[0]; 9, comment:# segments= sorted(segments, key=sort_f); 10, comment:# segments= segments_to_numpy( segments ); 11, comment:# return segments; 12, expression_statement; 13, expression_statement; 14, comment:# prevent overflows; 15, expression_statement; 16, expression_statement; 17, return_statement; 18, comment:"""sort segments in read order - left to right, up to down"""; 19, assignment; 20, assignment; 21, assignment; 22, assignment; 23, subscript; 24, pattern_list; 25, expression_list; 26, identifier:s; 27, call; 28, identifier:order; 29, binary_operator:mlw * (s[:, 1] // mlh) + s[:, 0]; 30, identifier:sort_order; 31, call; 32, identifier:segments; 33, identifier:sort_order; 34, identifier:mlh; 35, identifier:mlw; 36, attribute; 37, attribute; 38, attribute; 39, argument_list; 40, binary_operator:mlw * (s[:, 1] // mlh); 41, subscript; 42, attribute; 43, argument_list; 44, identifier:self; 45, identifier:max_line_height; 46, identifier:self; 47, identifier:max_line_width; 48, identifier:segments; 49, identifier:astype; 50, attribute; 51, identifier:mlw; 52, parenthesized_expression; 53, identifier:s; 54, slice; 55, integer:0; 56, identifier:numpy; 57, identifier:argsort; 58, identifier:order; 59, identifier:numpy; 60, identifier:uint32; 61, binary_operator:s[:, 1] // mlh; 62, subscript; 63, identifier:mlh; 64, identifier:s; 65, slice; 66, integer:1
code: def _process(self, segments):
          """sort segments in read order - left to right, up to down"""
          # sort_f= lambda r: max_line_width*(r[1]/max_line_height)+r[0]
          # segments= sorted(segments, key=sort_f)
          # segments= segments_to_numpy( segments )
          # return segments
          mlh, mlw = self.max_line_height, self.max_line_width
          s = segments.astype(numpy.uint32)  # prevent overflows
          order = mlw * (s[:, 1] // mlh) + s[:, 0]
          sort_order = numpy.argsort(order)
          return segments[sort_order]