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:
Hans de Goede 2015-03-24 13:14:19 +01:00 committed by Peter Hutterer
parent fe93145f86
commit 674490ca60
3 changed files with 12 additions and 11 deletions

View file

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

View file

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

View file

@ -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 */