Chromium Code Reviews| Index: ui/events/gesture_detection/velocity_tracker.cc |
| diff --git a/ui/events/gesture_detection/velocity_tracker.cc b/ui/events/gesture_detection/velocity_tracker.cc |
| index a3fd83e2e22247b6f9c77e04c10b39e65246c678..482e6a05780bd0a92cc38bbc2ca9945155179096 100644 |
| --- a/ui/events/gesture_detection/velocity_tracker.cc |
| +++ b/ui/events/gesture_detection/velocity_tracker.cc |
| @@ -51,13 +51,13 @@ struct Position { |
| }; |
| struct Estimator { |
| - enum { MAX_DEGREE = 4 }; |
| + static const uint8_t kMaxDegree = 4; |
| // Estimator time base. |
| TimeTicks time; |
| // Polynomial coefficients describing motion in X and Y. |
| - float xcoeff[MAX_DEGREE + 1], ycoeff[MAX_DEGREE + 1]; |
| + float xcoeff[kMaxDegree + 1], ycoeff[kMaxDegree + 1]; |
| // Polynomial degree (number of coefficients), or zero if no information is |
| // available. |
| @@ -71,7 +71,7 @@ struct Estimator { |
| time = TimeTicks(); |
| degree = 0; |
| confidence = 0; |
| - for (size_t i = 0; i <= MAX_DEGREE; i++) { |
| + for (size_t i = 0; i <= kMaxDegree; i++) { |
| xcoeff[i] = 0; |
| ycoeff[i] = 0; |
| } |
| @@ -114,9 +114,9 @@ class LeastSquaresVelocityTrackerStrategy : public VelocityTrackerStrategy { |
| }; |
| // Number of samples to keep. |
| - enum { HISTORY_SIZE = 20 }; |
| + static const uint8_t kHistorySize = 20; |
| - // Degree must be no greater than Estimator::MAX_DEGREE. |
| + // Degree must be no greater than Estimator::kMaxDegree. |
| LeastSquaresVelocityTrackerStrategy(uint32_t degree, |
| Weighting weighting = WEIGHTING_NONE); |
| virtual ~LeastSquaresVelocityTrackerStrategy(); |
| @@ -133,7 +133,7 @@ class LeastSquaresVelocityTrackerStrategy : public VelocityTrackerStrategy { |
| // Sample horizon. |
| // We don't use too much history by default since we want to react to quick |
| // changes in direction. |
| - enum { HORIZON_MS = 100 }; |
| + static const uint8_t kHorizonMS = 100; |
| struct Movement { |
| TimeTicks event_time; |
| @@ -150,7 +150,7 @@ class LeastSquaresVelocityTrackerStrategy : public VelocityTrackerStrategy { |
| const uint32_t degree_; |
| const Weighting weighting_; |
| uint32_t index_; |
| - Movement movements_[HISTORY_SIZE]; |
| + Movement movements_[kHistorySize]; |
| }; |
| // Velocity tracker algorithm that uses an IIR filter. |
| @@ -371,7 +371,7 @@ void LeastSquaresVelocityTrackerStrategy::AddMovement( |
| const TimeTicks& event_time, |
| BitSet32 id_bits, |
| const Position* positions) { |
| - if (++index_ == HISTORY_SIZE) { |
| + if (++index_ == kHistorySize) { |
| index_ = 0; |
| } |
| @@ -395,7 +395,7 @@ LeastSquaresVelocityTrackerStrategy::LeastSquaresVelocityTrackerStrategy( |
| uint32_t degree, |
| Weighting weighting) |
| : degree_(degree), weighting_(weighting) { |
| - DCHECK_LT(degree_, static_cast<uint32_t>(Estimator::MAX_DEGREE)); |
| + DCHECK_LT(degree_, static_cast<uint32_t>(Estimator::kMaxDegree)); |
| Clear(); |
| } |
| @@ -469,12 +469,9 @@ static bool SolveLeastSquares(const float* x, |
| // MSVC does not support variable-length arrays (used by the original Android |
| // implementation of this function). |
| #if defined(COMPILER_MSVC) |
| - enum { |
| - M_ARRAY_LENGTH = LeastSquaresVelocityTrackerStrategy::HISTORY_SIZE, |
| - N_ARRAY_LENGTH = Estimator::MAX_DEGREE |
| - }; |
| - DCHECK_LE(m, static_cast<uint32_t>(M_ARRAY_LENGTH)); |
|
tdresser
2014/10/20 14:27:31
These DCHECKs are still relevant, aren't they?
Chris Masone
2014/10/20 16:05:22
Yes, you're right
|
| - DCHECK_LE(n, static_cast<uint32_t>(N_ARRAY_LENGTH)); |
| + const uint32_t M_ARRAY_LENGTH = |
| + LeastSquaresVelocityTrackerStrategy::kHistorySize; |
| + const uint32_t N_ARRAY_LENGTH = Estimator::kMaxDegree; |
| #else |
| const uint32_t M_ARRAY_LENGTH = m; |
| const uint32_t N_ARRAY_LENGTH = n; |
| @@ -573,13 +570,13 @@ bool LeastSquaresVelocityTrackerStrategy::GetEstimator( |
| out_estimator->Clear(); |
| // Iterate over movement samples in reverse time order and collect samples. |
| - float x[HISTORY_SIZE]; |
| - float y[HISTORY_SIZE]; |
| - float w[HISTORY_SIZE]; |
| - float time[HISTORY_SIZE]; |
| + float x[kHistorySize]; |
| + float y[kHistorySize]; |
| + float w[kHistorySize]; |
| + float time[kHistorySize]; |
| uint32_t m = 0; |
| uint32_t index = index_; |
| - const base::TimeDelta horizon = base::TimeDelta::FromMilliseconds(HORIZON_MS); |
| + const base::TimeDelta horizon = base::TimeDelta::FromMilliseconds(kHorizonMS); |
| const Movement& newest_movement = movements_[index_]; |
| do { |
| const Movement& movement = movements_[index]; |
| @@ -595,8 +592,8 @@ bool LeastSquaresVelocityTrackerStrategy::GetEstimator( |
| y[m] = position.y; |
| w[m] = ChooseWeight(index); |
| time[m] = -age.InSecondsF(); |
| - index = (index == 0 ? HISTORY_SIZE : index) - 1; |
| - } while (++m < HISTORY_SIZE); |
| + index = (index == 0 ? kHistorySize : index) - 1; |
| + } while (++m < kHistorySize); |
| if (m == 0) |
| return false; // no data |
| @@ -638,7 +635,7 @@ float LeastSquaresVelocityTrackerStrategy::ChooseWeight(uint32_t index) const { |
| if (index == index_) { |
| return 1.0f; |
| } |
| - uint32_t next_index = (index + 1) % HISTORY_SIZE; |
| + uint32_t next_index = (index + 1) % kHistorySize; |
| float delta_millis = |
| static_cast<float>((movements_[next_index].event_time - |
| movements_[index].event_time).InMillisecondsF()); |
| @@ -700,7 +697,7 @@ float LeastSquaresVelocityTrackerStrategy::ChooseWeight(uint32_t index) const { |
| IntegratingVelocityTrackerStrategy::IntegratingVelocityTrackerStrategy( |
| uint32_t degree) |
| : degree_(degree) { |
| - DCHECK_LT(degree_, static_cast<uint32_t>(Estimator::MAX_DEGREE)); |
| + DCHECK_LT(degree_, static_cast<uint32_t>(Estimator::kMaxDegree)); |
| } |
| IntegratingVelocityTrackerStrategy::~IntegratingVelocityTrackerStrategy() {} |