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 if (IsEmpty()) | |
31 return gfx::Rect(); | |
32 | |
33 gfx::Point min_point(std::numeric_limits<int>::max(), | |
34 std::numeric_limits<int>::max()); | |
35 gfx::Point max_point(std::numeric_limits<int>::min(), | |
36 std::numeric_limits<int>::min()); | |
37 for (const LaserPoint& point : points_) { | |
38 min_point = gfx::Point(std::min(point.location.x(), min_point.x()), | |
39 std::min(point.location.y(), min_point.y())); | |
40 max_point = gfx::Point(std::max(point.location.x(), max_point.x()), | |
41 std::max(point.location.y(), max_point.y())); | |
42 } | |
43 return gfx::BoundingRect(min_point, max_point); | |
44 } | |
45 | |
46 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const { | |
47 DCHECK(!IsEmpty()); | |
48 return points_.front(); | |
49 } | |
50 | |
51 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { | |
52 DCHECK(!IsEmpty()); | |
53 return points_.back(); | |
54 } | |
55 | |
56 bool LaserPointerPoints::IsEmpty() const { | |
57 return points_.empty(); | |
58 } | |
59 | |
60 int LaserPointerPoints::GetNumberOfPoints() const { | |
61 return points_.size(); | |
62 } | |
63 | |
64 std::deque<LaserPointerPoints::LaserPoint>::const_iterator | |
65 LaserPointerPoints::PointsStart() const { | |
66 return points_.cbegin(); | |
67 } | |
68 | |
69 std::deque<LaserPointerPoints::LaserPoint>::const_iterator | |
70 LaserPointerPoints::PointsEnd() const { | |
71 return points_.cend(); | |
72 } | |
73 | |
74 void LaserPointerPoints::ClearOldPoints() { | |
75 DCHECK(!IsEmpty()); | |
76 auto first_alive_point = | |
77 std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) { | |
78 return this->points_.back().creation_time - p.creation_time < | |
jdufault
2016/08/23 02:11:25
Can you remove the explicit this?
sammiequon
2016/08/23 19:30:02
Done.
| |
79 this->life_duration_; | |
80 }); | |
81 points_.erase(points_.begin(), first_alive_point); | |
82 } | |
83 } // namespace ash | |
OLD | NEW |