libs/kimath: implement BBox() and Size() methods in SHAPE_COMPOUND

This commit is contained in:
Tomasz Wlostowski 2020-07-23 01:04:13 +02:00
parent c2b9db293f
commit 32bd31a1b8
2 changed files with 30 additions and 7 deletions

View File

@ -69,12 +69,8 @@ class SHAPE_COMPOUND : public SHAPE
int Distance( const SEG& aSeg ) const; int Distance( const SEG& aSeg ) const;
void Move ( const VECTOR2I& aVector ) override void Move ( const VECTOR2I& aVector ) override;
{
for( auto& item : m_shapes )
item->Move( aVector );
}
void AddShape( SHAPE* aShape ) void AddShape( SHAPE* aShape )
{ {
m_shapes.push_back( aShape ); m_shapes.push_back( aShape );
@ -86,10 +82,20 @@ class SHAPE_COMPOUND : public SHAPE
return m_shapes.empty(); return m_shapes.empty();
} }
int Size() const
{
return m_shapes.size();
}
void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override; void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override;
bool IsSolid() const override; bool IsSolid() const override;
SHAPE* UniqueSubshape() const
{
return m_shapes.size() != 1 ? nullptr : m_shapes[0];
}
private: private:
BOX2I m_cachedBBox; BOX2I m_cachedBBox;

View File

@ -72,18 +72,35 @@ SHAPE_COMPOUND* SHAPE_COMPOUND::Clone() const
const BOX2I SHAPE_COMPOUND::BBox( int aClearance ) const const BOX2I SHAPE_COMPOUND::BBox( int aClearance ) const
{ {
BOX2I bb;
if ( m_shapes.size() < 1 )
return bb;
bb = m_shapes[0]->BBox();
for( int i = 1; i < m_shapes.size(); i++ )
bb.Merge( m_shapes[i]->BBox() );
return bb;
}
void SHAPE_COMPOUND::Move ( const VECTOR2I& aVector )
{
for( auto& item : m_shapes )
item->Move( aVector );
} }
int SHAPE_COMPOUND::Distance( const SEG& aSeg ) const int SHAPE_COMPOUND::Distance( const SEG& aSeg ) const
{ {
assert(false);
} }
void SHAPE_COMPOUND::Rotate( double aAngle, const VECTOR2I& aCenter ) void SHAPE_COMPOUND::Rotate( double aAngle, const VECTOR2I& aCenter )
{ {
assert( false );
} }