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

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: Rebased. Created 4 years, 3 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) {
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 = GetOldest().location;
34 gfx::Point max_point = GetOldest().location;
35 for (const LaserPoint& point : points_) {
36 min_point.SetToMin(point.location);
37 max_point.SetToMax(point.location);
38 }
39 return gfx::BoundingRect(min_point, max_point);
40 }
41
42 LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const {
43 DCHECK(!IsEmpty());
44 return points_.front();
45 }
46
47 LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const {
48 DCHECK(!IsEmpty());
49 return points_.back();
50 }
51
52 bool LaserPointerPoints::IsEmpty() const {
53 return points_.empty();
54 }
55
56 int LaserPointerPoints::GetNumberOfPoints() const {
57 return points_.size();
58 }
59
60 const std::deque<LaserPointerPoints::LaserPoint>&
61 LaserPointerPoints::laser_points() {
62 return points_;
63 }
64
65 void LaserPointerPoints::ClearOldPoints() {
66 DCHECK(!IsEmpty());
67 auto first_alive_point =
68 std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) {
69 return GetNewest().creation_time - p.creation_time < life_duration_;
70 });
71 points_.erase(points_.begin(), first_alive_point);
72 }
73
74 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698