Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 namespace ash { | 10 namespace ash { |
| 11 | 11 |
| 12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) | 12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) |
| 13 : life_duration_(life_duration) {} | 13 : life_duration_(life_duration) {} |
| 14 | 14 |
| 15 LaserPointerPoints::~LaserPointerPoints() {} | 15 LaserPointerPoints::~LaserPointerPoints() {} |
| 16 | 16 |
| 17 void LaserPointerPoints::AddPoint(const gfx::Point& point) { | 17 void LaserPointerPoints::AddPoint(const gfx::Point& point) { |
| 18 LaserPoint new_point; | 18 LaserPoint new_point; |
| 19 new_point.location = point; | 19 new_point.location = point; |
| 20 new_point.creation_time = base::Time::Now(); | 20 new_point.age = 0.0; |
| 21 MoveForwardToTime(base::Time::Now()); | |
|
jdufault
2016/10/05 21:36:05
Call this at the start of the function. It's needl
sammiequon
2016/10/06 00:19:15
Done.
| |
| 21 points_.push_back(new_point); | 22 points_.push_back(new_point); |
| 23 } | |
| 24 | |
| 25 void LaserPointerPoints::MoveForwardToCurrentTime() { | |
| 26 MoveForwardToTime(base::Time::Now()); | |
| 27 } | |
| 28 | |
| 29 void LaserPointerPoints::MoveForwardToTime(const base::Time& new_latest_time) { | |
|
jdufault
2016/10/05 21:36:05
Drop new_ on new_latest_time_, it is redundant.
sammiequon
2016/10/06 00:19:15
Done.
| |
| 30 if (collection_latest_time_.is_null()) | |
| 31 collection_latest_time_ = new_latest_time; | |
|
jdufault
2016/10/05 21:36:05
If this is true then points_ must be empty, right?
sammiequon
2016/10/06 00:19:15
It seems DCHECK_IMPLIES is only used in v8 stuff.
| |
| 32 | |
| 33 // Update the ages of the points based on the change in new latest time. | |
| 34 base::TimeDelta delta = new_latest_time - collection_latest_time_; | |
| 35 double lifespan_change = | |
| 36 delta.InMillisecondsF() / life_duration_.InMillisecondsF(); | |
| 37 for (LaserPoint& point : points_) | |
| 38 point.age += lifespan_change; | |
| 22 ClearOldPoints(); | 39 ClearOldPoints(); |
|
jdufault
2016/10/05 21:36:05
Call ClearOldPoints after updating collection_late
sammiequon
2016/10/06 00:19:15
Done.
| |
| 40 collection_latest_time_ = new_latest_time; | |
| 23 } | 41 } |
| 24 | 42 |
| 25 void LaserPointerPoints::Clear() { | 43 void LaserPointerPoints::Clear() { |
| 26 points_.clear(); | 44 points_.clear(); |
| 27 } | 45 } |
| 28 | 46 |
| 29 gfx::Rect LaserPointerPoints::GetBoundingBox() { | 47 gfx::Rect LaserPointerPoints::GetBoundingBox() { |
| 30 if (IsEmpty()) | 48 if (IsEmpty()) |
| 31 return gfx::Rect(); | 49 return gfx::Rect(); |
| 32 | 50 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 55 | 73 |
| 56 int LaserPointerPoints::GetNumberOfPoints() const { | 74 int LaserPointerPoints::GetNumberOfPoints() const { |
| 57 return points_.size(); | 75 return points_.size(); |
| 58 } | 76 } |
| 59 | 77 |
| 60 const std::deque<LaserPointerPoints::LaserPoint>& | 78 const std::deque<LaserPointerPoints::LaserPoint>& |
| 61 LaserPointerPoints::laser_points() { | 79 LaserPointerPoints::laser_points() { |
| 62 return points_; | 80 return points_; |
| 63 } | 81 } |
| 64 | 82 |
| 65 void LaserPointerPoints::ClearOldPoints() { | 83 void LaserPointerPoints::ClearOldPoints() { |
|
jdufault
2016/10/05 21:36:05
It looks like the only caller of this method is Mo
sammiequon
2016/10/06 00:19:15
Done.
| |
| 66 DCHECK(!IsEmpty()); | |
| 67 auto first_alive_point = | 84 auto first_alive_point = |
| 68 std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) { | 85 std::find_if(points_.begin(), points_.end(), |
| 69 return GetNewest().creation_time - p.creation_time < life_duration_; | 86 [](LaserPoint& p) { return p.age < 1.0; }); |
| 70 }); | |
| 71 points_.erase(points_.begin(), first_alive_point); | 87 points_.erase(points_.begin(), first_alive_point); |
| 72 } | 88 } |
| 73 | |
| 74 } // namespace ash | 89 } // namespace ash |
| OLD | NEW |