filter: split calculating the accel factor into a helper function
authorPeter Hutterer <peter.hutterer@who-t.net>
Tue, 28 Jul 2015 05:46:33 +0000 (15:46 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Mon, 10 Aug 2015 23:19:55 +0000 (09:19 +1000)
No functional changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jonas Ã…dahl <jadahl@gmail.com>
src/filter.c

index b94647d..f3e0fb3 100644 (file)
@@ -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;
 }