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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 }; | 114 }; |
115 | 115 |
116 // Number of samples to keep. | 116 // Number of samples to keep. |
117 enum { HISTORY_SIZE = 20 }; | 117 enum { HISTORY_SIZE = 20 }; |
118 | 118 |
119 // Degree must be no greater than Estimator::MAX_DEGREE. | 119 // Degree must be no greater than Estimator::MAX_DEGREE. |
120 LeastSquaresVelocityTrackerStrategy(uint32_t degree, | 120 LeastSquaresVelocityTrackerStrategy(uint32_t degree, |
121 Weighting weighting = WEIGHTING_NONE); | 121 Weighting weighting = WEIGHTING_NONE); |
122 virtual ~LeastSquaresVelocityTrackerStrategy(); | 122 virtual ~LeastSquaresVelocityTrackerStrategy(); |
123 | 123 |
124 virtual void Clear() OVERRIDE; | 124 virtual void Clear() override; |
125 virtual void ClearPointers(BitSet32 id_bits) OVERRIDE; | 125 virtual void ClearPointers(BitSet32 id_bits) override; |
126 virtual void AddMovement(const TimeTicks& event_time, | 126 virtual void AddMovement(const TimeTicks& event_time, |
127 BitSet32 id_bits, | 127 BitSet32 id_bits, |
128 const Position* positions) OVERRIDE; | 128 const Position* positions) override; |
129 virtual bool GetEstimator(uint32_t id, | 129 virtual bool GetEstimator(uint32_t id, |
130 Estimator* out_estimator) const OVERRIDE; | 130 Estimator* out_estimator) const override; |
131 | 131 |
132 private: | 132 private: |
133 // Sample horizon. | 133 // Sample horizon. |
134 // We don't use too much history by default since we want to react to quick | 134 // We don't use too much history by default since we want to react to quick |
135 // changes in direction. | 135 // changes in direction. |
136 enum { HORIZON_MS = 100 }; | 136 enum { HORIZON_MS = 100 }; |
137 | 137 |
138 struct Movement { | 138 struct Movement { |
139 TimeTicks event_time; | 139 TimeTicks event_time; |
140 BitSet32 id_bits; | 140 BitSet32 id_bits; |
(...skipping 12 matching lines...) Expand all Loading... |
153 Movement movements_[HISTORY_SIZE]; | 153 Movement movements_[HISTORY_SIZE]; |
154 }; | 154 }; |
155 | 155 |
156 // Velocity tracker algorithm that uses an IIR filter. | 156 // Velocity tracker algorithm that uses an IIR filter. |
157 class IntegratingVelocityTrackerStrategy : public VelocityTrackerStrategy { | 157 class IntegratingVelocityTrackerStrategy : public VelocityTrackerStrategy { |
158 public: | 158 public: |
159 // Degree must be 1 or 2. | 159 // Degree must be 1 or 2. |
160 explicit IntegratingVelocityTrackerStrategy(uint32_t degree); | 160 explicit IntegratingVelocityTrackerStrategy(uint32_t degree); |
161 virtual ~IntegratingVelocityTrackerStrategy(); | 161 virtual ~IntegratingVelocityTrackerStrategy(); |
162 | 162 |
163 virtual void Clear() OVERRIDE; | 163 virtual void Clear() override; |
164 virtual void ClearPointers(BitSet32 id_bits) OVERRIDE; | 164 virtual void ClearPointers(BitSet32 id_bits) override; |
165 virtual void AddMovement(const TimeTicks& event_time, | 165 virtual void AddMovement(const TimeTicks& event_time, |
166 BitSet32 id_bits, | 166 BitSet32 id_bits, |
167 const Position* positions) OVERRIDE; | 167 const Position* positions) override; |
168 virtual bool GetEstimator(uint32_t id, | 168 virtual bool GetEstimator(uint32_t id, |
169 Estimator* out_estimator) const OVERRIDE; | 169 Estimator* out_estimator) const override; |
170 | 170 |
171 private: | 171 private: |
172 // Current state estimate for a particular pointer. | 172 // Current state estimate for a particular pointer. |
173 struct State { | 173 struct State { |
174 TimeTicks update_time; | 174 TimeTicks update_time; |
175 uint32_t degree; | 175 uint32_t degree; |
176 | 176 |
177 float xpos, xvel, xaccel; | 177 float xpos, xvel, xaccel; |
178 float ypos, yvel, yaccel; | 178 float ypos, yvel, yaccel; |
179 }; | 179 }; |
(...skipping 629 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 |