Performance optimisations for hatching.

This commit is contained in:
Jeff Young 2025-04-07 20:07:05 +01:00
parent bccf365380
commit 845cdb1b25
3 changed files with 39 additions and 3 deletions

View File

@ -596,7 +596,39 @@ void EDA_SHAPE::UpdateHatching() const
[&]( const std::vector<SEG>& hatchLines ) [&]( const std::vector<SEG>& hatchLines )
{ {
for( const SEG& seg : hatchLines ) for( const SEG& seg : hatchLines )
TransformOvalToPolygon( m_hatching, seg.A, seg.B, lineWidth, ARC_LOW_DEF, ERROR_INSIDE ); {
// This is essentially TransformOvalToPolygon(), but without the rounded ends, which
// in our case are nothing but a performance sink.
VECTOR2I endp = seg.B - seg.A;
VECTOR2I startp = seg.A;
// normalize the position in order to have endp.x >= 0
// it makes calculations more easy to understand
if( endp.x < 0 )
{
endp = seg.A - seg.B;
startp = seg.B;
}
EDA_ANGLE delta_angle( endp );
int seg_len = endp.EuclideanNorm();
int halfwidth = lineWidth / 2;
// Build the polygon (a horizontal rectangle).
SHAPE_POLY_SET polyshape;
polyshape.NewOutline();
polyshape.Append( -halfwidth, halfwidth );
polyshape.Append( -halfwidth, -halfwidth );
polyshape.Append( halfwidth + seg_len, -halfwidth );
polyshape.Append( halfwidth + seg_len, halfwidth );
// Rotate and move the polygon to its right location
polyshape.Rotate( -delta_angle );
polyshape.Move( startp );
m_hatching.Append( polyshape);
}
}; };
switch( m_shape ) switch( m_shape )

View File

@ -191,6 +191,7 @@ public:
{ {
POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems ); POLYGON_POINT_EDIT_BEHAVIOR::UpdateItem( aEditedPoint, aPoints, aCommit, aUpdatedItems );
m_shape.SetHatchingDirty(); m_shape.SetHatchingDirty();
m_shape.UpdateHatching();
} }
private: private:

View File

@ -368,8 +368,11 @@ void PCB_SHAPE::UpdateHatching() const
RECURSE_MODE::RECURSE ); RECURSE_MODE::RECURSE );
} }
m_hatching.BooleanSubtract( holes ); if( !holes.IsEmpty() )
m_hatching.Fracture(); {
m_hatching.BooleanSubtract( holes );
m_hatching.Fracture();
}
} }
} }