Add a helper for radians to degrees

This commit is contained in:
Peter Hutterer 2024-01-16 15:37:10 +10:00
parent 3fd38d8927
commit cf1c07e066
3 changed files with 9 additions and 3 deletions

View file

@ -324,7 +324,7 @@ tp_gesture_get_pinch_info(struct tp_dispatch *tp,
delta = device_delta(first->point, second->point); delta = device_delta(first->point, second->point);
normalized = tp_normalize_delta(tp, delta); normalized = tp_normalize_delta(tp, delta);
*distance = normalized_length(normalized); *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); *center = device_average(first->point, second->point);
} }

View file

@ -382,7 +382,7 @@ adjust_tilt(const struct input_absinfo *absinfo)
if (absinfo->resolution != 0 && if (absinfo->resolution != 0 &&
absinfo->maximum > 0 && absinfo->maximum > 0 &&
absinfo->minimum < 0) { absinfo->minimum < 0) {
value = 180.0/M_PI * absinfo->value/absinfo->resolution; value = rad2deg((double)absinfo->value/absinfo->resolution);
} else { } else {
/* Wacom supports physical [-64, 64] degrees, so map to that by /* Wacom supports physical [-64, 64] degrees, so map to that by
* default. If other tablets have a different physical range or * 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 */ /* atan2 is CCW, we want CW -> negate x */
if (x || y) if (x || y)
angle = ((180.0 * atan2(-x, y)) / M_PI); angle = rad2deg(atan2(-x, y));
angle = fmod(360 + angle - offset, 360); angle = fmod(360 + angle - offset, 360);

View file

@ -40,6 +40,12 @@ deg2rad(int degree)
return M_PI * degree / 180.0; return M_PI * degree / 180.0;
} }
static inline double
rad2deg(double rad)
{
return 180.0 / M_PI * rad;
}
static inline void static inline void
matrix_init_identity(struct matrix *m) matrix_init_identity(struct matrix *m)
{ {