[PATCH libinput] filter: rename all velocity-related bits to *velocity_ms*
Peter Hutterer
peter.hutterer at who-t.net
Mon Aug 3 17:05:10 PDT 2015
Everything in libinput is in µs now, make it clear that this is all in ms.
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
src/filter.c | 64 ++++++++++++++++++++++++++++++------------------------------
src/filter.h | 2 +-
2 files changed, 33 insertions(+), 33 deletions(-)
diff --git a/src/filter.c b/src/filter.c
index 2506ee2..d9eb61d 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -85,7 +85,7 @@ filter_get_speed(struct motion_filter *filter)
* Pointer acceleration filter constants
*/
-#define MAX_VELOCITY_DIFF 1 /* units/ms */
+#define MAX_VELOCITY_DIFF_MS 1 /* units/ms */
#define MOTION_TIMEOUT ms2us(1000)
#define NUM_POINTER_TRACKERS 16
@@ -101,8 +101,8 @@ struct pointer_accelerator {
accel_profile_func_t profile;
- double velocity; /* units/ms */
- double last_velocity; /* units/ms */
+ double velocity_ms; /* units/ms */
+ double last_velocity_ms;/* units/ms */
struct normalized_coords last;
struct pointer_tracker *trackers;
@@ -147,14 +147,14 @@ tracker_by_offset(struct pointer_accelerator *accel, unsigned int offset)
}
static double
-calculate_tracker_velocity(struct pointer_tracker *tracker, uint64_t time)
+calculate_tracker_velocity_ms(struct pointer_tracker *tracker, uint64_t time)
{
double tdelta = time - tracker->time + 1;
return normalized_length(tracker->delta) / tdelta * 1000.0; /* units/ms */
}
static inline double
-calculate_velocity_after_timeout(struct pointer_tracker *tracker)
+calculate_velocity_ms_after_timeout(struct pointer_tracker *tracker)
{
/* First movement after timeout needs special handling.
*
@@ -167,18 +167,18 @@ calculate_velocity_after_timeout(struct pointer_tracker *tracker)
* for really slow movements but provides much more useful initial
* movement in normal use-cases (pause, move, pause, move)
*/
- return calculate_tracker_velocity(tracker,
- tracker->time + MOTION_TIMEOUT);
+ return calculate_tracker_velocity_ms(tracker,
+ tracker->time + MOTION_TIMEOUT);
}
static double
-calculate_velocity(struct pointer_accelerator *accel, uint64_t time)
+calculate_velocity_ms(struct pointer_accelerator *accel, uint64_t time)
{
struct pointer_tracker *tracker;
- double velocity;
+ double velocity_ms;
double result = 0.0;
- double initial_velocity = 0.0;
- double velocity_diff;
+ double initial_velocity_ms = 0.0;
+ double velocity_diff_ms;
unsigned int offset;
unsigned int dir = tracker_by_offset(accel, 0)->dir;
@@ -192,11 +192,11 @@ calculate_velocity(struct pointer_accelerator *accel, uint64_t time)
if (time - tracker->time > MOTION_TIMEOUT ||
tracker->time > time) {
if (offset == 1)
- result = calculate_velocity_after_timeout(tracker);
+ result = calculate_velocity_ms_after_timeout(tracker);
break;
}
- velocity = calculate_tracker_velocity(tracker, time);
+ velocity_ms = calculate_tracker_velocity_ms(tracker, time);
/* Stop if direction changed */
dir &= tracker->dir;
@@ -204,19 +204,19 @@ calculate_velocity(struct pointer_accelerator *accel, uint64_t time)
/* First movement after dirchange - velocity is that
* of the last movement */
if (offset == 1)
- result = velocity;
+ result = velocity_ms;
break;
}
- if (initial_velocity == 0.0) {
- result = initial_velocity = velocity;
+ if (initial_velocity_ms == 0.0) {
+ result = initial_velocity_ms = velocity_ms;
} else {
/* Stop if velocity differs too much from initial */
- velocity_diff = fabs(initial_velocity - velocity);
- if (velocity_diff > MAX_VELOCITY_DIFF)
+ velocity_diff_ms = fabs(initial_velocity_ms - velocity_ms);
+ if (velocity_diff_ms > MAX_VELOCITY_DIFF_MS)
break;
- result = velocity;
+ result = velocity_ms;
}
}
@@ -225,27 +225,27 @@ calculate_velocity(struct pointer_accelerator *accel, uint64_t time)
static double
acceleration_profile(struct pointer_accelerator *accel,
- void *data, double velocity, uint64_t time)
+ void *data, double velocity_ms, uint64_t time)
{
- return accel->profile(&accel->base, data, velocity, time);
+ return accel->profile(&accel->base, data, velocity_ms, time);
}
static double
calculate_acceleration(struct pointer_accelerator *accel,
void *data,
- double velocity,
- double last_velocity,
+ double velocity_ms,
+ double last_velocity_ms,
uint64_t time)
{
double factor;
/* Use Simpson's rule to calculate the avarage acceleration between
* the previous motion and the most recent. */
- factor = acceleration_profile(accel, data, velocity, time);
- factor += acceleration_profile(accel, data, last_velocity, time);
+ factor = acceleration_profile(accel, data, velocity_ms, time);
+ factor += acceleration_profile(accel, data, last_velocity_ms, time);
factor += 4.0 *
acceleration_profile(accel, data,
- (last_velocity + velocity) / 2,
+ (last_velocity_ms + velocity_ms) / 2,
time);
factor = factor / 6.0;
@@ -260,7 +260,7 @@ accelerator_filter(struct motion_filter *filter,
{
struct pointer_accelerator *accel =
(struct pointer_accelerator *) filter;
- double velocity; /* units/ms */
+ double velocity_ms; /* units/ms */
double accel_value; /* unitless factor */
struct normalized_coords accelerated;
struct normalized_coords unnormalized;
@@ -273,11 +273,11 @@ accelerator_filter(struct motion_filter *filter,
unnormalized.y = unaccelerated->y * dpi_factor;
feed_trackers(accel, &unnormalized, time);
- velocity = calculate_velocity(accel, time);
+ velocity_ms = calculate_velocity_ms(accel, time);
accel_value = calculate_acceleration(accel,
data,
- velocity,
- accel->last_velocity,
+ velocity_ms,
+ accel->last_velocity_ms,
time);
accelerated.x = accel_value * unnormalized.x;
@@ -285,7 +285,7 @@ accelerator_filter(struct motion_filter *filter,
accel->last = unnormalized;
- accel->last_velocity = velocity;
+ accel->last_velocity_ms = velocity_ms;
return accelerated;
}
@@ -367,7 +367,7 @@ create_pointer_accelerator_filter(accel_profile_func_t profile,
filter->base.interface = &accelerator_interface;
filter->profile = profile;
- filter->last_velocity = 0.0;
+ filter->last_velocity_ms = 0.0;
filter->last.x = 0;
filter->last.y = 0;
diff --git a/src/filter.h b/src/filter.h
index 617fab1..0480aea 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -54,7 +54,7 @@ filter_get_speed(struct motion_filter *filter);
typedef double (*accel_profile_func_t)(struct motion_filter *filter,
void *data,
- double velocity,
+ double velocity_ms,
uint64_t time);
struct motion_filter *
--
2.4.3
More information about the wayland-devel
mailing list