Browse Source

Add assert to SHAPE_LINE_CHAIN::Segment + Deduplicate code

CSegment should have the exact same logic as Segment

Also, moving definition to .cpp file to reduce need to rebuild every time
newinvert
Roberto Fernandez Bautista 2 years ago
committed by Alex Shvartzkop
parent
commit
e950475bc3
  1. 22
      libs/kimath/include/geometry/shape_line_chain.h
  2. 15
      libs/kimath/src/geometry/shape_line_chain.cpp

22
libs/kimath/include/geometry/shape_line_chain.h

@ -330,16 +330,7 @@ public:
* from the end (i.e. -1 means the last segment in the line chain).
* @return a segment at the \a aIndex in the line chain.
*/
SEG Segment( int aIndex )
{
if( aIndex < 0 )
aIndex += SegmentCount();
if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
return SEG( m_points[aIndex], m_points[0], aIndex );
else
return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
}
SEG Segment( int aIndex ) const;
/**
* Return a constant copy of the \a aIndex segment in the line chain.
@ -348,16 +339,7 @@ public:
* from the end (i.e. -1 means the last segment in the line chain).
* @return a segment at \a aIndex in the line chain.
*/
const SEG CSegment( int aIndex ) const
{
if( aIndex < 0 )
aIndex += SegmentCount();
if( aIndex == (int)( m_points.size() - 1 ) && m_closed )
return SEG( m_points[aIndex], m_points[0], aIndex );
else
return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
}
const SEG CSegment( int aIndex ) const { return Segment( aIndex ); }
/**
* Return the vertex index of the next shape in the chain, or -1 if \a aPointIndex is the

15
libs/kimath/src/geometry/shape_line_chain.cpp

@ -1027,6 +1027,21 @@ int SHAPE_LINE_CHAIN::ShapeCount() const
}
SEG SHAPE_LINE_CHAIN::Segment( int aIndex ) const
{
if( aIndex < 0 )
aIndex += SegmentCount();
wxCHECK( aIndex < SegmentCount() && aIndex >= 0,
m_points.size() > 0 ? SEG( m_points.back(), m_points.back() ) : SEG( 0, 0, 0, 0 ) );
if( aIndex == (int) ( m_points.size() - 1 ) && m_closed )
return SEG( m_points[aIndex], m_points[0], aIndex );
else
return SEG( m_points[aIndex], m_points[aIndex + 1], aIndex );
}
int SHAPE_LINE_CHAIN::NextShape( int aPointIndex ) const
{
if( aPointIndex < 0 )

Loading…
Cancel
Save