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

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 8 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 <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) {
jdufault 2016/08/23 21:52:05 Instead of using base::Time::Now(), it might look
sammiequon 2016/08/24 00:04:05 I was wondering if the event times might be a litt
jdufault 2016/08/24 00:20:57 What do you mean by conflict with the times that t
sammiequon 2016/08/24 17:30:19 As per offline chat, this will stay the same.
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 points_.back().creation_time - p.creation_time < life_duration_;
jdufault 2016/08/23 21:52:05 Use GetNewest()
sammiequon 2016/08/24 00:04:04 Done.
79 });
80 points_.erase(points_.begin(), first_alive_point);
81 }
82 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698