Do not use cache when we modify vertices
When we add vertices to the tesselation routines, we cannot reuse these
without the original vertex points.
It may be possible to copy and modify the vertices from the hint data so
that they are properly positioned but naive attempts (moving based on
first point) did not work, so for now, we disable the hint cache when
the vertex sizes do not match as this prevents OOB access
Fixes https://gitlab.com/kicad/code/kicad/-/issues/17621
(cherry picked from commit 06b199fd41
)
This commit is contained in:
parent
18990587b9
commit
890376d04f
|
@ -88,9 +88,13 @@ public:
|
|||
|
||||
firstVertex->updateList();
|
||||
|
||||
if( aHintData )
|
||||
/**
|
||||
* If we have a hint data, we can skip the tesselation process as long as the
|
||||
* the hint source did not need to subdivide the polygon.
|
||||
*/
|
||||
if( aHintData && aHintData->Vertices().size() == m_vertices.size() )
|
||||
{
|
||||
m_result.Triangles() = aHintData->Triangles();
|
||||
m_result.SetTriangles( aHintData->Triangles() );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -170,8 +170,23 @@ public:
|
|||
int GetSourceOutlineIndex() const { return m_sourceOutline; }
|
||||
void SetSourceOutlineIndex( int aIndex ) { m_sourceOutline = aIndex; }
|
||||
|
||||
std::deque<TRI>& Triangles() { return m_triangles; }
|
||||
const std::deque<TRI>& Triangles() const { return m_triangles; }
|
||||
void SetTriangles( const std::deque<TRI>& aTriangles )
|
||||
{
|
||||
m_triangles.resize( aTriangles.size() );
|
||||
|
||||
for( size_t ii = 0; ii < aTriangles.size(); ii++ )
|
||||
{
|
||||
m_triangles[ii] = aTriangles[ii];
|
||||
m_triangles[ii].parent = this;
|
||||
}
|
||||
}
|
||||
|
||||
const std::deque<VECTOR2I>& Vertices() const { return m_vertices; }
|
||||
void SetVertices( const std::deque<VECTOR2I>& aVertices )
|
||||
{
|
||||
m_vertices = aVertices;
|
||||
}
|
||||
|
||||
size_t GetVertexCount() const
|
||||
{
|
||||
|
|
|
@ -3309,11 +3309,6 @@ void SHAPE_POLY_SET::cacheTriangulation( bool aPartition, bool aSimplify,
|
|||
triangulationValid = true;
|
||||
}
|
||||
|
||||
if( triangulationValid && wxLog::IsLevelEnabled(wxLOG_Trace, wxLOG_COMPONENT) )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return triangulationValid;
|
||||
};
|
||||
|
||||
|
@ -3449,7 +3444,7 @@ void SHAPE_POLY_SET::GetIndexableSubshapes( std::vector<const SHAPE*>& aSubshape
|
|||
|
||||
for( const std::unique_ptr<TRIANGULATED_POLYGON>& tpoly : m_triangulatedPolys )
|
||||
{
|
||||
for( TRIANGULATED_POLYGON::TRI& tri : tpoly->Triangles() )
|
||||
for( const TRIANGULATED_POLYGON::TRI& tri : tpoly->Triangles() )
|
||||
aSubshapes.push_back( &tri );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ BOOST_FIXTURE_TEST_CASE( RegressionTriangulationTests, TRIANGULATE_TEST_FIXTURE
|
|||
{
|
||||
const auto tri_poly = poly->TriangulatedPolygon( ii );
|
||||
|
||||
for( auto& tri : tri_poly->Triangles() )
|
||||
for( const auto& tri : tri_poly->Triangles() )
|
||||
tri_area += tri.Area();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue