import csv


def load_environment_data(filename):
    """
    Loads the environment boundaries and obstacles from a text file
    :param filename: path and name to the file with robot state information
    :return: lists of tuples of coordinates for the environment boundaries and obstacles
    """
    environment_bounds = list()
    obstacles = list()

    with open(filename, 'r', encoding='utf8') as fin:

        reader = csv.reader(fin, skipinitialspace=True, delimiter=',')

        raw_bounds = next(reader)
        while raw_bounds:
            x_coordinate = int(raw_bounds.pop(0))
            y_coordinate = int(raw_bounds.pop(0))
            coordinate = (x_coordinate, y_coordinate)
            environment_bounds.append(coordinate)

        for raw_obstacle in reader:
            temporary_obstacle = list()

            while raw_obstacle:
                x_coordinate = float(raw_obstacle.pop(0))
                y_coordinate = float(raw_obstacle.pop(0))
                coordinate = (x_coordinate, y_coordinate)
                temporary_obstacle.append(coordinate)

            obstacles.append(temporary_obstacle)

    return environment_bounds, obstacles