From 2f938dc6f477313a5af1d1622d3a8c6d266239ad Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 13 Mar 2023 03:06:43 +0100 Subject: Correct pointer direction The previous algorithm did not cut the circle into 16 equal parts. The division by 2pi yielded numbers smaller than 16, which no longer made sense after the cast to int. --- srcs/juloo.keyboard2/Pointers.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'srcs/juloo.keyboard2/Pointers.java') diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java index 6979d7b..1b62ca7 100644 --- a/srcs/juloo.keyboard2/Pointers.java +++ b/srcs/juloo.keyboard2/Pointers.java @@ -203,7 +203,7 @@ public final class Pointers implements Handler.Callback // [i] is [0, -1, 1, -2, 2, ...] for (int i = 0; i > -4; i = (~i>>31) - i) { - int d = (direction + i + 16 - 1) % 16; + int d = (direction + i + 16) % 16; // Don't make the difference between a key that doesn't exist and a key // that is removed by [_handler]. Triggers side effects. k = _handler.modifyKey(getKeyAtDirection(ptr.key, d), ptr.modifiers); @@ -241,8 +241,10 @@ public final class Pointers implements Handler.Callback { // See [getKeyAtDirection()] for the meaning. The starting point on the // circle is the top direction. - double a = Math.atan2(dy, dx); // between -pi and +pi, 0 is to the right - direction = ((int)(a * 16 / (Math.PI * 2)) + 21) % 16; + double a = Math.atan2(dy, dx) + Math.PI; + // a is between 0 and 2pi, 0 is pointing to the left + // add 12 to align 0 to the top + direction = ((int)(a * 8 / Math.PI) + 12) % 16; } if (direction != ptr.selected_direction) -- cgit v1.2.3