sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 15 | namespace webrtc { |
| 16 | |
sergeyu@chromium.org | ba6d56c | 2013-10-16 02:48:41 +0000 | [diff] [blame^] | 17 | bool 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.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 22 | void DesktopRect::IntersectWith(const DesktopRect& rect) { |
| 23 | left_ = std::max(left(), rect.left()); |
| 24 | top_ = std::max(top(), rect.top()); |
| 25 | right_ = std::min(right(), rect.right()); |
sergeyu@chromium.org | 60142de | 2013-05-24 21:07:20 +0000 | [diff] [blame] | 26 | bottom_ = std::min(bottom(), rect.bottom()); |
sergeyu@chromium.org | 85a1dab | 2013-04-29 20:10:57 +0000 | [diff] [blame] | 27 | if (is_empty()) { |
| 28 | left_ = 0; |
| 29 | top_ = 0; |
| 30 | right_ = 0; |
| 31 | bottom_ = 0; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void DesktopRect::Translate(int32_t dx, int32_t dy) { |
| 36 | left_ += dx; |
| 37 | top_ += dy; |
| 38 | right_ += dx; |
| 39 | bottom_ += dy; |
| 40 | } |
| 41 | |
| 42 | } // namespace webrtc |
| 43 | |