Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/common/system/chromeos/palette/tools/laser_pointer_points.h" | |
| 6 | |
| 7 #include <algorithm> | |
| 8 #include <limits> | |
| 9 | |
| 10 namespace ash { | |
| 11 | |
| 12 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) | |
| 13 : life_duration_(life_duration) {} | |
| 14 | |
| 15 LaserPointerPoints::~LaserPointerPoints() {} | |
| 16 | |
| 17 void LaserPointerPoints::AddPoint(const gfx::Point& point) { | |
| 18 LaserPoint new_point; | |
| 19 new_point.location = point; | |
| 20 new_point.creation_time = base::Time::Now(); | |
| 21 points_.push_back(new_point); | |
| 22 ClearOldPoints(); | |
| 23 } | |
| 24 | |
| 25 void LaserPointerPoints::Clear() { | |
| 26 points_.clear(); | |
| 27 } | |
| 28 | |
| 29 gfx::Rect LaserPointerPoints::GetBoundingBox() { | |
| 30 gfx::Point min_point(std::numeric_limits<int>::max(), | |
| 31 std::numeric_limits<int>::max()); | |
| 32 gfx::Point max_point(std::numeric_limits<int>::min(), | |
| 33 std::numeric_limits<int>::min()); | |
| 34 for (const LaserPoint& point : points_) { | |
| 35 min_point = gfx::Point(std::min(point.location.x(), min_point.x()), | |
| 36 std::min(point.location.y(), min_point.y())); | |
| 37 max_point = gfx::Point(std::max(point.location.x(), max_point.x()), | |
| 38 std::max(point.location.y(), max_point.y())); | |
| 39 } | |
| 40 return gfx::BoundingRect(min_point, max_point); | |
| 41 } | |
| 42 | |
| 43 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const { | |
| 44 DCHECK(!IsEmpty()); | |
| 45 return points_.front(); | |
| 46 } | |
| 47 | |
| 48 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { | |
| 49 DCHECK(!IsEmpty()); | |
| 50 return points_.back(); | |
| 51 } | |
| 52 | |
| 53 bool LaserPointerPoints::IsEmpty() const { | |
| 54 return points_.empty(); | |
| 55 } | |
| 56 | |
| 57 int LaserPointerPoints::GetNumberOfPoints() const { | |
| 58 return points_.size(); | |
| 59 } | |
| 60 | |
| 61 std::deque<LaserPointerPoints::LaserPoint>::const_iterator | |
| 62 LaserPointerPoints::PointsStart() const { | |
| 63 return points_.cbegin(); | |
| 64 } | |
| 65 | |
| 66 std::deque<LaserPointerPoints::LaserPoint>::const_iterator | |
| 67 LaserPointerPoints::PointsEnd() const { | |
| 68 return points_.cend(); | |
| 69 } | |
| 70 | |
| 71 void LaserPointerPoints::ClearOldPoints() { | |
| 72 DCHECK(!IsEmpty()); | |
| 73 LaserPoint newest = points_.back(); | |
| 74 base::TimeDelta life_duration = life_duration_; | |
| 75 auto first_alive_point = std::find_if( | |
| 76 points_.begin(), points_.end(), [&newest, &life_duration](LaserPoint& p) { | |
|
jdufault
2016/08/22 18:37:36
Can you capture [this] and use points_.back() and
sammiequon
2016/08/23 00:20:33
Done.
| |
| 77 return newest.creation_time - p.creation_time < life_duration; | |
| 78 }); | |
| 79 points_.erase(points_.begin(), first_alive_point); | |
| 80 } | |
| 81 } // namespace ash | |
| OLD | NEW |