change getQuadrant to getRegion
This commit is contained in:
parent
e408fd9607
commit
c8df3d5b57
|
@ -475,11 +475,20 @@ public class Utils {
|
||||||
} catch (Exception e) {}
|
} catch (Exception e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getQuadrant(double x, double y) {
|
/**
|
||||||
if (x < displayContainer.width / 2d) {
|
* Gets the region where the given point is in.
|
||||||
return y < displayContainer.height / 2d ? 2 : 3;
|
* First bit is set if x > half
|
||||||
}
|
* Second bit is set if y > half
|
||||||
return y < displayContainer.height / 2d ? 1 : 4;
|
*
|
||||||
|
* 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -33,12 +33,12 @@ public class CircleMover extends Mover {
|
||||||
public CircleMover(GameObject start, GameObject end, int dir) {
|
public CircleMover(GameObject start, GameObject end, int dir) {
|
||||||
super(start, end, dir);
|
super(start, end, dir);
|
||||||
if (startX - endX == 0 && startY - endY == 0) {
|
if (startX - endX == 0 && startY - endY == 0) {
|
||||||
int quadr = Utils.getQuadrant(startX, startY);
|
int quadr = Utils.getRegion(startX, startY);
|
||||||
switch (quadr) {
|
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 2: ang = 45d / 180d * Math.PI; break;
|
||||||
case 3: ang = -45d / 180d * Math.PI; break;
|
case 0: ang = -45d / 180d * Math.PI; break;
|
||||||
case 4: ang = -135d / 180d * Math.PI; break;
|
case 1: ang = -135d / 180d * Math.PI; break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ang = Math.atan2(startY - endY, startX - endX);
|
ang = Math.atan2(startY - endY, startX - endX);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user