21 #ifndef GR_LINE_DRAW__H
22 #define GR_LINE_DRAW__H
102 template <
typename T>
130 LineDrawImp<T> m_line ;
140 template <
typename T>
143 m_dx = (x2 > x1) ? (x2 - x1) : (x1 - x2) ;
144 m_dy = (y2 > y1) ? (y2 - y1) : (y1 - y2) ;
145 m_flat = m_dx > m_dy ;
146 m_big = m_flat ? x1 : y1 ;
147 m_small = m_flat ? y1 : x1 ;
148 m_step_big = m_flat ? ( x2 < x1 ? -1 : 1 ) : ( y2 < y1 ? -1 : 1 ) ;
149 m_step_small = m_flat ? ( y2 < y1 ? -1 : 1 ) : ( x2 < x1 ? -1 : 1 ) ;
150 m_dbig = m_flat ? m_dx : m_dy ;
151 m_dsmall = m_flat ? m_dy : m_dx ;
153 m_brc = m_dbig / T(2) ;
154 m_big_off_end = (m_flat ? x2 : y2) + m_step_big ;
157 template <
typename T>
160 return m_flat ? m_big : m_small ;
163 template <
typename T>
166 return m_flat ? m_small : m_big ;
169 template <
typename T>
175 template <
typename T>
178 if( m_big != m_big_off_end )
180 m_big += m_step_big ;
182 if( m_brc > m_brmax )
185 m_small += m_step_small ;
188 return m_big != m_big_off_end ;
191 template <
typename T>
198 template <
typename T>
200 m_line( x1 , y1 , x2 , y2 ) ,
204 m_horizontal( y1 == y2 ) ,
210 template <
typename T>
213 m_x1 = m_x2 = m_line.x() ;
217 template <
typename T>
226 ok = m_line.nextPoint() ;
227 }
while( ok && m_line.y() == m_y ) ;
231 template <
typename T>
241 else if( m_line.flat() )
252 else if( m_horizontal )
256 else if( m_line.flat() && m_off_end )
260 else if( m_line.flat() )
268 bool rc = m_line.nextPoint() ;
274 template <
typename T>
277 return m_line.flat() ;
280 template <
typename T>
283 return m_x1 < m_x2 ? m_x1 : m_x2 ;
286 template <
typename T>
289 return m_x1 < m_x2 ? m_x2 : m_x1 ;
292 template <
typename T>
T y() const
Returns the current y coordinate.
A class template for drawing lines in terms of separate horizontal line segments. ...
bool flat() const
Returns true if the x dimension of the line is greater the the y dimension.
T x1() const
Returns the current smaller x coordinate.
T y() const
Returns the current y coordinate for point-wise iteration.
T n() const
Returns the iteration count.
T x() const
Returns the current x coordinate for point-wise iteration.
A low-level line-drawing class used in the implementation of Gr::LineDraw.
LineDrawImp(T x1, T y1, T x2, T y2)
Constructor.
bool flat() const
Returns true if the x dimension of the line is greater the the y dimension.
T x2() const
Returns the current larger x coordinate.
bool more()
Iterator for the next line segment. Returns true at least once.
bool nextPoint()
Steps to the next point for point-wise iteration.
LineDraw(T x1, T y1, T x2, T y2)
Constructor.