Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00049 #ifdef _MSC_VER
00050 #pragma once
00051 #endif
00052
00053 #ifndef OGDF_INTERSECTION_RECTANGLE_H
00054 #define OGDF_INTERSECTION_RECTANGLE_H
00055
00056
00057 #define RECT_CMP_EPS 1e-06
00058
00059
00060 #include <ogdf/basic/geometry.h>
00061 #include <math.h>
00062
00063
00064 namespace ogdf {
00065
00066
00067 class OGDF_EXPORT IntersectionRectangle {
00068
00069 private:
00070
00071 DPoint m_p1;
00072 DPoint m_p2;
00073 double m_area;
00074 DPoint m_center;
00075
00076 public:
00077
00078
00079 IntersectionRectangle() : m_p1(), m_p2(), m_area(0.0), m_center() {}
00080
00081 IntersectionRectangle(const DPoint &p1, const DPoint &p2) : m_p1(p1), m_p2(p2) { init(); }
00082
00083 IntersectionRectangle(const IntersectionRectangle &dr) :
00084 m_p1(dr.m_p1), m_p2(dr.m_p2), m_area(dr.m_area), m_center(dr.m_center){};
00085
00086 IntersectionRectangle(double x1, double y1, double x2, double y2) {
00087 m_p1.m_x = x1; m_p1.m_y = y1; m_p2.m_x = x2; m_p2.m_y = y2;
00088 init();
00089 }
00090
00091 IntersectionRectangle(const DLine &dl) : m_p1(dl.start()), m_p2(dl.end())
00092 { init(); }
00093
00094 IntersectionRectangle(const DPoint &, double , double);
00095
00096
00097 bool operator==(const IntersectionRectangle &dr) const {
00098 return m_p1 == dr.m_p1 && m_p2 == dr.m_p2;
00099 }
00100
00101 bool operator!=(const IntersectionRectangle &dr) const {
00102 return !(*this == dr);
00103 }
00104
00105
00106 IntersectionRectangle &operator= (const IntersectionRectangle &dr) {
00107 if (this != &dr) {
00108 m_p1 = dr.m_p1;
00109 m_p2 = dr.m_p2;
00110 m_center = dr.m_center;
00111 m_area = dr.m_area;
00112 }
00113 return *this;
00114 }
00115
00116
00117 double width() const {
00118 return m_p2.m_x - m_p1.m_x;
00119 }
00120
00121 double height() const {
00122 return m_p2.m_y - m_p1.m_y;
00123 }
00124
00125 DPoint center() const { return m_center;}
00126
00127 double area() const { return m_area;}
00128
00129
00130
00131 const DPoint &p1() const { return m_p1; }
00132 const DPoint &p2() const { return m_p2; }
00133
00134 bool inside(const DPoint &p) const {
00135 if ((p.m_x + RECT_CMP_EPS) < m_p1.m_x ||
00136 (p.m_x - RECT_CMP_EPS) > m_p2.m_x ||
00137 (p.m_y + RECT_CMP_EPS) < m_p1.m_y ||
00138 (p.m_y - RECT_CMP_EPS) > m_p2.m_y)
00139 return false;
00140 return true;
00141 }
00142
00143 bool intersects(const IntersectionRectangle &) const;
00144
00145
00146
00147 IntersectionRectangle intersection(const IntersectionRectangle &) const;
00148
00149 double distance(const IntersectionRectangle &) const;
00150
00151 void move(const DPoint &);
00152
00153 private:
00154
00155 void init();
00156
00157 void yInvert() { swap(m_p1.m_y, m_p2.m_y); }
00158
00159 void xInvert() { swap(m_p1.m_x, m_p2.m_x); }
00160
00161 DLine bottom() const { return DLine(m_p1.m_x,m_p1.m_y,m_p2.m_x,m_p1.m_y);}
00162 DLine top() const { return DLine(m_p1.m_x, m_p2.m_y, m_p2.m_x,m_p2.m_y);}
00163 DLine left() const { return DLine(m_p1.m_x, m_p1.m_y, m_p1.m_x, m_p2.m_y);}
00164 DLine right() const { return DLine(m_p2.m_x, m_p1.m_y, m_p2.m_x, m_p2.m_y);}
00165
00166 double parallelDist(const DLine &, const DLine &) const;
00167
00168 double pointDist(const DPoint &p1, const DPoint &p2) const {
00169 return sqrt((p1.m_y - p2.m_y) * (p1.m_y - p2.m_y) + (p1.m_x - p2.m_x) * (p1.m_x - p2.m_x));
00170 }
00171 friend ostream& operator<<(ostream &,const IntersectionRectangle &);
00172 };
00173
00174
00175
00176 class PointComparer {
00177 public:
00178 static int compare(const DPoint &p1, const DPoint &p2) {
00179 if(p1.m_x > p2.m_x) return 1;
00180 if(p1.m_x < p2.m_x) return -1;
00181 if(p1.m_y > p2.m_y) return 1;
00182 if(p1.m_y < p2.m_y) return -1;
00183 return 0;
00184 }
00185 OGDF_AUGMENT_STATICCOMPARER(DPoint)
00186 };
00187
00188 }
00189 #endif