/**
     * Fill this collision map with a set of rectangles. A rectangle is added to a
     * cell if it overlaps with it (that includes just touching it). Afterwards,
     * each cell of the collision map should contain all rectangles that cover the
     * cell.
     *
     * @param rectangles is a set of rectangles to insert, it must be != null
     * @throws CollisionMapOutOfBoundsException if a rectangle is out of the bounds
     *                                          of this rectangle
     */
private void fillCollisionMap(Set<Rectangle> rectangles) throws CollisionMapOutOfBoundsException {
        // TODO Insert code for assignment 5.2.a
        for(Rectangle rectangle:rectangles){
            if(rectangle.getX() < this.gridRectangle.getX() ||
               rectangle.getX() + rectangle.getWidth() > this.gridRectangle.getX() + this.gridRectangle.getWidth() ||
               rectangle.getY() < this.gridRectangle.getY() ||
               rectangle.getY() + rectangle.getHeight() > this.gridRectangle.getY() + this.gridRectangle.getHeight()
            ){
                throw new CollisionMapOutOfBoundsException("a rectangle is out of the bounds of this rectangle");
            }
            int startX = (int)transformX(rectangle.getX());
            int startY = (int)transformY(rectangle.getY());
            int endX = (int)transformX(rectangle.getX() + rectangle.getWidth());
            if(endX == this.GRID_RESOLUTION_X){
                endX = this.GRID_RESOLUTION_X - 1;
            }
            int endY = (int)transformY(rectangle.getY() + rectangle.getHeight());
            if(endY == this.GRID_RESOLUTION_Y){
                endY = this.GRID_RESOLUTION_Y - 1;
            }
            for(int i = startX; i <= endX; i++){
                for(int j = startY; j<=endY; j++){
                    map[j][i].add(rectangle);
                }
            }
        }
    }
private void fillCollisionMap(Set<Rectangle> rectangles) throws CollisionMapOutOfBoundsException {
// TODO Insert code for assignment 5.2.a
for(Rectangle rectangle:rectangles){
if(rectangle.getX() < this.gridRectangle.getX() ||
rectangle.getX() + rectangle.getWidth() > this.gridRectangle.getX() + this.gridRectangle.getWidth() ||
rectangle.getY() < this.gridRectangle.getY() ||
rectangle.getY() + rectangle.getHeight() > this.gridRectangle.getY() + this.gridRectangle.getHeight()
){
throw new CollisionMapOutOfBoundsException("a rectangle is out of the bounds of this rectangle");
}
int startX = (int)transformX(rectangle.getX());
int startY = (int)transformY(rectangle.getY());
int endX = (int)transformX(rectangle.getX() + rectangle.getWidth());
if(endX == this.GRID_RESOLUTION_X){
endX = this.GRID_RESOLUTION_X - 1;
}
int endY = (int)transformY(rectangle.getY() + rectangle.getHeight());
if(endY == this.GRID_RESOLUTION_Y){
endY = this.GRID_RESOLUTION_Y - 1;
}
for(int i = startX; i <= endX; i++){
for(int j = startY; j<=endY; j++){
map[j][i].add(rectangle);
}
}
}
}
private void fillCollisionMap(Set<Rectangle> rectangles) throws CollisionMapOutOfBoundsException {
// TODO Insert code for assignment 5.2.a
for(Rectangle rectangle:rectangles){
if(rectangle.getX() < this.gridRectangle.getX() ||
rectangle.getX() + rectangle.getWidth() > this.gridRectangle.getX() + this.gridRectangle.getWidth() ||
rectangle.getY() < this.gridRectangle.getY() ||
rectangle.getY() + rectangle.getHeight() > this.gridRectangle.getY() + this.gridRectangle.getHeight()
){
throw new CollisionMapOutOfBoundsException("a rectangle is out of the bounds of this rectangle");
}
int startX = (int)transformX(rectangle.getX());
int startY = (int)transformY(rectangle.getY());
int endX = (int)transformX(rectangle.getX() + rectangle.getWidth());
if(endX == this.GRID_RESOLUTION_X){
endX = this.GRID_RESOLUTION_X - 1;
}
int endY = (int)transformY(rectangle.getY() + rectangle.getHeight());
if(endY == this.GRID_RESOLUTION_Y){
endY = this.GRID_RESOLUTION_Y - 1;
}
for(int i = startX; i <= endX; i++){
for(int j = startY; j<=endY; j++){
map[j][i].add(rectangle);
}
}
}
}
private void fillCollisionMap(Set<Rectangle> rectangles) throws CollisionMapOutOfBoundsException {
// TODO Insert code for assignment 5.2.a
for(Rectangle rectangle:rectangles){
if(rectangle.getX() < this.gridRectangle.getX() ||
rectangle.getX() + rectangle.getWidth() > this.gridRectangle.getX() + this.gridRectangle.getWidth() ||
rectangle.getY() < this.gridRectangle.getY() ||
rectangle.getY() + rectangle.getHeight() > this.gridRectangle.getY() + this.gridRectangle.getHeight()
){
throw new CollisionMapOutOfBoundsException("a rectangle is out of the bounds of this rectangle");
}
int startX = (int)transformX(rectangle.getX());
int startY = (int)transformY(rectangle.getY());
int endX = (int)transformX(rectangle.getX() + rectangle.getWidth());
if(endX == this.GRID_RESOLUTION_X){
endX = this.GRID_RESOLUTION_X - 1;
}
int endY = (int)transformY(rectangle.getY() + rectangle.getHeight());
if(endY == this.GRID_RESOLUTION_Y){
endY = this.GRID_RESOLUTION_Y - 1;
}
for(int i = startX; i <= endX; i++){
for(int j = startY; j<=endY; j++){
map[j][i].add(rectangle);
}
}
}
}