Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: ui/events/gesture_detection/velocity_tracker.cc

Issue 660173002: Type conversion fixes, ui/ edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/gesture_detection/velocity_tracker.h" 5 #include "ui/events/gesture_detection/velocity_tracker.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/events/gesture_detection/motion_event.h" 10 #include "ui/events/gesture_detection/motion_event.h"
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 break; 586 break;
587 587
588 TimeDelta age = newest_movement.event_time - movement.event_time; 588 TimeDelta age = newest_movement.event_time - movement.event_time;
589 if (age > horizon) 589 if (age > horizon)
590 break; 590 break;
591 591
592 const Position& position = movement.GetPosition(id); 592 const Position& position = movement.GetPosition(id);
593 x[m] = position.x; 593 x[m] = position.x;
594 y[m] = position.y; 594 y[m] = position.y;
595 w[m] = ChooseWeight(index); 595 w[m] = ChooseWeight(index);
596 time[m] = -age.InSecondsF(); 596 time[m] = -static_cast<float>(age.InSecondsF());
597 index = (index == 0 ? kHistorySize : index) - 1; 597 index = (index == 0 ? kHistorySize : index) - 1;
598 } while (++m < kHistorySize); 598 } while (++m < kHistorySize);
599 599
600 if (m == 0) 600 if (m == 0)
601 return false; // no data 601 return false; // no data
602 602
603 // Calculate a least squares polynomial fit. 603 // Calculate a least squares polynomial fit.
604 uint32_t degree = degree_; 604 uint32_t degree = degree_;
605 if (degree > m - 1) 605 if (degree > m - 1)
606 degree = m - 1; 606 degree = m - 1;
(...skipping 30 matching lines...) Expand all
637 if (index == index_) { 637 if (index == index_) {
638 return 1.0f; 638 return 1.0f;
639 } 639 }
640 uint32_t next_index = (index + 1) % kHistorySize; 640 uint32_t next_index = (index + 1) % kHistorySize;
641 float delta_millis = 641 float delta_millis =
642 static_cast<float>((movements_[next_index].event_time - 642 static_cast<float>((movements_[next_index].event_time -
643 movements_[index].event_time).InMillisecondsF()); 643 movements_[index].event_time).InMillisecondsF());
644 if (delta_millis < 0) 644 if (delta_millis < 0)
645 return 0.5f; 645 return 0.5f;
646 if (delta_millis < 10) 646 if (delta_millis < 10)
647 return 0.5f + delta_millis * 0.05; 647 return 0.5f + delta_millis * 0.05f;
648 648
649 return 1.0f; 649 return 1.0f;
650 } 650 }
651 651
652 case WEIGHTING_CENTRAL: { 652 case WEIGHTING_CENTRAL: {
653 // Weight points based on their age, weighing very recent and very old 653 // Weight points based on their age, weighing very recent and very old
654 // points less. 654 // points less.
655 // age 0ms: 0.5 655 // age 0ms: 0.5
656 // age 10ms: 1.0 656 // age 10ms: 1.0
657 // age 50ms: 1.0 657 // age 50ms: 1.0
658 // age 60ms: 0.5 658 // age 60ms: 0.5
659 float age_millis = 659 float age_millis =
660 static_cast<float>((movements_[index_].event_time - 660 static_cast<float>((movements_[index_].event_time -
661 movements_[index].event_time).InMillisecondsF()); 661 movements_[index].event_time).InMillisecondsF());
662 if (age_millis < 0) 662 if (age_millis < 0)
663 return 0.5f; 663 return 0.5f;
664 if (age_millis < 10) 664 if (age_millis < 10)
665 return 0.5f + age_millis * 0.05; 665 return 0.5f + age_millis * 0.05f;
666 if (age_millis < 50) 666 if (age_millis < 50)
667 return 1.0f; 667 return 1.0f;
668 if (age_millis < 60) 668 if (age_millis < 60)
669 return 0.5f + (60 - age_millis) * 0.05; 669 return 0.5f + (60 - age_millis) * 0.05f;
670 670
671 return 0.5f; 671 return 0.5f;
672 } 672 }
673 673
674 case WEIGHTING_RECENT: { 674 case WEIGHTING_RECENT: {
675 // Weight points based on their age, weighing older points less. 675 // Weight points based on their age, weighing older points less.
676 // age 0ms: 1.0 676 // age 0ms: 1.0
677 // age 50ms: 1.0 677 // age 50ms: 1.0
678 // age 100ms: 0.5 678 // age 100ms: 0.5
679 float age_millis = 679 float age_millis =
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 out_estimator->degree = state.degree; 808 out_estimator->degree = state.degree;
809 out_estimator->xcoeff[0] = state.xpos; 809 out_estimator->xcoeff[0] = state.xpos;
810 out_estimator->xcoeff[1] = state.xvel; 810 out_estimator->xcoeff[1] = state.xvel;
811 out_estimator->xcoeff[2] = state.xaccel / 2; 811 out_estimator->xcoeff[2] = state.xaccel / 2;
812 out_estimator->ycoeff[0] = state.ypos; 812 out_estimator->ycoeff[0] = state.ypos;
813 out_estimator->ycoeff[1] = state.yvel; 813 out_estimator->ycoeff[1] = state.yvel;
814 out_estimator->ycoeff[2] = state.yaccel / 2; 814 out_estimator->ycoeff[2] = state.yaccel / 2;
815 } 815 }
816 816
817 } // namespace ui 817 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | ui/events/keycodes/dom4/keycode_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698