kimath: SHAPE_POLY_SET should re-parent triangulated polygons when copied/cloned

This commit is contained in:
Tomasz Wlostowski 2020-10-08 15:22:02 +02:00
parent 80ba02caf5
commit db9e111838
2 changed files with 65 additions and 20 deletions

View File

@ -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,15 +140,9 @@ class SHAPE_POLY_SET : public SHAPE
c = m_vertices[ tri.c ];
}
void AddTriangle( const TRI& aTri )
{
m_triangles.push_back( aTri );
}
TRIANGULATED_POLYGON& operator=( const TRIANGULATED_POLYGON& aOther );
void AddTriangle( int a, int b, int c )
{
m_triangles.emplace_back( a, b, c, this );
}
void AddTriangle( int a, int b, int c );
void AddVertex( const VECTOR2I& aP )
{

View File

@ -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<SHAPE*>& aSubshapes )
{
aSubshapes.reserve( GetIndexableSubshapeCount() );
@ -2164,3 +2171,53 @@ void SHAPE_POLY_SET:: GetIndexableSubshapes( std::vector<SHAPE*>& 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()
{
}