change getQuadrant to getRegion

This commit is contained in:
yugecin 2017-05-26 17:18:44 +02:00
parent e408fd9607
commit c8df3d5b57
2 changed files with 18 additions and 9 deletions

View File

@ -475,11 +475,20 @@ public class Utils {
} catch (Exception e) {}
}
public static int getQuadrant(double x, double y) {
if (x < displayContainer.width / 2d) {
return y < displayContainer.height / 2d ? 2 : 3;
}
return y < displayContainer.height / 2d ? 1 : 4;
/**
* Gets the region where the given point is in.
* First bit is set if x > half
* Second bit is set if y > half
*
* 2 | 3
* --+--
* 0 | 1
*/
public static int getRegion(double x, double y) {
int q = 0;
if (y < displayContainer.height / 2d) q = 2;
if (x < displayContainer.width / 2d) q |= 1;
return q;
}
/*

View File

@ -33,12 +33,12 @@ public class CircleMover extends Mover {
public CircleMover(GameObject start, GameObject end, int dir) {
super(start, end, dir);
if (startX - endX == 0 && startY - endY == 0) {
int quadr = Utils.getQuadrant(startX, startY);
int quadr = Utils.getRegion(startX, startY);
switch (quadr) {
case 1: ang = 135d / 180d * Math.PI; break;
case 3: ang = 135d / 180d * Math.PI; break;
case 2: ang = 45d / 180d * Math.PI; break;
case 3: ang = -45d / 180d * Math.PI; break;
case 4: ang = -135d / 180d * Math.PI; break;
case 0: ang = -45d / 180d * Math.PI; break;
case 1: ang = -135d / 180d * Math.PI; break;
}
} else {
ang = Math.atan2(startY - endY, startX - endX);