00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef INC_MI32_FILLPOLY_H
00023 #define INC_MI32_FILLPOLY_H
00024
00025 #include <mi32/polyline.h>
00026
00027
00028 class FILLPOLYGON {
00029 public:
00030
00031
00032 class SPAN {
00033 public:
00034 void Process(const double x1, const double x2, const double y) {VProcess(x1,x2,y);};
00035 private:
00036 virtual void VProcess(const double x1, const double x2, const double y) = 0;
00037 };
00038
00039
00040
00041 static ERRVALUE MakeScans (
00042 const POLYLINE& polyline,
00043 SPAN& span,
00044 const double origin = 0.0,
00045 const double step = 1.0
00046 );
00047
00048 private:
00049 #ifndef GENERATING_DOXYGEN_OUTPUT
00050
00051 class EDGE {
00052 public:
00053
00054 EDGE (
00055 const DPOINT2D& p1,
00056 const DPOINT2D& p2
00057 ) :
00058 m_YMin(MIN(p1.y,p2.y)),
00059 m_YMax(MAX(p1.y,p2.y)),
00060 m_DX((p1.y != p2.y) ? (p2.x - p1.x) / (p2.y - p1.y) : 0.0),
00061 m_X((p1.y < p2.y) ? p1.x : p2.x)
00062 {
00063 }
00064
00065 EDGE& operator= (
00066 const EDGE& rhs
00067 ) {
00068 if (this != &rhs) {
00069 const_cast<double&>(m_YMin) = rhs.m_YMin;
00070 const_cast<double&>(m_YMax) = rhs.m_YMax;
00071 const_cast<double&>(m_DX) = rhs.m_DX;
00072 m_X = rhs.m_X;
00073 }
00074 return (*this);
00075 }
00076
00077 bool IsHorizontal (
00078 ) const {
00079 return (m_YMin == m_YMax);
00080 }
00081
00082 void SetX (
00083 const double y
00084 ) {
00085 m_X += m_DX * (y - m_YMin);
00086 return;
00087 }
00088
00089 double GetX (
00090 ) {
00091 return m_X;
00092 }
00093
00094 void UpdateX (
00095 ) {
00096 m_X += m_DX;
00097 return;
00098 }
00099
00100 const double m_YMin;
00101 const double m_YMax;
00102 const double m_DX;
00103
00104 private:
00105
00106 double m_X;
00107 };
00108
00109 static int DoubleLessCompare (
00110 const void *p1,
00111 const void *p2
00112 ) {
00113 const double *d1 = static_cast<const double*>(p1);
00114 const double *d2 = static_cast<const double*>(p2);
00115
00116 if (*d1 > *d2) return 1;
00117 if (*d1 < *d2) return -1;
00118 return 0;
00119 };
00120
00121 static int EdgeYMinGreaterCompare (
00122 const void *p1,
00123 const void *p2
00124 ) {
00125 const EDGE *d1 = static_cast<const EDGE*>(p1);
00126 const EDGE *d2 = static_cast<const EDGE*>(p2);
00127
00128 if (d1->m_YMin < d2->m_YMin) return 1;
00129 if (d1->m_YMin > d2->m_YMin) return -1;
00130 return 0;
00131 };
00132
00133
00134 FILLPOLYGON();
00135 ~FILLPOLYGON();
00136 FILLPOLYGON(const FILLPOLYGON&);
00137 #endif // GENERATING_DOXYGEN_OUTPUT
00138
00139 };
00140
00141 #endif
00142