[PATCH libinput] filter: rename all velocity-related bits to *velocity_ms*
Peter Hutterer
peter.hutterer at who-t.net
Mon Aug 3 21:50:50 PDT 2015
On Tue, Aug 04, 2015 at 10:48:19AM +0800, Jonas Ådahl wrote:
> On Tue, Aug 04, 2015 at 10:05:10AM +1000, Peter Hutterer wrote:
> > 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>
> > ---
>
> We also have the "speed" in the profiles that are in units/ms but not
> named accordingly. Also wonder why we have both "speed" and "velocity",
> especially since we pass the velocity to a profile function, and then
> the profile function calls it speed.
>
heh, after googling what the difference between speed and velocity is, the
current usage actually appears to be correct.
from the first hit:
http://www.physicsclassroom.com/class/1DKin/Lesson-1/Speed-and-Velocity
"Speed is a scalar quantity and does not keep track of direction; velocity is
a vector quantity and is direction aware."
and we do calculate velocity based on the directions of the input data,
whereas the acceleration profiles just take a speed and multiply that.
so I guess we should leave it as-is to be correct, I'll just append the ms.
Cheers,
Peter
> > 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
> >
> > _______________________________________________
> > wayland-devel mailing list
> > wayland-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list