diff options
author | Gyuhwan Park★ <unstabler@unstabler.pl> | 2023-02-08 20:57:52 +0300 |
---|---|---|
committer | Gyuhwan Park★ <unstabler@unstabler.pl> | 2023-02-08 20:57:52 +0300 |
commit | 93c352b20d2ffa483824d30aec5e9bb4a717e084 (patch) | |
tree | 73ea5e5a0b25ede5c8273fb44154518b9d5b7854 | |
parent | 1e20ccc21266366f3715fac484c2545f6d142b97 (diff) |
fix: merge overlapped rects
-rw-r--r-- | XrdpUlalacaPrivate.cpp | 46 | ||||
-rw-r--r-- | XrdpUlalacaPrivate.hpp | 4 |
2 files changed, 50 insertions, 0 deletions
diff --git a/XrdpUlalacaPrivate.cpp b/XrdpUlalacaPrivate.cpp index b8ea399..d2a49cf 100644 --- a/XrdpUlalacaPrivate.cpp +++ b/XrdpUlalacaPrivate.cpp @@ -126,7 +126,53 @@ std::unique_ptr<std::vector<ULIPCRect>> XrdpUlalacaPrivate::createCopyRects( return std::move(blocks); } +bool XrdpUlalacaPrivate::isRectOverlaps(const ULIPCRect &a, const ULIPCRect &b) { + int16_t a_x1 = a.x; + int16_t a_x2 = a.x + a.width; + int16_t a_y1 = a.y; + int16_t a_y2 = a.y + a.height; + int16_t b_x1 = b.x; + int16_t b_x2 = b.x + b.width; + int16_t b_y1 = b.y; + int16_t b_y2 = b.y + b.height; + + return ( + (a_x1 >= b_x1 && a_x1 <= b_x2 && a_y1 >= b_y1 && a_y1 <= b_y2) || + (a_x2 >= b_x1 && a_x2 <= b_x2 && a_y1 >= b_y1 && a_y1 <= b_y2) || + (a_x1 >= b_x1 && a_x1 <= b_x2 && a_y2 >= b_y1 && a_y2 <= b_y2) || + (a_x2 >= b_x1 && a_x2 <= b_x2 && a_y2 >= b_y1 && a_y2 <= b_y2) + ); +} + +void XrdpUlalacaPrivate::mergeRect(ULIPCRect &a, const ULIPCRect &b) { + int16_t a_x1 = a.x; + int16_t a_x2 = a.x + a.width; + int16_t a_y1 = a.y; + int16_t a_y2 = a.y + a.height; + int16_t b_x1 = b.x; + int16_t b_x2 = b.x + b.width; + int16_t b_y1 = b.y; + int16_t b_y2 = b.y + b.height; + + a.x = std::min(a_x1, b_x1); + a.y = std::min(a_y1, b_y1); + a.width = std::max(a_x2, b_x2) - a.x; + a.height = std::max(a_y2, b_y2) - a.y; +} + +std::vector<ULIPCRect> XrdpUlalacaPrivate::removeRectOverlap(const ULIPCRect &a, const ULIPCRect &b) { + +} + void XrdpUlalacaPrivate::addDirtyRect(ULIPCRect &rect) { + for (auto &x: *_dirtyRects) { + if (isRectOverlaps(x, rect)) { + mergeRect(x, rect); + return; + } + } + + _dirtyRects->push_back(rect); } diff --git a/XrdpUlalacaPrivate.hpp b/XrdpUlalacaPrivate.hpp index 50f60ba..0125c01 100644 --- a/XrdpUlalacaPrivate.hpp +++ b/XrdpUlalacaPrivate.hpp @@ -45,6 +45,10 @@ public: constexpr static const int NO_ERROR = 0; + static bool isRectOverlaps(const ULIPCRect &a, const ULIPCRect &b); + static void mergeRect(ULIPCRect &a, const ULIPCRect &b); + static std::vector<ULIPCRect> removeRectOverlap(const ULIPCRect &a, const ULIPCRect &b); + explicit XrdpUlalacaPrivate(XrdpUlalaca *mod); XrdpUlalacaPrivate(XrdpUlalacaPrivate &) = delete; ~XrdpUlalacaPrivate(); |