desktop_geometry.cc (2189B)
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 "modules/desktop_capture/desktop_geometry.h" 12 13 #include <algorithm> 14 #include <cmath> 15 #include <cstdint> 16 17 namespace webrtc { 18 19 bool DesktopRect::Contains(const DesktopVector& point) const { 20 return point.x() >= left() && point.x() < right() && point.y() >= top() && 21 point.y() < bottom(); 22 } 23 24 bool DesktopRect::ContainsRect(const DesktopRect& rect) const { 25 return rect.left() >= left() && rect.right() <= right() && 26 rect.top() >= top() && rect.bottom() <= bottom(); 27 } 28 29 void DesktopRect::IntersectWith(const DesktopRect& rect) { 30 left_ = std::max(left(), rect.left()); 31 top_ = std::max(top(), rect.top()); 32 right_ = std::min(right(), rect.right()); 33 bottom_ = std::min(bottom(), rect.bottom()); 34 if (is_empty()) { 35 left_ = 0; 36 top_ = 0; 37 right_ = 0; 38 bottom_ = 0; 39 } 40 } 41 42 void DesktopRect::UnionWith(const DesktopRect& rect) { 43 if (is_empty()) { 44 *this = rect; 45 return; 46 } 47 48 if (rect.is_empty()) { 49 return; 50 } 51 52 left_ = std::min(left(), rect.left()); 53 top_ = std::min(top(), rect.top()); 54 right_ = std::max(right(), rect.right()); 55 bottom_ = std::max(bottom(), rect.bottom()); 56 } 57 58 void DesktopRect::Translate(int32_t dx, int32_t dy) { 59 left_ += dx; 60 top_ += dy; 61 right_ += dx; 62 bottom_ += dy; 63 } 64 65 void DesktopRect::Extend(int32_t left_offset, 66 int32_t top_offset, 67 int32_t right_offset, 68 int32_t bottom_offset) { 69 left_ -= left_offset; 70 top_ -= top_offset; 71 right_ += right_offset; 72 bottom_ += bottom_offset; 73 } 74 75 void DesktopRect::Scale(double horizontal, double vertical) { 76 right_ += static_cast<int>(std::round(width() * (horizontal - 1))); 77 bottom_ += static_cast<int>(std::round(height() * (vertical - 1))); 78 } 79 80 } // namespace webrtc