ACF $AcfVersion:0$
CRectangle.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
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
15namespace i2d
16{
17
18
19class CRect;
20class CLine2d;
21
22
27{
28public:
29 static QByteArray GetTypeName();
30
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;
104
108 const istd::CRange& GetVerticalRange() const;
117 void SetVerticalRange(const istd::CRange& range);
118
126 void SetTopLeft(const CVector2d& topLeft);
134 void SetTopRight(const CVector2d& topRight);
142 void SetBottomLeft(const CVector2d& bottomLeft);
150 void SetBottomRight(const CVector2d& bottomRight);
151
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
196
200 bool IsIntersectedBy(const CRectangle& rect) const;
201
206 bool IsIntersectedBy(const CLine2d& line) const;
207
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
254 void Expand(const CRectangle& rect);
255
259 double GetDistance(const CVector2d& position) const;
260
264 double GetMaxDistance(const CVector2d& position) const;
265
270
271 void Translate(const i2d::CVector2d& delta);
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 override;
281 virtual void MoveCenterTo(const CVector2d& position) override;
282 virtual CRectangle GetBoundingBox() const override;
283 virtual bool Transform(
284 const ITransformation2d& transformation,
286 double* errorFactorPtr = NULL) override;
287 virtual bool InvTransform(
288 const ITransformation2d& transformation,
290 double* errorFactorPtr = NULL) override;
291 virtual bool GetTransformed(
292 const ITransformation2d& transformation,
293 IObject2d& result,
295 double* errorFactorPtr = NULL) const override;
296 virtual bool GetInvTransformed(
297 const ITransformation2d& transformation,
298 IObject2d& result,
300 double* errorFactorPtr = NULL) const override;
301
302 // reimplemented (iser::IObject)
303 virtual QByteArray GetFactoryId() const override;
304
305 // reimplemented (iser::ISerializable)
306 virtual bool Serialize(iser::IArchive& archive) override;
307
308 // reimplemented (istd::IChangeable)
309 virtual int GetSupportedOperations() const override;
310 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
312
313 // static methods
317 static const i2d::CRectangle& GetEmpty();
321 static const i2d::CRectangle& GetInvalid();
322
323private:
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
335inline double CRectangle::GetLeft() const
336{
337 return m_horizontalRange.GetMinValue();
338}
339
340
341inline double CRectangle::GetTop() const
342{
343 return m_verticalRange.GetMinValue();
344}
345
346
347inline double CRectangle::GetRight() const
348{
349 return m_horizontalRange.GetMaxValue();
350}
351
352
353inline 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
401
Definition of a line in 2D-space.
Definition CLine2d.h:25
Base class for 2D-objects implementing interface i2d::IObject2d.
Simple rectangle with integer bounds.
Definition CRect.h:22
Definition of rectangle area orthogonal to axis of coordination system.
Definition CRectangle.h:27
double GetTop() const
Get value of top boundary.
Definition CRectangle.h:341
double GetHeight() const
Get height of this rectangle.
void SetBottom(double bottom)
Set value of bottom boundary.
void SetBottomLeft(const CVector2d &bottomLeft)
Set left-bottom point of this rectangle.
CVector2d GetTopCenter() const
Get point in center of top edge.
CRectangle GetTranslated(const i2d::CVector2d &delta) const
virtual bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
void Reset()
Make rectangle empty.
double GetDistance(const CVector2d &position) const
Get distance from nearest point of this rectangle to specified position.
void Intersect(const CRectangle &rectangle)
Set new rectangle as intersection of the current rectangle with a given one.
CVector2d GetLeftBottom() const
Get left-bottom point of this rectangle.
const istd::CRange & GetHorizontalRange() const
Get values of horizontal boundaries.
Definition CRectangle.h:359
CVector2d GetBottomCenter() const
Get point in center of bottom edge.
virtual QByteArray GetFactoryId() const override
double GetLeft() const
Get value of left boundary.
Definition CRectangle.h:335
void Translate(const i2d::CVector2d &delta)
void SetTop(double top)
Set value of top boundary.
bool IsIntersectedBy(const CLine2d &line) const
Returns true, if this rectangle is intersected by the line rect.
CVector2d GetRightTop() const
Get right-top point of this rectangle.
void SetBottomRight(const CVector2d &bottomRight)
Set right-bottom point of this rectangle.
bool IsEmpty() const
Return true if the rectangle is empty.
void Expand(const CRectangle &rect)
Expand rectangle.
CVector2d GetRightBottom() const
Get right-bottom point of this rectangle.
void Unite(const i2d::CVector2d &position)
Set this rectangle to union of rectangle and point.
CLine2d GetIntersection(const CLine2d &line) const
Get resulting line of the intersection of this rectangle with the line line.
bool operator==(const CRectangle &rect) const
virtual int GetSupportedOperations() const override
Get set of flags for supported operations.
double GetBottom() const
Get value of bottom boundary.
Definition CRectangle.h:353
void SetRight(double right)
Set value of right boundary.
void SetTopLeft(const CVector2d &topLeft)
Set left-top point of this rectangle.
CRectangle(const istd::CRange &horizontalRange, const istd::CRange &verticalRange)
CVector2d GetLeftTop() const
Get left-top point of this rectangle.
virtual CRectangle GetBoundingBox() const override
Get bounding box of this shape.
CVector2d GetRightCenter() const
Get point in center of right edge.
bool Contains(const CVector2d &point) const
Check if some point is contained in this rectangle.
CRectangle(double left, double top, double width, double height)
static QByteArray GetTypeName()
CRectangle GetUnion(const CRectangle &rect) const
Get union of two rectangles.
istd::CRange & GetVerticalRangeRef()
Get values of vertical boundaries as reference.
Definition CRectangle.h:377
bool operator!=(const CRectangle &rect) const
virtual bool GetTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const override
Calulate transformation of the object into second one.
CRectangle GetIntersection(const CRectangle &rect) const
Get resulting rectangle of the intersection of this rectangle with rect.
void SetVerticalRange(const istd::CRange &range)
Set values of vertical boundaries.
virtual CVector2d GetCenter() const override
Returns center of this 2D-object.
CVector2d GetNearestPointTo(const CVector2d &point) const
Get the nearest point in the rectangle for the some given point.
virtual bool InvTransform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) override
Do inverse transformation of this object.
CRectangle GetUnion(const i2d::CVector2d &position) const
Get union of this rectangle and point.
istd::CRange & GetHorizontalRangeRef()
Get values of horizontal boundaries as reference.
Definition CRectangle.h:365
static const i2d::CRectangle & GetInvalid()
Get invalid rectangle.
Definition CRectangle.h:391
double GetMaxDistance(const CVector2d &position) const
Get maximal distance from points of this rectangle to specified position.
void SetHorizontalRange(const istd::CRange &range)
Set values of horizontal boundaries.
static const i2d::CRectangle & GetEmpty()
Get empty rectangle with all values set to 0.
Definition CRectangle.h:385
virtual bool Transform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) override
Transform this object using some transformation.
bool IsValidNonEmpty() const
Return true if the rectangle is valid and it is not empty.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
const istd::CRange & GetVerticalRange() const
Get values of vertical boundaries.
Definition CRectangle.h:371
CRectangle(const istd::CIndex2d &size)
bool Contains(const CRectangle &rect) const
Check if some rectangle is fully contained in this rectangle.
double GetRight() const
Get value of right boundary.
Definition CRectangle.h:347
void Unite(const CRectangle &rect)
Set this rectangle to union of two rectangles.
CRectangle(const i2d::CRect &rect)
CVector2d GetSize() const
Get size of this rectangle.
void SetLeft(double left)
Set value of left boundary.
bool IsIntersectedBy(const CRectangle &rect) const
Returns true, if this rectangle is intersected by the other rectangle rect.
virtual void MoveCenterTo(const CVector2d &position) override
Move object to position position.
CRectangle(const CVector2d &topLeft, const CVector2d &bottomRight)
double GetWidth() const
Get width of this rectangle.
void SetTopRight(const CVector2d &topRight)
Set right-top point of this rectangle.
CRectangle GetExpanded(const CRectangle &rect) const
Get expanded rectangle (simple sum of boundary values).
virtual istd::TUniqueInterfacePtr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
bool IsValid() const
Return true if the rectangle is valid.
virtual bool GetInvTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=NULL) const override
Calulate inverse transformation of the object into second one.
CVector2d GetLeftCenter() const
Get point in center of left edge.
bool Contains(const istd::CIndex2d &point) const
Check if some point is contained in this rectangle.
Definition of position or mathematical vector on 2D plane.
Definition CVector2d.h:29
Common interface for describing the 2D-objects.
Definition IObject2d.h:26
Common interface for all calibration objects.
@ EM_NONE
There are no preferences, should be automatically selected.
Represents an input/output persistence archive for object serialization.
Definition IArchive.h:164
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
ValueType GetMaxValue() const
Get the top value.
Definition TRange.h:382
ValueType GetMinValue() const
Get the bottom value.
Definition TRange.h:341
Unique ownership smart pointer for interface types.
#define NULL
Definition istd.h:74
Contains the 2D objects.
Definition CAffine2d.h:11