(coordinates, tile_extent, mapper_func, all_out_of_bounds_func=None)
return tmp
Recursively traverses the array of coordinates (depth first) and applies the specified function
Recursively traverses the array of coordinates (depth first) and applies the specified function
Recursively traverses the array of coordinates ( depth first ) and applies the specified function
def map_coordinates_recursive(coordinates, tile_extent, mapper_func, all_out_of_bounds_func=None):
    """
    Recursively traverses the array of coordinates (depth first) and applies the specified function
    """
    any_tuples_inside_bounds = False
    tuple_count_on_current_array_depth = 0
    tmp = []
    is_coordinate_tuple = len(coordinates) == 2 and all(isinstance(c, int) for c in coordinates)
    if is_coordinate_tuple:
        newval = mapper_func(coordinates)
        tmp.append(newval)
    else:
        for coord in coordinates:
            is_coordinate_tuple = len(coord) == 2 and all(isinstance(c, int) for c in coord)
            if is_coordinate_tuple:
                tuple_count_on_current_array_depth += 1
                if not any_tuples_inside_bounds and 1 <= coord[0] <= tile_extent and 1 <= coord[1] <= tile_extent:
                    any_tuples_inside_bounds = True

                newval = mapper_func(coord)
                tmp.append(newval)
            else:
                tmp.append(
                    map_coordinates_recursive(
                        coordinates=coord,
                        tile_extent=tile_extent,
                        mapper_func=mapper_func,
                        all_out_of_bounds_func=all_out_of_bounds_func,
                    )
                )

    all_out_of_bounds = tuple_count_on_current_array_depth > 0 and not any_tuples_inside_bounds
    if all_out_of_bounds_func:
        all_out_of_bounds_func(all_out_of_bounds)
    return tmp
def map_coordinates_recursive ( coordinates , tile_extent , mapper_func , all_out_of_bounds_func = None ) : any_tuples_inside_bounds = False tuple_count_on_current_array_depth = 0 tmp = [ ] is_coordinate_tuple = len ( coordinates ) == 2 and all ( isinstance ( c , int ) for c in coordinates ) if is_coordinate_tuple : newval = mapper_func ( coordinates ) tmp . append ( newval ) else : for coord in coordinates : is_coordinate_tuple = len ( coord ) == 2 and all ( isinstance ( c , int ) for c in coord ) if is_coordinate_tuple : tuple_count_on_current_array_depth += 1 if not any_tuples_inside_bounds and 1 <= coord [ 0 ] <= tile_extent and 1 <= coord [ 1 ] <= tile_extent : any_tuples_inside_bounds = True newval = mapper_func ( coord ) tmp . append ( newval ) else : tmp . append ( map_coordinates_recursive ( coordinates = coord , tile_extent = tile_extent , mapper_func = mapper_func , all_out_of_bounds_func = all_out_of_bounds_func , ) ) all_out_of_bounds = tuple_count_on_current_array_depth > 0 and not any_tuples_inside_bounds if all_out_of_bounds_func : all_out_of_bounds_func ( all_out_of_bounds ) return tmp