diff --git a/libs/kimath/include/geometry/shape_poly_set.h b/libs/kimath/include/geometry/shape_poly_set.h index a02bc7927e..5ea5c61446 100644 --- a/libs/kimath/include/geometry/shape_poly_set.h +++ b/libs/kimath/include/geometry/shape_poly_set.h @@ -88,17 +88,7 @@ class SHAPE_POLY_SET : public SHAPE virtual bool IsClosed() const override { return true; } - virtual const BOX2I BBox( int aClearance = 0 ) const override - { - BOX2I bbox( parent->m_vertices[a] ); - bbox.Merge( parent->m_vertices[b] ); - bbox.Merge( parent->m_vertices[c] ); - - if( aClearance != 0 ) - bbox.Inflate( aClearance ); - - return bbox; - } + virtual const BOX2I BBox( int aClearance = 0 ) const override; virtual const VECTOR2I GetPoint( int aIndex ) const override { @@ -132,6 +122,10 @@ class SHAPE_POLY_SET : public SHAPE TRIANGULATED_POLYGON* parent; }; + TRIANGULATED_POLYGON(); + TRIANGULATED_POLYGON( const TRIANGULATED_POLYGON& aOther ); + ~TRIANGULATED_POLYGON(); + void Clear() { m_vertices.clear(); @@ -146,16 +140,10 @@ class SHAPE_POLY_SET : public SHAPE c = m_vertices[ tri.c ]; } - void AddTriangle( const TRI& aTri ) - { - m_triangles.push_back( aTri ); - } - - void AddTriangle( int a, int b, int c ) - { - m_triangles.emplace_back( a, b, c, this ); - } + TRIANGULATED_POLYGON& operator=( const TRIANGULATED_POLYGON& aOther ); + void AddTriangle( int a, int b, int c ); + void AddVertex( const VECTOR2I& aP ) { m_vertices.push_back( aP ); diff --git a/libs/kimath/src/geometry/shape_poly_set.cpp b/libs/kimath/src/geometry/shape_poly_set.cpp index 1c32126658..457fee8ee3 100644 --- a/libs/kimath/src/geometry/shape_poly_set.cpp +++ b/libs/kimath/src/geometry/shape_poly_set.cpp @@ -1906,6 +1906,8 @@ SHAPE_POLY_SET &SHAPE_POLY_SET::operator=( const SHAPE_POLY_SET& aOther ) m_triangulatedPolys.clear(); m_triangulationValid = false; + printf("operator= %p %p\n", this, &aOther ); + if( aOther.IsTriangulationUpToDate() ) { for( unsigned i = 0; i < aOther.TriangulatedPolyCount(); i++ ) @@ -1930,6 +1932,8 @@ MD5_HASH SHAPE_POLY_SET::GetHash() const bool SHAPE_POLY_SET::IsTriangulationUpToDate() const { + + printf("[%p] IsTriValid %d\n", this, !!m_triangulationValid ); if( !m_triangulationValid ) return false; @@ -2137,11 +2141,13 @@ bool SHAPE_POLY_SET::hasTouchingHoles( const POLYGON& aPoly ) const return false; } + bool SHAPE_POLY_SET::HasIndexableSubshapes() const { return IsTriangulationUpToDate(); } + size_t SHAPE_POLY_SET::GetIndexableSubshapeCount() const { size_t n = 0; @@ -2150,6 +2156,7 @@ size_t SHAPE_POLY_SET::GetIndexableSubshapeCount() const return n; } + void SHAPE_POLY_SET:: GetIndexableSubshapes( std::vector& aSubshapes ) { aSubshapes.reserve( GetIndexableSubshapeCount() ); @@ -2164,3 +2171,53 @@ void SHAPE_POLY_SET:: GetIndexableSubshapes( std::vector& aSubshapes ) } } + +const BOX2I SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRI::BBox( int aClearance ) const +{ + BOX2I bbox( parent->m_vertices[a] ); + bbox.Merge( parent->m_vertices[b] ); + bbox.Merge( parent->m_vertices[c] ); + + if( aClearance != 0 ) + bbox.Inflate( aClearance ); + + return bbox; +} + + +void SHAPE_POLY_SET::TRIANGULATED_POLYGON::AddTriangle( int a, int b, int c ) +{ + m_triangles.emplace_back( a, b, c, this ); +} + + +SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRIANGULATED_POLYGON( const TRIANGULATED_POLYGON& aOther ) +{ + m_vertices = aOther.m_vertices; + m_triangles = aOther.m_triangles; + + for( TRI& tri : m_triangles ) + tri.parent = this; +} + + +SHAPE_POLY_SET::TRIANGULATED_POLYGON& SHAPE_POLY_SET::TRIANGULATED_POLYGON::operator=( const TRIANGULATED_POLYGON& aOther ) +{ + m_vertices = aOther.m_vertices; + m_triangles = aOther.m_triangles; + + for( TRI& tri : m_triangles ) + tri.parent = this; + + return *this; +} + + +SHAPE_POLY_SET::TRIANGULATED_POLYGON::TRIANGULATED_POLYGON() +{ +} + + +SHAPE_POLY_SET::TRIANGULATED_POLYGON::~TRIANGULATED_POLYGON() +{ +}