CRectangle.h
Go to the documentation of this file.
1 #ifndef i2d_CRectangle_included
2 #define i2d_CRectangle_included
3 
4 
5 // Qt includes
6 #include <QtCore/QRectF>
7 
8 // ACF includes
9 #include <istd/TRange.h>
10 #include <istd/CIndex2d.h>
11 #include <iser/ISerializable.h>
12 #include <i2d/CObject2dBase.h>
13 
14 
15 namespace i2d
16 {
17 
18 
19 class CRect;
20 class CLine2d;
21 
22 
27 {
28 public:
29  static QByteArray GetTypeName();
30 
31  CRectangle();
32  CRectangle(double left, double top, double width, double height);
33  CRectangle(const CVector2d& topLeft, const CVector2d& bottomRight);
34  CRectangle(const istd::CRange& horizontalRange, const istd::CRange& verticalRange);
35  CRectangle(const i2d::CRect& rect);
36  explicit CRectangle(const istd::CIndex2d& size);
37 
41  bool IsValid() const;
42 
46  bool IsEmpty() const;
47 
51  bool IsValidNonEmpty() const;
52 
56  void Reset();
57 
61  double GetLeft() const;
65  void SetLeft(double left);
69  double GetTop() const;
73  void SetTop(double top);
77  double GetRight() const;
81  void SetRight(double right);
85  double GetBottom() const;
89  void SetBottom(double bottom);
90 
94  const istd::CRange& GetHorizontalRange() const;
103  void SetHorizontalRange(const istd::CRange& range);
104 
108  const istd::CRange& GetVerticalRange() const;
117  void SetVerticalRange(const istd::CRange& range);
118 
122  CVector2d GetLeftTop() const;
126  void SetTopLeft(const CVector2d& topLeft);
130  CVector2d GetRightTop() const;
134  void SetTopRight(const CVector2d& topRight);
138  CVector2d GetLeftBottom() const;
142  void SetBottomLeft(const CVector2d& bottomLeft);
146  CVector2d GetRightBottom() const;
150  void SetBottomRight(const CVector2d& bottomRight);
151 
155  CVector2d GetLeftCenter() const;
159  CVector2d GetRightCenter() const;
163  CVector2d GetTopCenter() const;
167  CVector2d GetBottomCenter() const;
168 
172  bool Contains(const CVector2d& point) const;
176  bool Contains(const istd::CIndex2d& point) const;
181  bool Contains(const CRectangle& rect) const;
182 
186  double GetWidth() const;
190  double GetHeight() const;
191 
195  CVector2d GetSize() const;
196 
200  bool IsIntersectedBy(const CRectangle& rect) const;
201 
206  bool IsIntersectedBy(const CLine2d& line) const;
207 
211  CRectangle GetIntersection(const CRectangle& rect) const;
212 
216  CLine2d GetIntersection(const CLine2d& line) const;
217 
221  void Intersect(const CRectangle& rectangle);
222 
228  CRectangle GetUnion(const CRectangle& rect) const;
233  void Unite(const CRectangle& rect);
234 
239  CRectangle GetUnion(const i2d::CVector2d& position) const;
244  void Unite(const i2d::CVector2d& position);
245 
249  CRectangle GetExpanded(const CRectangle& rect) const;
254  void Expand(const CRectangle& rect);
255 
259  double GetDistance(const CVector2d& position) const;
260 
264  double GetMaxDistance(const CVector2d& position) const;
265 
269  CVector2d GetNearestPointTo(const CVector2d& point) const;
270 
271  void Translate(const i2d::CVector2d& delta);
272  CRectangle GetTranslated(const i2d::CVector2d& delta) const;
273 
274  bool operator==(const CRectangle& rect) const;
275  bool operator!=(const CRectangle& rect) const;
276 
277  operator QRectF() const;
278 
279  // reimplemented (i2d::IObject2d)
280  virtual CVector2d GetCenter() const;
281  virtual void MoveCenterTo(const CVector2d& position);
282  virtual CRectangle GetBoundingBox() const;
283  virtual bool Transform(
284  const ITransformation2d& transformation,
286  double* errorFactorPtr = NULL);
287  virtual bool InvTransform(
288  const ITransformation2d& transformation,
290  double* errorFactorPtr = NULL);
291  virtual bool GetTransformed(
292  const ITransformation2d& transformation,
293  IObject2d& result,
295  double* errorFactorPtr = NULL) const;
296  virtual bool GetInvTransformed(
297  const ITransformation2d& transformation,
298  IObject2d& result,
300  double* errorFactorPtr = NULL) const;
301 
302  // reimplemented (iser::IObject)
303  virtual QByteArray GetFactoryId() const;
304 
305  // reimplemented (iser::ISerializable)
306  virtual bool Serialize(iser::IArchive& archive);
307 
308  // reimplemented (istd::IChangeable)
309  virtual int GetSupportedOperations() const;
310  virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
312 
313  // static methods
317  static const i2d::CRectangle& GetEmpty();
321  static const i2d::CRectangle& GetInvalid();
322 
323 private:
324  istd::CRange m_horizontalRange;
325  istd::CRange m_verticalRange;
326 
327  // static atributes
328  static CRectangle s_empty;
329  static CRectangle s_invalid;
330 };
331 
332 
333 // inline methods
334 
335 inline double CRectangle::GetLeft() const
336 {
337  return m_horizontalRange.GetMinValue();
338 }
339 
340 
341 inline double CRectangle::GetTop() const
342 {
343  return m_verticalRange.GetMinValue();
344 }
345 
346 
347 inline double CRectangle::GetRight() const
348 {
349  return m_horizontalRange.GetMaxValue();
350 }
351 
352 
353 inline double CRectangle::GetBottom() const
354 {
355  return m_verticalRange.GetMaxValue();
356 }
357 
358 
360 {
361  return m_horizontalRange;
362 }
363 
364 
366 {
367  return m_horizontalRange;
368 }
369 
370 
372 {
373  return m_verticalRange;
374 }
375 
376 
378 {
379  return m_verticalRange;
380 }
381 
382 
383 // static methods
384 
386 {
387  return s_empty;
388 }
389 
390 
392 {
393  return s_invalid;
394 }
395 
396 
397 } // namespace i2d
398 
399 
400 #endif // !i2d_CRectangle_included
401 
402 
CVector2d GetBottomCenter() const
Get point in center of bottom edge.
virtual CVector2d GetCenter() const
Returns center of this 2D-object.
void SetBottom(double bottom)
Set value of bottom boundary.
External references are simple ignored.
Definition: IChangeable.h:197
CompatibilityMode
Control how relationship betweeen objects are interpreted.
Definition: IChangeable.h:186
void SetTopLeft(const CVector2d &topLeft)
Set left-top point of this rectangle.
virtual bool Transform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL)
Transform this object using some transformation.
double GetWidth() const
Get width of this rectangle.
void SetBottomRight(const CVector2d &bottomRight)
Set right-bottom point of this rectangle.
void SetTopRight(const CVector2d &topRight)
Set right-top point of this rectangle.
bool operator!=(const CRectangle &rect) const
CRectangle GetExpanded(const CRectangle &rect) const
Get expanded rectangle (simple sum of boundary values).
static const i2d::CRectangle & GetEmpty()
Get empty rectangle with all values set to 0.
Definition: CRectangle.h:385
void Unite(const CRectangle &rect)
Set this rectangle to union of two rectangles.
Definition of a line in 2D-space.
Definition: CLine2d.h:24
Common interface for all calibration objects.
Simple rectangle with integer bounds.
Definition: CRect.h:21
Index implementation for addressing elements in 2D-space.
Definition: CIndex2d.h:20
void SetHorizontalRange(const istd::CRange &range)
Set values of horizontal boundaries.
ValueType GetMaxValue() const
Get the top value.
Definition: TRange.h:352
virtual CRectangle GetBoundingBox() const
Get bounding box of this shape.
CRectangle GetTranslated(const i2d::CVector2d &delta) const
virtual void MoveCenterTo(const CVector2d &position)
Move object to position position.
virtual bool Serialize(iser::IArchive &archive)
Load or store state of this object as a archive stream.
void SetTop(double top)
Set value of top boundary.
double GetBottom() const
Get value of bottom boundary.
Definition: CRectangle.h:353
void Intersect(const CRectangle &rectangle)
Set new rectangle as intersection of the current rectangle with a given one.
CVector2d GetTopCenter() const
Get point in center of top edge.
CVector2d GetRightBottom() const
Get right-bottom point of this rectangle.
There are no preferences, should be automatically selected.
double GetHeight() const
Get height of this rectangle.
Represent input/output persistence archive.
Definition: IArchive.h:30
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
Definition of rectangle area orthogonal to axis of coordination system.
Definition: CRectangle.h:26
CVector2d GetNearestPointTo(const CVector2d &point) const
Get the nearest point in the rectangle for the some given point.
void SetBottomLeft(const CVector2d &bottomLeft)
Set left-bottom point of this rectangle.
CVector2d GetSize() const
Get size of this rectangle.
virtual QByteArray GetFactoryId() const
static const i2d::CRectangle & GetInvalid()
Get invalid rectangle.
Definition: CRectangle.h:391
CVector2d GetLeftBottom() const
Get left-bottom point of this rectangle.
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
bool Contains(const CVector2d &point) const
Check if some point is contained in this rectangle.
double GetTop() const
Get value of top boundary.
Definition: CRectangle.h:341
Base class for 2D-objects implementing interface i2d::IObject2d.
Definition: CObject2dBase.h:18
bool IsValid() const
Return true if the rectangle is valid.
double GetRight() const
Get value of right boundary.
Definition: CRectangle.h:347
virtual bool InvTransform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL)
Do inverse transformation of this object.
#define NULL
Definition: istd.h:64
const istd::CRange & GetHorizontalRange() const
Get values of horizontal boundaries.
Definition: CRectangle.h:359
virtual bool GetTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const
Calulate transformation of the object into second one.
CVector2d GetRightCenter() const
Get point in center of right edge.
virtual bool GetInvTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const
Calulate inverse transformation of the object into second one.
void Translate(const i2d::CVector2d &delta)
bool IsValidNonEmpty() const
Return true if the rectangle is valid and it is not empty.
CRectangle GetIntersection(const CRectangle &rect) const
Get resulting rectangle of the intersection of this rectangle with rect.
CVector2d GetLeftCenter() const
Get point in center of left edge.
void Reset()
Make rectangle empty.
istd::CRange & GetHorizontalRangeRef()
Get values of horizontal boundaries as reference.
Definition: CRectangle.h:365
double GetMaxDistance(const CVector2d &position) const
Get maximal distance from points of this rectangle to specified position.
Common interface for describing the 2D-objects.
Definition: IObject2d.h:22
const istd::CRange & GetVerticalRange() const
Get values of vertical boundaries.
Definition: CRectangle.h:371
CVector2d GetLeftTop() const
Get left-top point of this rectangle.
void SetLeft(double left)
Set value of left boundary.
bool operator==(const CRectangle &rect) const
virtual int GetSupportedOperations() const
Get set of flags for supported operations.
double GetDistance(const CVector2d &position) const
Get distance from nearest point of this rectangle to specified position.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
void SetRight(double right)
Set value of right boundary.
void Expand(const CRectangle &rect)
Expand rectangle.
bool IsIntersectedBy(const CRectangle &rect) const
Returns true, if this rectangle is intersected by the other rectangle rect.
double GetLeft() const
Get value of left boundary.
Definition: CRectangle.h:335
CRectangle GetUnion(const CRectangle &rect) const
Get union of two rectangles.
void SetVerticalRange(const istd::CRange &range)
Set values of vertical boundaries.
ValueType GetMinValue() const
Get the bottom value.
Definition: TRange.h:331
virtual istd::IChangeable * CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const
Make a copy of this object.
bool IsEmpty() const
Return true if the rectangle is empty.
CVector2d GetRightTop() const
Get right-top point of this rectangle.
static QByteArray GetTypeName()
istd::CRange & GetVerticalRangeRef()
Get values of vertical boundaries as reference.
Definition: CRectangle.h:377

© 2007-2017 Witold Gantzke and Kirill Lepskiy