00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef RECT_H
00030 #define RECT_H
00031
00032 #include "QGpCoreToolsDLLExport.h"
00033 #include "Point.h"
00034 #include "Point2D.h"
00035 #include "Curve.h"
00036 #include "XMLClass.h"
00037
00038 namespace QGpCoreTools {
00039
00040 class QGPCORETOOLS_EXPORT Rect: public XMLClass
00041 {
00042 public:
00043 enum Area {AllRect,
00044 AboveAscDiag,
00045 BelowAscDiag,
00046 AboveDescDiag,
00047 BelowDescDiag};
00048 inline Rect();
00049 inline Rect(const Point2D& p1, const Point2D& p2);
00050 inline Rect(const Point& p1, const Point& p2);
00051 inline Rect(const QPoint& p1, const QPoint& p2);
00052 inline Rect(const QPointF& p1, const QPointF& p2);
00053 inline Rect(double nx1, double ny1, double nx2, double ny2);
00054 Rect(const Rect& o);
00055 virtual ~Rect() {}
00056
00057 virtual const QString& xml_tagName() const {return xmlRectTag;}
00058 static const QString xmlRectTag;
00059
00060 void setLimits (double nx1, double ny1, double nx2, double ny2);
00061 bool includes (const Rect & r) const;
00062 bool includes (const Point & p) const;
00063 bool includes (const Point2D & p) const;
00064 bool includes (const Point2D & p, Area inArea) const;
00065 inline bool includes (const Point2D& p1, const Point2D& p2) const;
00066 bool includes (double x1, double y1, double x2, double y2) const;
00067 bool isNull() {return _x1==_x2 && _y1==_y2;}
00068 double x1() const {return _x1;}
00069 double y1() const {return _y1;}
00070 double x2() const {return _x2;}
00071 double y2() const {return _y2;}
00072 Point2D topLeft() const {return Point2D(_x1, _y1);}
00073 Point2D bottomRight() const {return Point2D(_x2, _y2);}
00074 double width() const {return _x2 -_x1;}
00075 double height() const {return _y2 -_y1;}
00076 double area() const {return width()*height();}
00077 void setX1(double nx1);
00078 void setY1(double ny1);
00079 void setX2(double nx2);
00080 void setY2(double ny2);
00081 void add(double x, double y);
00082 void add(const Point& p);
00083 void add(const Point2D& p);
00084 void add(const Rect& r);
00085 Rect intersect(const Rect& r) const;
00086 void intersect(Point& p1, Point& p2) const;
00087 void square();
00088 void enlarge(double dx, double dy, SamplingOptions xScale, SamplingOptions yScale);
00089 void enlarge(double ratio, SamplingOptions xScale, SamplingOptions yScale);
00090 void printDebug() const;
00091 protected:
00092 virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00093 virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00094 virtual XMLMember xml_member(XML_MEMBER_ARGS);
00095 protected:
00096 double _x1, _y1, _x2, _y2;
00097 };
00098
00099
00100 inline Rect::Rect()
00101 {
00102 setLimits(0,0,0,0);
00103 }
00104
00105 inline Rect::Rect(double nx1, double ny1, double nx2, double ny2)
00106 {
00107 setLimits(nx1,ny1,nx2,ny2);
00108 }
00109
00110 inline Rect::Rect(const Point2D& p1, const Point2D& p2)
00111 {
00112 setLimits(p1.x(), p1.y(), p2.x(), p2.y());
00113 }
00114
00115 inline Rect::Rect(const Point& p1, const Point& p2)
00116 {
00117 setLimits(p1.x(), p1.y(), p2.x(), p2.y());
00118 }
00119
00120 inline Rect::Rect(const QPoint& p1, const QPoint& p2)
00121 {
00122 setLimits(p1.x(), p1.y(), p2.x(), p2.y());
00123 }
00124
00125 inline Rect::Rect(const QPointF& p1, const QPointF& p2)
00126 {
00127 setLimits(p1.x(), p1.y(), p2.x(), p2.y());
00128 }
00129
00130 inline bool Rect::includes (const Point2D& p1, const Point2D& p2) const
00131 {
00132 return includes(p1.x(), p1.y(), p2.x(), p2.y());
00133 }
00134
00135 }
00136
00137 #endif // RECT_H