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

Side by Side Diff: ash/laser/laser_pointer_points.cc

Issue 2745953002: ash: Add basic prediction code to the laser pointer. (Closed)
Patch Set: more tests and nits Created 3 years, 9 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
« no previous file with comments | « ash/laser/laser_pointer_points.h ('k') | ash/laser/laser_pointer_points_test_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ash/laser/laser_pointer_points.h" 5 #include "ash/laser/laser_pointer_points.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "ui/gfx/geometry/rect_conversions.h" 10 #include "ui/gfx/geometry/rect_conversions.h"
11 11
12 namespace ash { 12 namespace ash {
13 13
14 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) 14 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
15 : life_duration_(life_duration) {} 15 : life_duration_(life_duration) {}
16 16
17 LaserPointerPoints::~LaserPointerPoints() {} 17 LaserPointerPoints::~LaserPointerPoints() {}
18 18
19 void LaserPointerPoints::AddPoint(const gfx::PointF& point) { 19 void LaserPointerPoints::AddPoint(const gfx::PointF& point,
20 MoveForwardToTime(base::Time::Now()); 20 const base::TimeTicks& time) {
21 // Move forward in time if needed.
22 if (time > collection_latest_time_)
23 MoveForwardToTime(time);
21 24
22 LaserPoint new_point; 25 LaserPoint new_point;
23 new_point.location = point; 26 new_point.location = point;
27 new_point.time = time;
28 new_point.age = std::min((collection_latest_time_ - time).InMillisecondsF() /
29 life_duration_.InMillisecondsF(),
30 1.0);
24 points_.push_back(new_point); 31 points_.push_back(new_point);
25 } 32 }
26 33
27 void LaserPointerPoints::MoveForwardToTime(const base::Time& latest_time) { 34 void LaserPointerPoints::MoveForwardToTime(const base::TimeTicks& latest_time) {
35 DCHECK_GE(latest_time, collection_latest_time_);
36
28 if (!points_.empty()) { 37 if (!points_.empty()) {
29 DCHECK(!collection_latest_time_.is_null()); 38 DCHECK(!collection_latest_time_.is_null());
30 39
31 // Increase the age of points based on how much time has elapsed. 40 // Increase the age of points based on how much time has elapsed.
32 base::TimeDelta delta = latest_time - collection_latest_time_; 41 base::TimeDelta delta = latest_time - collection_latest_time_;
33 double lifespan_change = 42 double lifespan_change =
34 delta.InMillisecondsF() / life_duration_.InMillisecondsF(); 43 delta.InMillisecondsF() / life_duration_.InMillisecondsF();
35 for (LaserPoint& point : points_) 44 for (LaserPoint& point : points_)
36 point.age += lifespan_change; 45 point.age += lifespan_change;
37 46
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 82
74 bool LaserPointerPoints::IsEmpty() const { 83 bool LaserPointerPoints::IsEmpty() const {
75 return points_.empty(); 84 return points_.empty();
76 } 85 }
77 86
78 int LaserPointerPoints::GetNumberOfPoints() const { 87 int LaserPointerPoints::GetNumberOfPoints() const {
79 return points_.size(); 88 return points_.size();
80 } 89 }
81 90
82 const std::deque<LaserPointerPoints::LaserPoint>& 91 const std::deque<LaserPointerPoints::LaserPoint>&
83 LaserPointerPoints::laser_points() { 92 LaserPointerPoints::laser_points() const {
84 return points_; 93 return points_;
85 } 94 }
86 } // namespace ash 95 } // namespace ash
OLDNEW
« no previous file with comments | « ash/laser/laser_pointer_points.h ('k') | ash/laser/laser_pointer_points_test_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698