From 32bd31a1b8578aa1e53a0875f87f0eb5bd24f407 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Thu, 23 Jul 2020 01:04:13 +0200 Subject: [PATCH] libs/kimath: implement BBox() and Size() methods in SHAPE_COMPOUND --- libs/kimath/include/geometry/shape_compound.h | 18 ++++++++++++------ libs/kimath/src/geometry/shape_compound.cpp | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/libs/kimath/include/geometry/shape_compound.h b/libs/kimath/include/geometry/shape_compound.h index e80818e016..1b1fa9dbf1 100644 --- a/libs/kimath/include/geometry/shape_compound.h +++ b/libs/kimath/include/geometry/shape_compound.h @@ -69,12 +69,8 @@ class SHAPE_COMPOUND : public SHAPE int Distance( const SEG& aSeg ) const; - void Move ( const VECTOR2I& aVector ) override - { - for( auto& item : m_shapes ) - item->Move( aVector ); - } - + void Move ( const VECTOR2I& aVector ) override; + void AddShape( SHAPE* aShape ) { m_shapes.push_back( aShape ); @@ -86,10 +82,20 @@ class SHAPE_COMPOUND : public SHAPE return m_shapes.empty(); } + int Size() const + { + return m_shapes.size(); + } + void Rotate( double aAngle, const VECTOR2I& aCenter = { 0, 0 } ) override; bool IsSolid() const override; + SHAPE* UniqueSubshape() const + { + return m_shapes.size() != 1 ? nullptr : m_shapes[0]; + } + private: BOX2I m_cachedBBox; diff --git a/libs/kimath/src/geometry/shape_compound.cpp b/libs/kimath/src/geometry/shape_compound.cpp index 802245fea9..49ab038dd2 100644 --- a/libs/kimath/src/geometry/shape_compound.cpp +++ b/libs/kimath/src/geometry/shape_compound.cpp @@ -72,18 +72,35 @@ SHAPE_COMPOUND* SHAPE_COMPOUND::Clone() 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 { - + assert(false); } void SHAPE_COMPOUND::Rotate( double aAngle, const VECTOR2I& aCenter ) { + assert( false ); }