mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-28 15:30:07 +01:00
filter: split calculating the accel factor into a helper function
No functional changes. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Jonas Ådahl <jadahl@gmail.com>
This commit is contained in:
parent
4c48b46d15
commit
f2663e2b25
1 changed files with 25 additions and 10 deletions
35
src/filter.c
35
src/filter.c
|
|
@ -266,6 +266,27 @@ calculate_acceleration(struct pointer_accelerator *accel,
|
|||
return factor; /* unitless factor */
|
||||
}
|
||||
|
||||
static inline double
|
||||
calculate_acceleration_factor(struct pointer_accelerator *accel,
|
||||
const struct normalized_coords *unaccelerated,
|
||||
void *data,
|
||||
uint64_t time)
|
||||
{
|
||||
double velocity; /* units/us */
|
||||
double accel_factor;
|
||||
|
||||
feed_trackers(accel, unaccelerated, time);
|
||||
velocity = calculate_velocity(accel, time);
|
||||
accel_factor = calculate_acceleration(accel,
|
||||
data,
|
||||
velocity,
|
||||
accel->last_velocity,
|
||||
time);
|
||||
accel->last_velocity = velocity;
|
||||
|
||||
return accel_factor;
|
||||
}
|
||||
|
||||
static struct normalized_coords
|
||||
accelerator_filter(struct motion_filter *filter,
|
||||
const struct normalized_coords *unaccelerated,
|
||||
|
|
@ -273,7 +294,6 @@ accelerator_filter(struct motion_filter *filter,
|
|||
{
|
||||
struct pointer_accelerator *accel =
|
||||
(struct pointer_accelerator *) filter;
|
||||
double velocity; /* units/us */
|
||||
double accel_value; /* unitless factor */
|
||||
struct normalized_coords accelerated;
|
||||
struct normalized_coords unnormalized;
|
||||
|
|
@ -285,19 +305,14 @@ accelerator_filter(struct motion_filter *filter,
|
|||
unnormalized.x = unaccelerated->x * dpi_factor;
|
||||
unnormalized.y = unaccelerated->y * dpi_factor;
|
||||
|
||||
feed_trackers(accel, &unnormalized, time);
|
||||
velocity = calculate_velocity(accel, time);
|
||||
accel_value = calculate_acceleration(accel,
|
||||
data,
|
||||
velocity,
|
||||
accel->last_velocity,
|
||||
time);
|
||||
accel_value = calculate_acceleration_factor(accel,
|
||||
&unnormalized,
|
||||
data,
|
||||
time);
|
||||
|
||||
accelerated.x = accel_value * unnormalized.x;
|
||||
accelerated.y = accel_value * unnormalized.y;
|
||||
|
||||
accel->last_velocity = velocity;
|
||||
|
||||
return accelerated;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue