@@ -49,10 +49,7 @@ ruis::event_status flickable::on_mouse_button(const mouse_button_event& event)
4949 {
5050 utki::assert (event.action == button_action::press, SL);
5151
52- this ->push_touch_move_to_history ({
53- .position = event.pos ,
54- .timestamp_ms = utki::get_ticks_ms ()
55- });
52+ this ->push_touch_move_to_history ({.position = event.pos , .timestamp_ms = utki::get_ticks_ms ()});
5653 auto vel = this ->calculate_touch_velocity ();
5754 std::cout << " touch press, vel = " << vel << std::endl;
5855
@@ -103,15 +100,12 @@ ruis::event_status flickable::on_mouse_move(const mouse_move_event& event)
103100 if (event.pointer_id != this ->cur_pointer_id ) {
104101 return this ->flickable_on_mouse_move (event);
105102 }
106- }else {
103+ } else {
107104 // no touch active, ignore mouse move events
108105 return ruis::event_status::propagate;
109106 }
110107
111- this ->push_touch_move_to_history ({
112- .position = event.pos ,
113- .timestamp_ms = utki::get_ticks_ms ()
114- });
108+ this ->push_touch_move_to_history ({.position = event.pos , .timestamp_ms = utki::get_ticks_ms ()});
115109
116110 auto vel = this ->calculate_touch_velocity ();
117111 std::cout << " touch move, vel = " << vel << std::endl;
@@ -186,20 +180,23 @@ void flickable::update(uint32_t dt_ms)
186180 // TODO:
187181}
188182
189- namespace {
183+ namespace {
190184constexpr auto max_history_records = 10 ;
191- }
185+ } // namespace
192186
193- void flickable::push_touch_move_to_history (touch_move_info tm){
187+ void flickable::push_touch_move_to_history (touch_move_info tm)
188+ {
194189 constexpr auto max_history_age_ms = 200 ;
195190 constexpr auto min_time_between_points_ms = 1 ;
196191
197192 // drop too old records
198- while (!this ->touch_history .empty () && tm.timestamp_ms - this ->touch_history .front ().timestamp_ms > max_history_age_ms){
193+ while (!this ->touch_history .empty () &&
194+ tm.timestamp_ms - this ->touch_history .front ().timestamp_ms > max_history_age_ms)
195+ {
199196 this ->touch_history .pop_front ();
200197 }
201198
202- if (this ->touch_history .empty ()){
199+ if (this ->touch_history .empty ()) {
203200 this ->touch_history .push_back (std::move (tm));
204201 return ;
205202 }
@@ -208,26 +205,27 @@ void flickable::push_touch_move_to_history(touch_move_info tm){
208205
209206 auto & last_record = this ->touch_history .back ();
210207
211- if (tm.timestamp_ms - last_record.timestamp_ms <= min_time_between_points_ms){
208+ if (tm.timestamp_ms - last_record.timestamp_ms <= min_time_between_points_ms) {
212209 // we are too close in time to the last record, just update the last record
213210 last_record = tm;
214211 return ;
215212 }
216213
217- if (this ->touch_history .size () == max_history_records){
214+ if (this ->touch_history .size () == max_history_records) {
218215 this ->touch_history .pop_front ();
219216 }
220217
221218 this ->touch_history .push_back (std::move (tm));
222219};
223220
224- ruis::vec2 flickable::calculate_touch_velocity (){
225- if (this ->touch_history .size () < 2 ){
221+ ruis::vec2 flickable::calculate_touch_velocity ()
222+ {
223+ if (this ->touch_history .size () < 2 ) {
226224 // std::cout << "flickable::calculate_touch_velocity(): return 0. this->touch_history.size() = " << this->touch_history.size() << std::endl;
227225 return {0 };
228226 }
229227
230- if (this ->touch_history .size () == 2 ){
228+ if (this ->touch_history .size () == 2 ) {
231229 const auto & p1 = this ->touch_history .front ();
232230 const auto & p2 = this ->touch_history .back ();
233231
@@ -249,7 +247,8 @@ ruis::vec2 flickable::calculate_touch_velocity(){
249247 return vel;
250248}
251249
252- ruis::vec2 flickable::calculate_touch_velocity_for_at_least_3_points_using_ols_method (){
250+ ruis::vec2 flickable::calculate_touch_velocity_for_at_least_3_points_using_ols_method ()
251+ {
253252 // Ordinary Least Squares method fits quadratic curve y(t)=a*t^2+b*t+c to a set of n >= 3 points.
254253 // Coefficients a, b and c can be found by solving the following system of linear equations
255254 //
@@ -276,7 +275,7 @@ ruis::vec2 flickable::calculate_touch_velocity_for_at_least_3_points_using_ols_m
276275 ruis::vec2 pos_time_sum = 0 ;
277276 ruis::vec2 pos_sum = 0 ;
278277
279- for (const auto & rec : this ->touch_history ){
278+ for (const auto & rec : this ->touch_history ) {
280279 // Here we still do arithmetics in uint32_t space.
281280 // The time_bias_ms is the latest timestamp, so subtract from it to get positive biased time.
282281 uint32_t shifted_time = time_bias_ms - rec.timestamp_ms ;
@@ -313,14 +312,14 @@ ruis::vec2 flickable::calculate_touch_velocity_for_at_least_3_points_using_ols_m
313312 constexpr auto epsilon = ruis::real (1e-9 );
314313
315314 using std::abs;
316- if (abs (det) < epsilon){
315+ if (abs (det) < epsilon) {
317316 // the matrix is not invertible
318317 return {0 };
319318 }
320319
321320 // replace 2nd column with right-hand side vector and calculate determinant
322321 ruis::vec2 det_b;
323- for (auto [p0, p1, p2, out] : utki::views::zip (pos_time_pow2_sum, pos_time_sum, pos_sum, det_b)){
322+ for (auto [p0, p1, p2, out] : utki::views::zip (pos_time_pow2_sum, pos_time_sum, pos_sum, det_b)) {
324323 m[0 ][1 ] = p0;
325324 m[1 ][1 ] = p1;
326325 m[2 ][1 ] = p2;
0 commit comments