mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-11 16:10:10 +00:00
Fixed issue where the final segment of the dashed style was not finishing properly
Fixes https://gitlab.com/kicad/code/kicad/-/issues/18335
This commit is contained in:
parent
6f3e16382e
commit
11e749ad2b
@ -170,8 +170,8 @@ void STROKE_PARAMS::Stroke( const SHAPE* aShape, LINE_STYLE aLineStyle, int aWid
|
||||
|
||||
wxASSERT( startAngle < arcEndAngle );
|
||||
|
||||
EDA_ANGLE angleIncrementInRadians = EDA_ANGLE( M_PI / ANGLE_360 );
|
||||
|
||||
EDA_ANGLE angleIncrementInRadians = EDA_ANGLE( M_PI / ANGLE_360 );
|
||||
|
||||
for( size_t i = 0; i < 10000 && startAngle < arcEndAngle; ++i )
|
||||
{
|
||||
EDA_ANGLE theta = ANGLE_360 * strokes[ i % wrapAround ] / C;
|
||||
@ -179,44 +179,26 @@ void STROKE_PARAMS::Stroke( const SHAPE* aShape, LINE_STYLE aLineStyle, int aWid
|
||||
|
||||
if( i % 2 == 0 )
|
||||
{
|
||||
// Calculate the remaining arc length from the current startAngle to the arcEndAngle
|
||||
EDA_ANGLE remainingArcLength = arcEndAngle - startAngle;
|
||||
|
||||
if( remainingArcLength < theta )
|
||||
{
|
||||
// If the remaining arc length is less than the current segment length (theta),
|
||||
// we need to adjust the segment length to fit within the remaining arc.
|
||||
|
||||
// Check if the remaining arc length is greater than the gap length (strokes[1]).
|
||||
// strokes[1] represents the gap between dashes/dots in the pattern.
|
||||
if( remainingArcLength > ( ANGLE_360 * strokes[1] / C ) )
|
||||
{
|
||||
// If the remaining arc length is greater than the gap length,
|
||||
// adjust the segment length (theta) to leave space for the final gap.
|
||||
theta = remainingArcLength - ( ANGLE_360 * strokes[1] / C );
|
||||
|
||||
// Ensure that the adjusted segment length does not exceed the arcEndAngle.
|
||||
endAngle = startAngle + theta;
|
||||
}
|
||||
else
|
||||
{
|
||||
// If the remaining arc length is less than or equal to the gap length,
|
||||
// simply set the endAngle to the arcEndAngle to complete the arc.
|
||||
endAngle = arcEndAngle;
|
||||
}
|
||||
}
|
||||
|
||||
if( aLineStyle == LINE_STYLE::DASH
|
||||
|| ( ( aLineStyle == LINE_STYLE::DASHDOT || aLineStyle == LINE_STYLE::DASHDOTDOT )
|
||||
&& ( i % wrapAround ) == 0 ) )
|
||||
if( ( ( aLineStyle == LINE_STYLE::DASHDOT || aLineStyle == LINE_STYLE::DASHDOTDOT )
|
||||
&& i % wrapAround == 0 )
|
||||
|| aLineStyle == LINE_STYLE::DASH )
|
||||
{
|
||||
for( EDA_ANGLE currentAngle = startAngle; currentAngle < endAngle;
|
||||
currentAngle += angleIncrementInRadians )
|
||||
{
|
||||
VECTOR2I a( center.x + KiROUND( r * currentAngle.Cos() ),
|
||||
center.y + KiROUND( r * currentAngle.Sin() ) );
|
||||
VECTOR2I b( center.x + KiROUND( r * ( currentAngle + angleIncrementInRadians ).Cos() ),
|
||||
center.y + KiROUND( r * ( currentAngle + angleIncrementInRadians ).Sin() ) );
|
||||
|
||||
// Calculate the next angle step, ensuring it doesn't exceed the endAngle
|
||||
EDA_ANGLE nextAngle = currentAngle + angleIncrementInRadians;
|
||||
|
||||
if( nextAngle > endAngle )
|
||||
{
|
||||
nextAngle = endAngle; // Set nextAngle to endAngle if it exceeds
|
||||
}
|
||||
|
||||
VECTOR2I b( center.x + KiROUND( r * nextAngle.Cos() ),
|
||||
center.y + KiROUND( r * nextAngle.Sin() ) );
|
||||
|
||||
aStroker( a, b ); // Draw the segment as an arc
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user