mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-30 14:10:08 +01:00
Add a normalized_length helper function and use this where applicable
Add a normalized_length helper function and use this where applicable, just a minor cleanup. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
fe93145f86
commit
674490ca60
3 changed files with 12 additions and 11 deletions
|
|
@ -530,15 +530,11 @@ static bool
|
|||
tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp,
|
||||
struct tp_touch *t)
|
||||
{
|
||||
int threshold = DEFAULT_TAP_MOVE_THRESHOLD;
|
||||
struct normalized_coords normalized;
|
||||
struct normalized_coords norm =
|
||||
tp_normalize_delta(tp, device_delta(t->point,
|
||||
t->tap.initial));
|
||||
|
||||
normalized = tp_normalize_delta(tp,
|
||||
device_delta(t->point,
|
||||
t->tap.initial));
|
||||
|
||||
return normalized.x * normalized.x + normalized.y * normalized.y
|
||||
> threshold * threshold;
|
||||
return normalized_length(norm) > DEFAULT_TAP_MOVE_THRESHOLD;
|
||||
}
|
||||
|
||||
static bool
|
||||
|
|
|
|||
|
|
@ -137,11 +137,9 @@ tracker_by_offset(struct pointer_accelerator *accel, unsigned int offset)
|
|||
static double
|
||||
calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time)
|
||||
{
|
||||
double distance;
|
||||
double tdelta = time - tracker->time + 1;
|
||||
|
||||
distance = hypot(tracker->delta.x, tracker->delta.y);
|
||||
return distance / tdelta; /* units/ms */
|
||||
return normalized_length(tracker->delta) / tdelta; /* units/ms */
|
||||
}
|
||||
|
||||
static double
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#define LIBINPUT_PRIVATE_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "linux/input.h"
|
||||
|
||||
|
|
@ -373,4 +374,10 @@ device_delta(struct device_coords a, struct device_coords b)
|
|||
return delta;
|
||||
}
|
||||
|
||||
static inline double
|
||||
normalized_length(struct normalized_coords norm)
|
||||
{
|
||||
return hypot(norm.x, norm.y);
|
||||
}
|
||||
|
||||
#endif /* LIBINPUT_PRIVATE_H */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue