1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef FRAMEWORKS_WMSERVER_SRC_RECTS_H 17 #define FRAMEWORKS_WMSERVER_SRC_RECTS_H 18 19 #include <vector> 20 21 class Rects { 22 public: 23 Rects() = default; 24 Rects(int32_t x, int32_t y, int32_t w, int32_t h); 25 virtual ~Rects() = default; 26 27 int32_t GetSize() const; 28 int32_t GetX(int32_t index) const; 29 int32_t GetY(int32_t index) const; 30 int32_t GetW(int32_t index) const; 31 int32_t GetH(int32_t index) const; 32 33 Rects operator -(Rects &other); 34 Rects &operator -=(Rects &other); 35 36 private: 37 struct Rect { 38 int32_t x; 39 int32_t y; 40 int32_t w; 41 int32_t h; 42 }; 43 static void Intersect(const struct Rect &a, const struct Rect &b, struct Rect &out); 44 static void Subtrace(const struct Rect &rect, const struct Rect &inner, std::vector<struct Rect> &result); 45 static void RectsSubtrace(std::vector<struct Rect> &lrects, std::vector<struct Rect> rrects); 46 47 std::vector<struct Rect> rects; 48 }; 49 50 #endif // FRAMEWORKS_WMSERVER_SRC_RECTS_H 51