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

Side by Side Diff: ash/common/system/chromeos/palette/tools/laser_pointer_points.cc

Issue 2239743004: Palette tool laser prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@patch
Patch Set: Fixed patch set 4 errors. Created 4 years, 4 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
OLDNEW
(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 <limits>
8
9 namespace ash {
10
11 LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration)
12 : life_duration_(life_duration) {}
13
14 LaserPointerPoints::~LaserPointerPoints() {}
15
16 void LaserPointerPoints::AddPoint(const gfx::Point& point) {
17 LaserPoint new_point;
18 new_point.location = point;
19 new_point.creation_time = base::Time::Now();
20 points_.push_back(new_point);
21 ClearOldPoints();
22 }
23
24 void LaserPointerPoints::Clear() {
25 points_.clear();
26 }
27
28 gfx::Rect LaserPointerPoints::GetBoundingBox() {
29 gfx::Point min_point(INT_MAX, INT_MAX);
jdufault 2016/08/19 01:02:08 std::numeric_limits<int64_t>::max() (or whatever t
sammiequon 2016/08/19 20:28:46 Done.
30 gfx::Point max_point(INT_MIN, INT_MIN);
31 for (auto it = points_.begin(); it != points_.end(); it++) {
jdufault 2016/08/19 01:02:08 for (const LaserPoint& point : points_)
sammiequon 2016/08/19 20:28:46 Done.
32 min_point = gfx::Point(std::min(it->location.x(), min_point.x()),
33 std::min(it->location.y(), min_point.y()));
34 max_point = gfx::Point(std::max(it->location.x(), max_point.x()),
35 std::max(it->location.y(), max_point.y()));
36 }
37 return gfx::BoundingRect(min_point, max_point);
38 }
39
40 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const {
41 DCHECK(!IsEmpty());
42 return points_.front();
43 }
44
45 LaserPointerPoints::LaserPoint LaserPointerPoints::GetMostRecent() const {
46 DCHECK(!IsEmpty());
47 return points_.back();
48 }
49
50 bool LaserPointerPoints::IsEmpty() const {
51 return points_.empty();
52 }
53
54 int LaserPointerPoints::GetNumberOfPoints() const {
55 return points_.size();
56 }
57
58 std::deque<LaserPointerPoints::LaserPoint>::const_iterator
59 LaserPointerPoints::PointsStart() const {
60 return points_.cbegin();
61 }
62
63 std::deque<LaserPointerPoints::LaserPoint>::const_iterator
64 LaserPointerPoints::PointsEnd() const {
65 return points_.cend();
66 }
67
68 void LaserPointerPoints::ClearOldPoints() {
jdufault 2016/08/19 01:02:08 This only gets called after a point has been added
sammiequon 2016/08/19 20:28:46 Done.
69 if (!points_.empty()) {
70 LaserPoint newest = points_.back();
71 auto it = points_.begin();
jdufault 2016/08/19 01:02:08 What about auto it = std::find_if(points_.begin
sammiequon 2016/08/19 20:28:46 Done.
72 for (; it != points_.end(); ++it) {
73 if (newest.creation_time - it->creation_time > life_duration_) {
74 } else {
75 // Since the points are sorted by time we can end the loop early once
76 // the condition fails.
77 break;
78 }
79 }
80 points_.erase(points_.begin(), it);
81 }
82 }
83 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698