e341b3525a107c87bca8b8e3e120fe104845b2c5
[platform/core/uifw/lottie-player.git] / src / vector / vregion.h
1 #ifndef VREGION_H
2 #define VREGION_H
3 #include <vglobal.h>
4 #include <vpoint.h>
5 #include <vrect.h>
6 #include <utility>
7 #include "vdebug.h"
8
9 V_BEGIN_NAMESPACE
10
11 struct VRegionData;
12
13 class VRegion {
14 public:
15     VRegion();
16     VRegion(int x, int y, int w, int h);
17     VRegion(const VRect &r);
18     VRegion(const VRegion &region);
19     VRegion(VRegion &&other);
20     ~VRegion();
21     VRegion &      operator=(const VRegion &);
22     VRegion &      operator=(VRegion &&);
23     bool           empty() const;
24     bool           contains(const VRect &r) const;
25     VRegion        united(const VRect &r) const;
26     VRegion        united(const VRegion &r) const;
27     VRegion        intersected(const VRect &r) const;
28     VRegion        intersected(const VRegion &r) const;
29     VRegion        subtracted(const VRegion &r) const;
30     void           translate(const VPoint &p);
31     inline void    translate(int dx, int dy);
32     VRegion        translated(const VPoint &p) const;
33     inline VRegion translated(int dx, int dy) const;
34     int            rectCount() const;
35     VRect          rectAt(int index) const;
36
37     VRegion  operator+(const VRect &r) const;
38     VRegion  operator+(const VRegion &r) const;
39     VRegion  operator-(const VRegion &r) const;
40     VRegion &operator+=(const VRect &r);
41     VRegion &operator+=(const VRegion &r);
42     VRegion &operator-=(const VRegion &r);
43
44     VRect boundingRect() const noexcept;
45     bool  intersects(const VRegion &region) const;
46
47     bool        operator==(const VRegion &r) const;
48     inline bool operator!=(const VRegion &r) const { return !(operator==(r)); }
49     friend VDebug &operator<<(VDebug &os, const VRegion &o);
50
51 private:
52     bool    within(const VRect &r) const;
53     VRegion copy() const;
54     void    detach();
55     void    cleanUp(VRegionData *x);
56
57     struct VRegionData *d;
58 };
59 inline void VRegion::translate(int dx, int dy)
60 {
61     translate(VPoint(dx, dy));
62 }
63
64 inline VRegion VRegion::translated(int dx, int dy) const
65 {
66     return translated(VPoint(dx, dy));
67 }
68
69 V_END_NAMESPACE
70
71 #endif  // VREGION_H