KiCad PCB EDA Suite
SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T > Class Template Reference

Class SEGMENT_ITERATOR_TEMPLATE. More...

#include <shape_poly_set.h>

Public Member Functions

bool IsLastPolygon () const
 Function IsLastOutline. More...
 
 operator bool () const
 
void Advance ()
 Function Advance advances the indices of the current vertex/outline/contour, checking whether the vertices in the holes have to be iterated through. More...
 
void operator++ (int dummy)
 
void operator++ ()
 
Get ()
 
operator* ()
 
VERTEX_INDEX GetIndex ()
 Function GetIndex. More...
 
bool IsAdjacent (SEGMENT_ITERATOR_TEMPLATE< T > aOther)
 Function IsAdjacent. More...
 

Private Attributes

SHAPE_POLY_SETm_poly
 
int m_currentPolygon
 
int m_currentContour
 
int m_currentSegment
 
int m_lastPolygon
 
bool m_iterateHoles
 

Friends

class SHAPE_POLY_SET
 

Detailed Description

template<class T>
class SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >

Class SEGMENT_ITERATOR_TEMPLATE.

Base class for iterating over all segments in a given SHAPE_POLY_SET.

Definition at line 212 of file shape_poly_set.h.

Member Function Documentation

template<class T>
void SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::Advance ( )
inline

Function Advance advances the indices of the current vertex/outline/contour, checking whether the vertices in the holes have to be iterated through.

Definition at line 234 of file shape_poly_set.h.

References SHAPE_POLY_SET::CPolygon(), SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentContour, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentPolygon, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentSegment, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_iterateHoles, and SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_poly.

Referenced by SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::operator++().

235  {
236  // Advance vertex index
238  int last;
239 
240  // Check whether the user wants to iterate through the vertices of the holes
241  // and behave accordingly
242  if( m_iterateHoles )
243  {
244  last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
245 
246  // If the last vertex of the contour was reached, advance the contour index
247  if( m_currentSegment >= last )
248  {
249  m_currentSegment = 0;
251 
252  // If the last contour of the current polygon was reached, advance the
253  // outline index
254  int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
255 
256  if( m_currentContour >= totalContours )
257  {
258  m_currentContour = 0;
260  }
261  }
262  }
263  else
264  {
265  last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
266  // If the last vertex of the outline was reached, advance to the following
267  // polygon
268  if( m_currentSegment >= last )
269  {
270  m_currentSegment = 0;
272  }
273  }
274  }
const POLYGON & CPolygon(int aIndex) const
template<class T>
bool SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::IsAdjacent ( SEGMENT_ITERATOR_TEMPLATE< T >  aOther)
inline

Function IsAdjacent.

Parameters
aOtheris an iterator pointing to another segment.
Returns
bool - true if both iterators point to the same segment of the same contour of the same polygon of the same polygon set; false otherwise.

Definition at line 318 of file shape_poly_set.h.

References abs, SHAPE_POLY_SET::CPolygon(), SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentContour, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentPolygon, SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentSegment, and SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_poly.

Referenced by SHAPE_POLY_SET::IsPolygonSelfIntersecting().

319  {
320  // Check that both iterators point to the same contour of the same polygon of the
321  // same polygon set
322  if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
323  m_currentContour == aOther.m_currentContour )
324  {
325  // Compute the total number of segments
326  int numSeg;
327  numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
328 
329  // Compute the difference of the segment indices. If it is exactly one, they
330  // are adjacent. The only missing case where they also are adjacent is when
331  // the segments are the first and last one, in which case the difference
332  // always equals the total number of segments minus one.
333  int indexDiff = abs( m_currentSegment - aOther.m_currentSegment );
334 
335  return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
336  }
337 
338  return false;
339  }
#define abs(a)
Definition: auxiliary.h:84
const POLYGON & CPolygon(int aIndex) const
template<class T>
bool SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::IsLastPolygon ( ) const
inline

Function IsLastOutline.

Returns
bool - true if the current outline is the last one.

Definition at line 219 of file shape_poly_set.h.

References SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_currentPolygon, and SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_lastPolygon.

template<class T>
T SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::operator* ( )
inline

Definition at line 291 of file shape_poly_set.h.

References SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::Get().

292  {
293  return Get();
294  }
template<class T>
void SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::operator++ ( int  dummy)
inline

Definition at line 276 of file shape_poly_set.h.

References SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::Advance().

277  {
278  Advance();
279  }
void Advance()
Function Advance advances the indices of the current vertex/outline/contour, checking whether the ver...
template<class T>
void SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::operator++ ( )
inline

Definition at line 281 of file shape_poly_set.h.

References SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::Advance().

282  {
283  Advance();
284  }
void Advance()
Function Advance advances the indices of the current vertex/outline/contour, checking whether the ver...

Friends And Related Function Documentation

template<class T>
friend class SHAPE_POLY_SET
friend

Definition at line 342 of file shape_poly_set.h.

Member Data Documentation

template<class T>
bool SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::m_iterateHoles
private

The documentation for this class was generated from the following file: