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.
This commit is contained in:
Jules Aguillon 2023-03-13 03:06:43 +01:00
parent ce51df6f5a
commit 2f938dc6f4

View File

@ -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)