From cf1c07e06672b0e086db68a8d2d5af6a3af8ccbc Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Tue, 16 Jan 2024 15:37:10 +1000 Subject: [PATCH] Add a helper for radians to degrees --- src/evdev-mt-touchpad-gestures.c | 2 +- src/evdev-tablet.c | 4 ++-- src/util-matrix.h | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c index ad11c262..1e5d039b 100644 --- a/src/evdev-mt-touchpad-gestures.c +++ b/src/evdev-mt-touchpad-gestures.c @@ -324,7 +324,7 @@ tp_gesture_get_pinch_info(struct tp_dispatch *tp, delta = device_delta(first->point, second->point); normalized = tp_normalize_delta(tp, delta); *distance = normalized_length(normalized); - *angle = atan2(normalized.y, normalized.x) * 180.0 / M_PI; + *angle = rad2deg(atan2(normalized.y, normalized.x)); *center = device_average(first->point, second->point); } diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 5625e23f..3f976ffb 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -382,7 +382,7 @@ adjust_tilt(const struct input_absinfo *absinfo) if (absinfo->resolution != 0 && absinfo->maximum > 0 && absinfo->minimum < 0) { - value = 180.0/M_PI * absinfo->value/absinfo->resolution; + value = rad2deg((double)absinfo->value/absinfo->resolution); } else { /* Wacom supports physical [-64, 64] degrees, so map to that by * default. If other tablets have a different physical range or @@ -419,7 +419,7 @@ convert_tilt_to_rotation(struct tablet_dispatch *tablet) /* atan2 is CCW, we want CW -> negate x */ if (x || y) - angle = ((180.0 * atan2(-x, y)) / M_PI); + angle = rad2deg(atan2(-x, y)); angle = fmod(360 + angle - offset, 360); diff --git a/src/util-matrix.h b/src/util-matrix.h index 584a412c..09ac99e4 100644 --- a/src/util-matrix.h +++ b/src/util-matrix.h @@ -40,6 +40,12 @@ deg2rad(int degree) return M_PI * degree / 180.0; } +static inline double +rad2deg(double rad) +{ + return 180.0 / M_PI * rad; +} + static inline void matrix_init_identity(struct matrix *m) {