I have a method which returns the direction of a vector.
The direction can be either N, NE, E, SE, S, SW, W, NW(8 total).
Here is my method, which is horrible buggy:
public static Direction getDirection(Point2D.Float normalizedPoint)
{
int x = Math.round(normalizedPoint.x);
int y = Math.round(normalizedPoint.y);
if (x == 1 && y == 1)
return Direction.NW;
else if(x == 1 && y == 0)
return Direction.W;
else if(x == 1 && y == -1)
return Direction.SW;
else if(x == 0 && y == -1)
return Direction.S;
else if(x == -1 && y == -1)
return Direction.SE;
else if(x == -1 && y == 0)
return Direction.E;
else if(x == -1 && y == 1)
return Direction.NE;
else if(x == 0 && y == 1)
return Direction.E;
return null;
}
How do I resolve this?