Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cRegion.h
Go to the documentation of this file.
1 //
5 //
6 
7 #ifndef _INC_cRegion_H
8 #define _INC_cRegion_H
9 #ifndef NO_PRAGMA_ONCE
10 #pragma once
11 #endif
12 
13 #include "cRectI.h"
15 
16 #ifdef GRAY_DLL // force implementation/instantiate for DLL/SO.
17 namespace Gray
18 {
19  template class GRAYLIB_LINK CArray<GrayLib::cRectI, const GrayLib::cRectI&>;
20  template class GRAYLIB_LINK cArrayTyped<GrayLib::cRectI, const GrayLib::cRectI&>;
21 }
22 #endif
23 
24 namespace GrayLib
25 {
27 
28  class GRAYLIB_LINK cRegion : public CObject // similar to MFC CRgn
29  {
33  typedef int DVALUE_t;
34 
35  protected:
37  private:
38  cArrayStruct<cRectI> m_Rects;
39 
40  private:
41  void UpdateRegionUnion();
42 
43  public:
44  cRegion(const cRectI& rect);
45  cRegion();
46  virtual ~cRegion();
47 
48  virtual bool isValidCheck() const noexcept // override // memory allocation and structure definitions are valid.
49  {
50  if (!COBJECT_IsValidCheck())
51  return false;
52  if (!IS_TYPE_OF(cRegion, this)) // structure definitions are valid.
53  return false;
54  return true;
55  }
56 
57  bool isRegionEmpty() const
58  {
59  return(m_rectUnion.IsRectEmpty());
60  }
61  void EmptyRegion()
62  {
63  m_rectUnion.SetRectEmptyX();
64  m_Rects.RemoveAll();
65  }
66  void AddRegion(const cRegion* pRegionTest);
67  bool SubtractRegion(const cRegion* pRegionTest);
68  void SetRegionSubtract(const cRectI& rect1, const cRectI& rect2);
69 
70  const cRectI& get_RectUnion() const
71  {
72  return m_rectUnion;
73  }
74  void put_RectUnion(const cRectI& rect)
75  {
76  m_Rects.RemoveAll();
77  m_rectUnion = rect;
78  }
79 
80  ITERATE_t get_RegionRectCount() const;
81  const cRectI& GetRegionRect(ITERATE_t i) const;
82  cRectI& RefRegionRect(ITERATE_t i);
83  virtual bool AddRegionRect(const cRectI& rect);
84  virtual void RemoveRegionRect(ITERATE_t i);
85  bool SubtractRegionRect(const cRectI& rect);
86 
87  void OptimizeRegionRects();
88 
89  cPoint2i GetRegionCorner(DIR_TYPE eDir = DIR_QTY) const;
90  bool PtInRegion(int x, int y) const; // MFC like
91  bool PtInRegion(const cPoint2i& pt) const // MFC like
92  {
93  return PtInRegion(pt.x, pt.y);
94  }
95 
96  // RectInRegion = really just checks overlap!
97  bool IsOverlapped(const cRectI& rect) const;
98  bool IsInsideMe(const cRectI& rect) const;
99 
100  bool IsInsideMe(const cRegion* pRegionIsSmaller) const;
101  bool IsOverlapped(const cRegion* pRegionTest) const;
102  bool IsEqualRegion(const cRegion* pRegionTest) const;
103 
104  HRESULT v_SetRegion(const cVariant& vVal);
105  void v_GetRegion(cVariant& vVal) const;
106 
108  };
109 }
110 
111 #endif // _INC_cRegion_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_TYPE_OF(t, p)
Definition: PtrCast.h:23
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
#define COBJECT_IsValidCheck()
Definition: cObject.h:64
#define UNITTEST2_PREDEF(x)
Definition: cUnitTestDecl.h:19
Definition: cPoint2.h:20
Definition: cRectI.h:22
bool IsRectEmpty() const noexcept
Definition: cRectT.h:428
void SetRectEmptyX() noexcept
Definition: cRectT.h:140
Definition: cRegion.h:29
UNITTEST_FRIEND(cRegion)
void EmptyRegion()
Definition: cRegion.h:61
virtual bool isValidCheck() const noexcept
< memory allocation and structure definitions are valid.
Definition: cRegion.h:48
bool PtInRegion(const cPoint2i &pt) const
Definition: cRegion.h:91
void put_RectUnion(const cRectI &rect)
Definition: cRegion.h:74
const cRectI & get_RectUnion() const
Definition: cRegion.h:70
cRectI m_rectUnion
The union rectangle. (may have holes in it of course)
Definition: cRegion.h:36
bool isRegionEmpty() const
Definition: cRegion.h:57
Definition: cVariant.h:26
void RemoveAll()
Clean up.
Definition: cArray.h:230
Definition: cObject.h:67
Definition: cArray.h:932
Definition: cMesh.h:22
DIR_TYPE
Definition: cDirectionDef.h:25
@ DIR_QTY
Also means "Center".
Definition: cDirectionDef.h:38
interface const RECTQ_t & rect
Definition: cQuadtree.h:44
< The main namespace for all Core functions.
Definition: GrayCore.cpp:14
int ITERATE_t
like size_t but signed
Definition: Index.h:28