From c8df3d5b573396ba5f91641c8f90c8fdb2898cf6 Mon Sep 17 00:00:00 2001 From: yugecin Date: Fri, 26 May 2017 17:18:44 +0200 Subject: [PATCH] change getQuadrant to getRegion --- src/itdelatrisu/opsu/Utils.java | 19 ++++++++++++++----- src/yugecin/opsudance/movers/CircleMover.java | 8 ++++---- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index cab4f177..2e2b5d54 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -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; } /* diff --git a/src/yugecin/opsudance/movers/CircleMover.java b/src/yugecin/opsudance/movers/CircleMover.java index 8f9ebe7a..e9e3bda4 100644 --- a/src/yugecin/opsudance/movers/CircleMover.java +++ b/src/yugecin/opsudance/movers/CircleMover.java @@ -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);