Change partitions to fixed size

Partititioning small polygons causes excessive partitions when we use a
fixed number of cells per side.  Partitioning by size keeps the
partition count limited and speeds the calculations.

Also adds an option to not partition the grid for elements (like 3d
raytracing) that do not need it.

Fixes https://gitlab.com/kicad/code/kicad/issues/5579
This commit is contained in:
Seth Hillbrand 2020-09-10 09:28:52 -07:00
parent 6009414e22
commit 08d4e91f3b
3 changed files with 15 additions and 11 deletions

View File

@ -132,7 +132,7 @@ void Convert_shape_line_polygon_to_triangles( SHAPE_POLY_SET &aPolyList,
const BOARD_ITEM &aBoardItem )
{
aPolyList.CacheTriangulation();
aPolyList.CacheTriangulation( false );
const double conver_d = (double)aBiuTo3DunitsScale;
for( unsigned int j = 0; j < aPolyList.TriangulatedPolyCount(); j++ )

View File

@ -99,7 +99,7 @@ class SHAPE_POLY_SET : public SHAPE
return bbox;
}
virtual const VECTOR2I GetPoint( int aIndex ) const override
virtual const VECTOR2I GetPoint( int aIndex ) const override
{
switch(aIndex)
{
@ -165,7 +165,7 @@ class SHAPE_POLY_SET : public SHAPE
return m_triangles.size();
}
size_t GetVertexCount() const
size_t GetVertexCount() const
{
return m_vertices.size();
}
@ -1365,7 +1365,7 @@ class SHAPE_POLY_SET : public SHAPE
SHAPE_POLY_SET& operator=( const SHAPE_POLY_SET& );
void CacheTriangulation();
void CacheTriangulation( bool aPartition = true );
bool IsTriangulationUpToDate() const;
MD5_HASH GetHash() const;

View File

@ -1903,7 +1903,7 @@ bool SHAPE_POLY_SET::IsTriangulationUpToDate() const
static void partitionPolyIntoRegularCellGrid(
const SHAPE_POLY_SET& aPoly, int aCells, SHAPE_POLY_SET& aOut )
const SHAPE_POLY_SET& aPoly, int aSize, SHAPE_POLY_SET& aOut )
{
BOX2I bb = aPoly.BBox();
@ -1917,13 +1917,13 @@ static void partitionPolyIntoRegularCellGrid(
if( w > h )
{
n_cells_x = aCells;
n_cells_y = (int) floor( h / w * (double) aCells ) + 1;
n_cells_x = w / aSize;
n_cells_y = floor( h / w * n_cells_x ) + 1;
}
else
{
n_cells_x = (int) floor( w / h * (double) aCells ) + 1;
n_cells_y = aCells;
n_cells_y = h / aSize;
n_cells_x = floor( w / h * n_cells_y ) + 1;
}
SHAPE_POLY_SET ps1( aPoly ), ps2( aPoly ), maskSetOdd, maskSetEven;
@ -1968,7 +1968,7 @@ static void partitionPolyIntoRegularCellGrid(
}
void SHAPE_POLY_SET::CacheTriangulation()
void SHAPE_POLY_SET::CacheTriangulation( bool aPartition )
{
bool recalculate = !m_hash.IsValid();
MD5_HASH hash;
@ -1992,7 +1992,11 @@ void SHAPE_POLY_SET::CacheTriangulation()
SHAPE_POLY_SET tmpSet;
partitionPolyIntoRegularCellGrid( *this, 20, tmpSet );
if( aPartition )
// This partitions into regularly-sized grids (1cm in pcbnew)
partitionPolyIntoRegularCellGrid( *this, 1e7, tmpSet );
else
tmpSet = *this;
m_triangulatedPolys.clear();
m_triangulationValid = true;