So in this piece of code i'm writing I have these shapes defined by an ArrayList of Point objects, these points represent cells on a grid. Each shape has an x and a y, which is the centre of the shape, in an absolute coordinate system - bottom left corner would be 0, 0 etc. Each of the shapes should be able to rotate around the centre. I have defined these shapes in their "north facing" orientation using coordinates relative to their centre. How would I be able to retrieve a list of absolute coordinates for each cell given the parameters x and y for the centre of the shape for each of the four directions N, E, S, W.
ArrayList<Point> adjustedCells = new ArrayList<Point>();
for(Point point : cells) {
Point adjustedPoint;
switch (getOrientation()) {
case NORTH:
adjustedPoint = new Point(x + point.x, y + point.y);
adjustedCells.add(adjustedPoint);
case SOUTH:
adjustedPoint = new Point(x - point.x, y - point.y);
adjustedCells.add(adjustedPoint);
case EAST:
adjustedPoint = new Point(x - point.y, y + point.x);
adjustedCells.add(adjustedPoint);
case WEST:
adjustedPoint = new Point(x + point.y, y - point.x);
adjustedCells.add(adjustedPoint);
}
}
This is what I tried based on other code I've found but it's clearly not giving the correct coordinates. This piece is just inside a method with the parameters x and y which are the centre x and y of the shape in absolute.