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

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

#include <shape_poly_set.h>

Public Member Functions

bool IsLastPolygon () const
 
 operator bool () const
 
void Advance ()
 Advance 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 () const
 
bool IsAdjacent (SEGMENT_ITERATOR_TEMPLATE< T > aOther) const
 

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 >

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

Definition at line 336 of file shape_poly_set.h.

Member Function Documentation

◆ Advance()

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

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

Definition at line 356 of file shape_poly_set.h.

357 {
358 // Advance vertex index
360 int last;
361
362 // Check whether the user wants to iterate through the vertices of the holes
363 // and behave accordingly.
364 if( m_iterateHoles )
365 {
366 last = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
367
368 // If the last vertex of the contour was reached, advance the contour index.
369 if( m_currentSegment >= last )
370 {
373
374 // If the last contour of the current polygon was reached, advance the
375 // outline index.
376 int totalContours = m_poly->CPolygon( m_currentPolygon ).size();
377
378 if( m_currentContour >= totalContours )
379 {
382 }
383 }
384 }
385 else
386 {
387 last = m_poly->CPolygon( m_currentPolygon )[0].SegmentCount();
388 // If the last vertex of the outline was reached, advance to the following
389 // polygon
390 if( m_currentSegment >= last )
391 {
394 }
395 }
396 }
const POLYGON & CPolygon(int aIndex) const

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++().

◆ Get()

◆ GetIndex()

template<class T >
VERTEX_INDEX SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::GetIndex ( ) const
inline
Returns
the indices of the current polygon, contour and vertex.

Definition at line 421 of file shape_poly_set.h.

422 {
423 VERTEX_INDEX index;
424
425 index.m_polygon = m_currentPolygon;
426 index.m_contour = m_currentContour;
427 index.m_vertex = m_currentSegment;
428
429 return index;
430 }

References SHAPE_POLY_SET::VERTEX_INDEX::m_contour, 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::VERTEX_INDEX::m_polygon, and SHAPE_POLY_SET::VERTEX_INDEX::m_vertex.

◆ IsAdjacent()

template<class T >
bool SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::IsAdjacent ( SEGMENT_ITERATOR_TEMPLATE< T >  aOther) const
inline
Parameters
aOtheris an iterator pointing to another segment.
Returns
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 437 of file shape_poly_set.h.

438 {
439 // Check that both iterators point to the same contour of the same polygon of the
440 // same polygon set.
441 if( m_poly == aOther.m_poly && m_currentPolygon == aOther.m_currentPolygon &&
442 m_currentContour == aOther.m_currentContour )
443 {
444 // Compute the total number of segments.
445 int numSeg;
446 numSeg = m_poly->CPolygon( m_currentPolygon )[m_currentContour].SegmentCount();
447
448 // Compute the difference of the segment indices. If it is exactly one, they
449 // are adjacent. The only missing case where they also are adjacent is when
450 // the segments are the first and last one, in which case the difference
451 // always equals the total number of segments minus one.
452 int indexDiff = std::abs( m_currentSegment - aOther.m_currentSegment );
453
454 return ( indexDiff == 1 ) || ( indexDiff == (numSeg - 1) );
455 }
456
457 return false;
458 }
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401

References std::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().

◆ IsLastPolygon()

template<class T >
bool SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::IsLastPolygon ( ) const
inline

◆ operator bool()

◆ operator*()

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

◆ operator++() [1/2]

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

Definition at line 403 of file shape_poly_set.h.

404 {
405 Advance();
406 }
void Advance()
Advance the indices of the current vertex/outline/contour, checking whether the vertices in the holes...

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

◆ operator++() [2/2]

template<class T >
void SHAPE_POLY_SET::SEGMENT_ITERATOR_TEMPLATE< T >::operator++ ( int  dummy)
inline

Definition at line 398 of file shape_poly_set.h.

399 {
400 Advance();
401 }

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

Friends And Related Function Documentation

◆ SHAPE_POLY_SET

template<class T >
friend class SHAPE_POLY_SET
friend

Definition at line 461 of file shape_poly_set.h.

Member Data Documentation

◆ m_currentContour

◆ m_currentPolygon

◆ m_currentSegment

◆ m_iterateHoles

◆ m_lastPolygon

◆ m_poly


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