| OLD | NEW |
| 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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 break; | 587 break; |
| 588 | 588 |
| 589 TimeDelta age = newest_movement.event_time - movement.event_time; | 589 TimeDelta age = newest_movement.event_time - movement.event_time; |
| 590 if (age > horizon) | 590 if (age > horizon) |
| 591 break; | 591 break; |
| 592 | 592 |
| 593 const Position& position = movement.GetPosition(id); | 593 const Position& position = movement.GetPosition(id); |
| 594 x[m] = position.x; | 594 x[m] = position.x; |
| 595 y[m] = position.y; | 595 y[m] = position.y; |
| 596 w[m] = ChooseWeight(index); | 596 w[m] = ChooseWeight(index); |
| 597 time[m] = -age.InSecondsF(); | 597 time[m] = -static_cast<float>(age.InSecondsF()); |
| 598 index = (index == 0 ? HISTORY_SIZE : index) - 1; | 598 index = (index == 0 ? HISTORY_SIZE : index) - 1; |
| 599 } while (++m < HISTORY_SIZE); | 599 } while (++m < HISTORY_SIZE); |
| 600 | 600 |
| 601 if (m == 0) | 601 if (m == 0) |
| 602 return false; // no data | 602 return false; // no data |
| 603 | 603 |
| 604 // Calculate a least squares polynomial fit. | 604 // Calculate a least squares polynomial fit. |
| 605 uint32_t degree = degree_; | 605 uint32_t degree = degree_; |
| 606 if (degree > m - 1) | 606 if (degree > m - 1) |
| 607 degree = m - 1; | 607 degree = m - 1; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 638 if (index == index_) { | 638 if (index == index_) { |
| 639 return 1.0f; | 639 return 1.0f; |
| 640 } | 640 } |
| 641 uint32_t next_index = (index + 1) % HISTORY_SIZE; | 641 uint32_t next_index = (index + 1) % HISTORY_SIZE; |
| 642 float delta_millis = | 642 float delta_millis = |
| 643 static_cast<float>((movements_[next_index].event_time - | 643 static_cast<float>((movements_[next_index].event_time - |
| 644 movements_[index].event_time).InMillisecondsF()); | 644 movements_[index].event_time).InMillisecondsF()); |
| 645 if (delta_millis < 0) | 645 if (delta_millis < 0) |
| 646 return 0.5f; | 646 return 0.5f; |
| 647 if (delta_millis < 10) | 647 if (delta_millis < 10) |
| 648 return 0.5f + delta_millis * 0.05; | 648 return 0.5f + delta_millis * 0.05f; |
| 649 | 649 |
| 650 return 1.0f; | 650 return 1.0f; |
| 651 } | 651 } |
| 652 | 652 |
| 653 case WEIGHTING_CENTRAL: { | 653 case WEIGHTING_CENTRAL: { |
| 654 // Weight points based on their age, weighing very recent and very old | 654 // Weight points based on their age, weighing very recent and very old |
| 655 // points less. | 655 // points less. |
| 656 // age 0ms: 0.5 | 656 // age 0ms: 0.5 |
| 657 // age 10ms: 1.0 | 657 // age 10ms: 1.0 |
| 658 // age 50ms: 1.0 | 658 // age 50ms: 1.0 |
| 659 // age 60ms: 0.5 | 659 // age 60ms: 0.5 |
| 660 float age_millis = | 660 float age_millis = |
| 661 static_cast<float>((movements_[index_].event_time - | 661 static_cast<float>((movements_[index_].event_time - |
| 662 movements_[index].event_time).InMillisecondsF()); | 662 movements_[index].event_time).InMillisecondsF()); |
| 663 if (age_millis < 0) | 663 if (age_millis < 0) |
| 664 return 0.5f; | 664 return 0.5f; |
| 665 if (age_millis < 10) | 665 if (age_millis < 10) |
| 666 return 0.5f + age_millis * 0.05; | 666 return 0.5f + age_millis * 0.05f; |
| 667 if (age_millis < 50) | 667 if (age_millis < 50) |
| 668 return 1.0f; | 668 return 1.0f; |
| 669 if (age_millis < 60) | 669 if (age_millis < 60) |
| 670 return 0.5f + (60 - age_millis) * 0.05; | 670 return 0.5f + (60 - age_millis) * 0.05f; |
| 671 | 671 |
| 672 return 0.5f; | 672 return 0.5f; |
| 673 } | 673 } |
| 674 | 674 |
| 675 case WEIGHTING_RECENT: { | 675 case WEIGHTING_RECENT: { |
| 676 // Weight points based on their age, weighing older points less. | 676 // Weight points based on their age, weighing older points less. |
| 677 // age 0ms: 1.0 | 677 // age 0ms: 1.0 |
| 678 // age 50ms: 1.0 | 678 // age 50ms: 1.0 |
| 679 // age 100ms: 0.5 | 679 // age 100ms: 0.5 |
| 680 float age_millis = | 680 float age_millis = |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 out_estimator->degree = state.degree; | 809 out_estimator->degree = state.degree; |
| 810 out_estimator->xcoeff[0] = state.xpos; | 810 out_estimator->xcoeff[0] = state.xpos; |
| 811 out_estimator->xcoeff[1] = state.xvel; | 811 out_estimator->xcoeff[1] = state.xvel; |
| 812 out_estimator->xcoeff[2] = state.xaccel / 2; | 812 out_estimator->xcoeff[2] = state.xaccel / 2; |
| 813 out_estimator->ycoeff[0] = state.ypos; | 813 out_estimator->ycoeff[0] = state.ypos; |
| 814 out_estimator->ycoeff[1] = state.yvel; | 814 out_estimator->ycoeff[1] = state.yvel; |
| 815 out_estimator->ycoeff[2] = state.yaccel / 2; | 815 out_estimator->ycoeff[2] = state.yaccel / 2; |
| 816 } | 816 } |
| 817 | 817 |
| 818 } // namespace ui | 818 } // namespace ui |
| OLD | NEW |