I need to determine the quadrant of point, in a faster way. I am only aware of "determine using the signs" method. I am looking for a good approach, if any. If not any fixes to my code would help. Assume there are 4 quads on the plane. My code-
int x = scan.nextInt() > 0 ? 1 : 0;
int y = scan.nextInt() > 0 ? 1 : 0;
switch (x) {
case 1:
switch (y) {
case 1:
quad = 1;
break;
case 0:
quad = 4;
break;
}
break;
case 0:
switch (y) {
case 1:
quad = 2;
break;
case 0:
quad = 3;
break;
}
break;
}
The switch cases look disgusting and are too complicated because you are nesting them plus you are adding too many extra lines of code because of the break clauses. Use "if and else" blocks for better readability, I suspect this is why you got confused in the first place.