Chromium Code Reviews| Index: ash/common/system/chromeos/palette/tools/laser_pointer_points.cc |
| diff --git a/ash/common/system/chromeos/palette/tools/laser_pointer_points.cc b/ash/common/system/chromeos/palette/tools/laser_pointer_points.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..123dcde2982bb2e4e56f54fc7ce15c42a9fb4f80 |
| --- /dev/null |
| +++ b/ash/common/system/chromeos/palette/tools/laser_pointer_points.cc |
| @@ -0,0 +1,82 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ash/common/system/chromeos/palette/tools/laser_pointer_points.h" |
| + |
| +#include <algorithm> |
| +#include <limits> |
| + |
| +namespace ash { |
| + |
| +LaserPointerPoints::LaserPointerPoints(base::TimeDelta life_duration) |
| + : life_duration_(life_duration) {} |
| + |
| +LaserPointerPoints::~LaserPointerPoints() {} |
| + |
| +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.
|
| + LaserPoint new_point; |
| + new_point.location = point; |
| + new_point.creation_time = base::Time::Now(); |
| + points_.push_back(new_point); |
| + ClearOldPoints(); |
| +} |
| + |
| +void LaserPointerPoints::Clear() { |
| + points_.clear(); |
| +} |
| + |
| +gfx::Rect LaserPointerPoints::GetBoundingBox() { |
| + if (IsEmpty()) |
| + return gfx::Rect(); |
| + |
| + gfx::Point min_point(std::numeric_limits<int>::max(), |
| + std::numeric_limits<int>::max()); |
| + gfx::Point max_point(std::numeric_limits<int>::min(), |
| + std::numeric_limits<int>::min()); |
| + for (const LaserPoint& point : points_) { |
| + min_point = gfx::Point(std::min(point.location.x(), min_point.x()), |
| + std::min(point.location.y(), min_point.y())); |
| + max_point = gfx::Point(std::max(point.location.x(), max_point.x()), |
| + std::max(point.location.y(), max_point.y())); |
| + } |
| + return gfx::BoundingRect(min_point, max_point); |
| +} |
| + |
| +LaserPointerPoints::LaserPoint LaserPointerPoints::GetOldest() const { |
| + DCHECK(!IsEmpty()); |
| + return points_.front(); |
| +} |
| + |
| +LaserPointerPoints::LaserPoint LaserPointerPoints::GetNewest() const { |
| + DCHECK(!IsEmpty()); |
| + return points_.back(); |
| +} |
| + |
| +bool LaserPointerPoints::IsEmpty() const { |
| + return points_.empty(); |
| +} |
| + |
| +int LaserPointerPoints::GetNumberOfPoints() const { |
| + return points_.size(); |
| +} |
| + |
| +std::deque<LaserPointerPoints::LaserPoint>::const_iterator |
| +LaserPointerPoints::PointsStart() const { |
| + return points_.cbegin(); |
| +} |
| + |
| +std::deque<LaserPointerPoints::LaserPoint>::const_iterator |
| +LaserPointerPoints::PointsEnd() const { |
| + return points_.cend(); |
| +} |
| + |
| +void LaserPointerPoints::ClearOldPoints() { |
| + DCHECK(!IsEmpty()); |
| + auto first_alive_point = |
| + std::find_if(points_.begin(), points_.end(), [this](LaserPoint& p) { |
| + 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.
|
| + }); |
| + points_.erase(points_.begin(), first_alive_point); |
| +} |
| +} // namespace ash |