ICF 3.1.1.10
Technical documentation of ICF Libraries
CRectangle.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QRectF>
11
12// ICF includes
13#include <istd/TRange.h>
14#include <istd/CIndex2d.h>
15#include <iser/ISerializable.h>
16#include <i2d/CObject2dBase.h>
17
18
19namespace i2d
20{
21
22
23class CRect;
24class CLine2d;
25
26
31{
32public:
33 static QByteArray GetTypeName();
34
36 CRectangle(double left, double top, double width, double height);
37 CRectangle(const CVector2d& topLeft, const CVector2d& bottomRight);
38 CRectangle(const istd::CRange& horizontalRange, const istd::CRange& verticalRange);
39 CRectangle(const i2d::CRect& rect);
40 explicit CRectangle(const istd::CIndex2d& size);
41
45 bool IsValid() const;
46
50 bool IsEmpty() const;
51
55 bool IsValidNonEmpty() const;
56
60 void Reset();
61
65 double GetLeft() const;
69 void SetLeft(double left);
73 double GetTop() const;
77 void SetTop(double top);
81 double GetRight() const;
85 void SetRight(double right);
89 double GetBottom() const;
93 void SetBottom(double bottom);
94
98 const istd::CRange& GetHorizontalRange() const;
108
112 const istd::CRange& GetVerticalRange() const;
121 void SetVerticalRange(const istd::CRange& range);
122
130 void SetTopLeft(const CVector2d& topLeft);
138 void SetTopRight(const CVector2d& topRight);
146 void SetBottomLeft(const CVector2d& bottomLeft);
154 void SetBottomRight(const CVector2d& bottomRight);
155
172
176 bool Contains(const CVector2d& point) const;
180 bool Contains(const istd::CIndex2d& point) const;
185 bool Contains(const CRectangle& rect) const;
186
190 double GetWidth() const;
194 double GetHeight() const;
195
200
204 bool IsIntersectedBy(const CRectangle& rect) const;
205
210 bool IsIntersectedBy(const CLine2d& line) const;
211
216
220 CLine2d GetIntersection(const CLine2d& line) const;
221
225 void Intersect(const CRectangle& rectangle);
226
232 CRectangle GetUnion(const CRectangle& rect) const;
237 void Unite(const CRectangle& rect);
238
243 CRectangle GetUnion(const i2d::CVector2d& position) const;
248 void Unite(const i2d::CVector2d& position);
249
258 void Expand(const CRectangle& rect);
259
263 double GetDistance(const CVector2d& position) const;
264
268 double GetMaxDistance(const CVector2d& position) const;
269
274
275 void Translate(const i2d::CVector2d& delta);
277
278 bool operator==(const CRectangle& rect) const;
279 bool operator!=(const CRectangle& rect) const;
280
281 operator QRectF() const;
282
283 // reimplemented (i2d::IObject2d)
284 CVector2d GetCenter() const override;
285 void MoveCenterTo(const CVector2d& position) override;
286 CRectangle GetBoundingBox() const override;
288 const ITransformation2d& transformation,
290 double* errorFactorPtr = nullptr) override;
292 const ITransformation2d& transformation,
294 double* errorFactorPtr = nullptr) override;
296 const ITransformation2d& transformation,
297 IObject2d& result,
299 double* errorFactorPtr = nullptr) const override;
301 const ITransformation2d& transformation,
302 IObject2d& result,
304 double* errorFactorPtr = nullptr) const override;
305
306 // reimplemented (iser::IObject)
307 QByteArray GetFactoryId() const override;
308
309 // reimplemented (iser::ISerializable)
310 bool Serialize(iser::IArchive& archive) override;
311
312 // reimplemented (istd::IChangeable)
313 int GetSupportedOperations() const override;
314 bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS) override;
315 std::unique_ptr<istd::IChangeable> CloneMe(CompatibilityMode mode = CM_WITHOUT_REFS) const override;
316
317 // static methods
321 static const i2d::CRectangle& GetEmpty();
325 static const i2d::CRectangle& GetInvalid();
326
327private:
328 istd::CRange m_horizontalRange;
329 istd::CRange m_verticalRange;
330
331 // static atributes
332 static CRectangle s_empty;
333 static CRectangle s_invalid;
334};
335
336
337// inline methods
338
339inline double CRectangle::GetLeft() const
340{
341 return m_horizontalRange.GetMinValue();
342}
343
344
345inline double CRectangle::GetTop() const
346{
347 return m_verticalRange.GetMinValue();
348}
349
350
351inline double CRectangle::GetRight() const
352{
353 return m_horizontalRange.GetMaxValue();
354}
355
356
357inline double CRectangle::GetBottom() const
358{
359 return m_verticalRange.GetMaxValue();
360}
361
362
364{
365 return m_horizontalRange;
366}
367
368
370{
371 return m_horizontalRange;
372}
373
374
376{
377 return m_verticalRange;
378}
379
380
382{
383 return m_verticalRange;
384}
385
386
387// static methods
388
390{
391 return s_empty;
392}
393
394
396{
397 return s_invalid;
398}
399
400
401} // namespace i2d
402
403
Definition of a line in 2D-space.
Definition CLine2d.h:26
Base class for 2D-objects implementing interface i2d::IObject2d.
Simple rectangle with integer bounds.
Definition CRect.h:26
Definition of rectangle area orthogonal to axis of coordination system.
Definition CRectangle.h:31
double GetTop() const
Get value of top boundary.
Definition CRectangle.h:345
double GetHeight() const
Get height of this rectangle.
void MoveCenterTo(const CVector2d &position) override
Move object to position position.
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.
bool Transform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=nullptr) override
Transform this object using some transformation.
CRectangle GetTranslated(const i2d::CVector2d &delta) const
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:363
CVector2d GetBottomCenter() const
Get point in center of bottom edge.
QByteArray GetFactoryId() const override
double GetLeft() const
Get value of left boundary.
Definition CRectangle.h:339
void Translate(const i2d::CVector2d &delta)
bool Serialize(iser::IArchive &archive) override
Load or store state of this object as a archive stream.
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
double GetBottom() const
Get value of bottom boundary.
Definition CRectangle.h:357
void SetRight(double right)
Set value of right boundary.
void SetTopLeft(const CVector2d &topLeft)
Set left-top point of this rectangle.
int GetSupportedOperations() const override
Get set of flags for supported operations.
CRectangle(const istd::CRange &horizontalRange, const istd::CRange &verticalRange)
CVector2d GetLeftTop() const
Get left-top point of this rectangle.
bool InvTransform(const ITransformation2d &transformation, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=nullptr) override
Do inverse transformation of this object.
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)
bool GetInvTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=nullptr) const override
Calulate inverse transformation of the object into second one.
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:381
bool operator!=(const CRectangle &rect) const
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.
bool GetTransformed(const ITransformation2d &transformation, IObject2d &result, ITransformation2d::ExactnessMode mode=ITransformation2d::EM_NONE, double *errorFactorPtr=nullptr) const override
Calulate transformation of the object into second one.
CVector2d GetNearestPointTo(const CVector2d &point) const
Get the nearest point in the rectangle for the some given point.
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:369
static const i2d::CRectangle & GetInvalid()
Get invalid rectangle.
Definition CRectangle.h:395
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:389
bool IsValidNonEmpty() const
Return true if the rectangle is valid and it is not empty.
const istd::CRange & GetVerticalRange() const
Get values of vertical boundaries.
Definition CRectangle.h:375
CRectangle(const istd::CIndex2d &size)
bool Contains(const CRectangle &rect) const
Check if some rectangle is fully contained in this rectangle.
bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS) override
double GetRight() const
Get value of right boundary.
Definition CRectangle.h:351
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.
std::unique_ptr< istd::IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const override
Make a copy of this object.
CRectangle(const CVector2d &topLeft, const CVector2d &bottomRight)
CVector2d GetCenter() const override
Returns center of this 2D-object.
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).
bool IsValid() const
Return true if the rectangle is valid.
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:30
Common interface for all calibration objects.
@ EM_NONE
There are no preferences, should be automatically selected.
Represent input/output persistence archive.
Definition IArchive.h:34
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:25
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:356
ValueType GetMinValue() const
Get the bottom value.
Definition TRange.h:335
Contains the 2D objects.
Definition CAffine2d.h:15

© Witold Gantzke and Kirill Lepskiy