1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License in the LICENSE-APACHE file or at:
// https://www.apache.org/licenses/LICENSE-2.0
//! Event handling: mouse / touch velocity sampling
//!
//! The goal here is to yield estimates of velocity (in pixels per second) for
//! mouse motion and touch swipe events. Estimates should be smooth (ideally at
//! least two delta samples) and responsive (ideally no longer than the period
//! of one frame).
//!
//! From a cursory web search and some tests on available devices:
//!
//! - Common (basic) mice usually report at 125 Hz while gaming mice commonly
//! report at 1 kHz (potentially up to 8 kHz)
//! - Some touchscreens report at ~100 Hz while modern phone touchscreens often
//! report at twice the screen refresh rate (with some gaming phones using
//! ~1-2 kHz).
//! - A Windows Precision Touchpad is required to report at 125 Hz; my Elan
//! touchpad reports at 150 Hz.
//! - Troubleshooting requests attest that rates are sometimes much lower (as
//! low as 30 Hz).
//!
//! A sample period of `3500 / screen_refresh_hz` ms should allow at least 3
//! (delta) samples while providing 7 in the common 125 Hz mouse, 60 Hz screen
//! case. Provided we ignore deltas of zero, we may limit our sample buffer to
//! a relatively small size (e.g. 8 samples) without making results too jittery;
//! this also improves responsiveness when the sample rate is high.
use crateVec2;
use SmallVec;
use ;
const MAX_SAMPLES: usize = 8;
/// A buffer of recent delta samples used to estimate velocity
pub