You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.1 KiB

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