blob: 1ff7c683c79828a0d8c4e5f9c4c4cb23fd365243 [file] [log] [blame]
sergeyu@chromium.org85a1dab2013-04-29 20:10:57 +00001/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "webrtc/modules/desktop_capture/desktop_geometry.h"
12
13#include <algorithm>
14
15namespace webrtc {
16
sergeyu@chromium.orgba6d56c2013-10-16 02:48:41 +000017bool DesktopRect::Contains(const DesktopVector& point) const {
18 return point.x() >= left() && point.x() < right() &&
19 point.y() >= top() && point.y() < bottom();
20}
21
sergeyu@chromium.org8b0791c2013-11-19 02:15:47 +000022bool DesktopRect::ContainsRect(const DesktopRect& rect) const {
23 return rect.left() >= left() && rect.right() <= right() &&
24 rect.top() >= top() && rect.bottom() <= bottom();
25}
26
sergeyu@chromium.org85a1dab2013-04-29 20:10:57 +000027void DesktopRect::IntersectWith(const DesktopRect& rect) {
28 left_ = std::max(left(), rect.left());
29 top_ = std::max(top(), rect.top());
30 right_ = std::min(right(), rect.right());
sergeyu@chromium.org60142de2013-05-24 21:07:20 +000031 bottom_ = std::min(bottom(), rect.bottom());
sergeyu@chromium.org85a1dab2013-04-29 20:10:57 +000032 if (is_empty()) {
33 left_ = 0;
34 top_ = 0;
35 right_ = 0;
36 bottom_ = 0;
37 }
38}
39
40void DesktopRect::Translate(int32_t dx, int32_t dy) {
41 left_ += dx;
42 top_ += dy;
43 right_ += dx;
44 bottom_ += dy;
45}
46
47} // namespace webrtc
48