Mobile API Reference  MicroStrategy 2019
Rect2D.h
Go to the documentation of this file.
1 //==============================================================================================
2 // FILENAME : Rect2D.h
3 // AUTHOR : Liang Liu
4 // CREATION : 2008-09-25
5 // Copyright (C) MicroStrategy Incorporated 2008
6 // All Rights Reserved
7 //==============================================================================================
8 
9 #ifndef MsiChart_Rect2D_h
10 #define MsiChart_Rect2D_h
11 
12 #include "Point2D.h"
13 
14 namespace MsiChart
15 {
16  typedef enum
17  {
23 
25  class Rect2D
26  {
27  public:
35  Rect2D(int iX, int iY,
36  Int32 iWidth, Int32 iHeight) : x(iX),y(iY),width(iWidth),height(iHeight){}
37 
39  Rect2D(): x(0), y(0), width(0), height(0){}
40 
46  void Explode(Int32 iXOffset, Int32 iYOffset);
47 
51  void Expand(Int32 iOffset, REC_EXP_DIRECTION iExpDirection);
52 
58  void Implode(Int32 iXOffset, Int32 iYOffset);
59 
64  Point2D GetTopLeft() const;
69  Point2D GetBottomLeft() const;
74  Point2D GetTopRight() const;
79  Point2D GetBottomRight() const;
84  Point2D GetCenter() const;
89  Point2D GetLeftMiddle() const;
94  Point2D GetTopMiddle() const;
99  Point2D GetRightMiddle() const;
104  Point2D GetBottomMiddle() const;
110  bool HasIntersection(const Rect2D& irRect) const;
116  bool PointInRectangle(const Point2D& irPoint) const;
117 
118  void Reset(int iX, int iY, Int32 iWidth, Int32 iHeight);
119 
120  bool IsEqualTo(Rect2D& irRect) const;
121  public:
122  int x;
123  int y;
126  };
127 
128  inline void Rect2D::Explode(Int32 iXOffset, Int32 iYOffset)
129  {
130  x -= iXOffset;
131  y -= iYOffset;
132  width += (iXOffset*2);
133  height += (iYOffset*2);
134  }
135 
136  inline void Rect2D::Expand(Int32 iOffset, REC_EXP_DIRECTION iExpDirection)
137  {
138 // if (iOffset <= 0)
139 // return;
140 
141  if (iExpDirection & REC_EXP_HRIZONTAL)
142  {
143  x -= iOffset;
144  width += 2 * iOffset;
145  }
146 
147  if (iExpDirection & REC_EXP_VERTICAL)
148  {
149  y -= iOffset;
150  height += 2 * iOffset;
151  }
152  }
153 
154  inline void Rect2D::Implode(Int32 iXOffset, Int32 iYOffset)
155  {
156  if (iXOffset * 2 > width)
157  {
158  iXOffset = width / 2;
159  }
160  if (iYOffset * 2 > height)
161  {
162  iYOffset = height / 2;
163  }
164  Rect2D::Explode(-iXOffset, -iYOffset);
165  }
166 
168  {
169  return Point2D(x, y);
170  }
172  {
173  return Point2D(x, y + height);
174  }
176  {
177  return Point2D(x + width, y);
178  }
180  {
181  return Point2D(x + width, y + height);
182  }
183  inline Point2D Rect2D::GetCenter() const
184  {
185  return Point2D(x + width / 2, y + height / 2);
186  }
187 
189  {
190  return Point2D(x, y + height / 2);
191  }
192 
194  {
195  return Point2D(x + width / 2, y);
196  }
197 
199  {
200  return Point2D(x + width, y + height / 2);
201  }
202 
204  {
205  return Point2D(x + width / 2, y + height);
206  }
207  inline bool Rect2D::HasIntersection(const Rect2D& irRect) const
208  {
209  return x < (irRect.x + irRect.width) && irRect.x < (x + width) &&
210  y < (irRect.y + irRect.height) && irRect.y < (y + height);
211  }
212 
213  inline bool Rect2D::PointInRectangle(const Point2D& irPoint) const
214  {
215  return ((irPoint.x >= x) && (irPoint.x <= x + width)
216  && (irPoint.y >= y) && (irPoint.y <= y + height));
217  }
218 
219  inline void Rect2D::Reset(int iX, int iY, Int32 iWidth, Int32 iHeight)
220  {
221  x = iX;
222  y = iY;
223  width = iWidth;
224  height = iHeight;
225  }
226 
227  inline bool Rect2D::IsEqualTo(Rect2D& irRect) const
228  {
229  if (x != irRect.x || y != irRect.y)
230  return false;
231  if (width != irRect.width || height != irRect.height)
232  return false;
233  return true;
234  }
235 
236 }
237 #endif
Point2D GetRightMiddle() const
Definition: Rect2D.h:198
Point< Int32 > Point2D
Definition: Point2D.h:402
Point2D GetTopRight() const
Definition: Rect2D.h:175
Definition: Rect2D.h:20
bool PointInRectangle(const Point2D &irPoint) const
Definition: Rect2D.h:213
Rect2D()
Constructs without parameters. All data members will be initialized as 0.
Definition: Rect2D.h:39
Point2D GetTopMiddle() const
Definition: Rect2D.h:193
T y
Y-coordinate of current point.
Definition: Point2D.h:175
Int32 width
Width of current rectangle.
Definition: Rect2D.h:124
Definition: Rect2D.h:19
#define Int32
Definition: BasicTypes.h:20
T x
X-coordinate of current point.
Definition: Point2D.h:174
Definition: Rect2D.h:18
Point2D GetTopLeft() const
Definition: Rect2D.h:167
void Implode(Int32 iXOffset, Int32 iYOffset)
Definition: Rect2D.h:154
int x
X-coordinate of left edge.
Definition: Rect2D.h:122
REC_EXP_DIRECTION
Definition: Rect2D.h:16
void Explode(Int32 iXOffset, Int32 iYOffset)
Definition: Rect2D.h:128
void Reset(int iX, int iY, Int32 iWidth, Int32 iHeight)
Definition: Rect2D.h:219
bool IsEqualTo(Rect2D &irRect) const
Definition: Rect2D.h:227
Definition: ABLPlot.h:21
Int32 height
Height of current rectangle.
Definition: Rect2D.h:125
Rect2D(int iX, int iY, Int32 iWidth, Int32 iHeight)
Definition: Rect2D.h:35
Point2D GetBottomRight() const
Definition: Rect2D.h:179
Definition: Rect2D.h:21
Point2D GetBottomLeft() const
Definition: Rect2D.h:171
Point2D GetLeftMiddle() const
Definition: Rect2D.h:188
Point2D GetBottomMiddle() const
Definition: Rect2D.h:203
bool HasIntersection(const Rect2D &irRect) const
Definition: Rect2D.h:207
int y
Y-coordinate of left edge.
Definition: Rect2D.h:123
Point2D GetCenter() const
Definition: Rect2D.h:183
void Expand(Int32 iOffset, REC_EXP_DIRECTION iExpDirection)
Definition: Rect2D.h:136
Use four Int32 values to represent a 2D rectangle.
Definition: Rect2D.h:25