From 058c9d24496b2dd252edb229fc7f6e921a2e6238 Mon Sep 17 00:00:00 2001 From: NepEgor Date: Mon, 20 Mar 2023 01:22:44 +0400 Subject: [PATCH] multiplication optimization --- lib/touch_controls/src/touch_joystick.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/touch_controls/src/touch_joystick.cpp b/lib/touch_controls/src/touch_joystick.cpp index fcb944d..b3f8559 100644 --- a/lib/touch_controls/src/touch_joystick.cpp +++ b/lib/touch_controls/src/touch_joystick.cpp @@ -109,10 +109,10 @@ TouchJoystick::TouchState TouchJoystick::touch(int8_t fid, int32_t tx, int32_t t } else // in bounds outside of outer dead zone { - float len = sqrt(t2); + float factor = dead_zone_outer / sqrt(t2) * pos2usb; - x = (tx * dead_zone_outer / len) * pos2usb + usb_x; - y = (ty * dead_zone_outer / len) * pos2usb + usb_y; + x = tx * factor + usb_x; + y = ty * factor + usb_y; } if (invert_x) x = 2 * usb_x - x;