diff --git a/common/geometry/shape_poly_set.cpp b/common/geometry/shape_poly_set.cpp index ff2ad87425..3b81809e3d 100644 --- a/common/geometry/shape_poly_set.cpp +++ b/common/geometry/shape_poly_set.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -58,14 +57,6 @@ SHAPE_POLY_SET::SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther ) : { } - -SHAPE_POLY_SET::~SHAPE_POLY_SET() -{ - for( auto p : m_triangulatedPolys ) - delete p; -} - - SHAPE* SHAPE_POLY_SET::Clone() const { return new SHAPE_POLY_SET( *this ); @@ -1871,6 +1862,19 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode, } +SHAPE_POLY_SET &SHAPE_POLY_SET::operator=(const SHAPE_POLY_SET & aOther) +{ + static_cast(*this) = aOther; + m_polys = aOther.m_polys; + + // reset poly cache: + m_hash = MD5_HASH{}; + m_triangulationValid = false; + m_triangulatedPolys.clear(); + return *this; +} + + typedef std::map P2T_MAP; typedef std::vector P2T_VEC; @@ -2022,9 +2026,8 @@ void SHAPE_POLY_SET::CacheTriangulation() for( int i = 0; i < tmpSet.OutlineCount(); i++ ) { - auto p = new TRIANGULATED_POLYGON(); - m_triangulatedPolys.push_back( p ); - triangulateSingle( tmpSet.Polygon( i ), *p ); + m_triangulatedPolys.push_back( std::make_unique() ); + triangulateSingle( tmpSet.Polygon( i ), *m_triangulatedPolys.back() ); } m_triangulationValid = true; diff --git a/include/geometry/shape_poly_set.h b/include/geometry/shape_poly_set.h index cec3491cb3..7494aebb87 100644 --- a/include/geometry/shape_poly_set.h +++ b/include/geometry/shape_poly_set.h @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -406,8 +407,6 @@ class SHAPE_POLY_SET : public SHAPE */ SHAPE_POLY_SET( const SHAPE_POLY_SET& aOther ); - ~SHAPE_POLY_SET(); - /** * Function GetRelativeIndices * @@ -585,7 +584,7 @@ class SHAPE_POLY_SET : public SHAPE const TRIANGULATED_POLYGON* TriangulatedPolygon( int aIndex ) const { - return m_triangulatedPolys[aIndex]; + return m_triangulatedPolys[aIndex].get(); } @@ -1120,6 +1119,8 @@ class SHAPE_POLY_SET : public SHAPE public: + SHAPE_POLY_SET& operator=( const SHAPE_POLY_SET& ); + void CacheTriangulation(); bool IsTriangulationUpToDate() const; @@ -1128,7 +1129,7 @@ class SHAPE_POLY_SET : public SHAPE MD5_HASH checksum() const; - std::vector m_triangulatedPolys; + std::vector> m_triangulatedPolys; bool m_triangulationValid = false; MD5_HASH m_hash;