Fix arc editing bugs when endpoints match.
Fixes https://gitlab.com/kicad/code/kicad/-/issues/16532
This commit is contained in:
parent
5bd620d8f9
commit
f99505e190
|
@ -1481,14 +1481,16 @@ void EDA_SHAPE::calcEdit( const VECTOR2I& aPosition )
|
|||
m_end = aPosition;
|
||||
|
||||
v = m_start - m_end;
|
||||
|
||||
double chordAfter = sq( v.x ) + sq( v.y );
|
||||
double ratio = chordAfter / chordBefore;
|
||||
double ratio = 0.0;
|
||||
|
||||
if( chordBefore > 0 )
|
||||
ratio = chordAfter / chordBefore;
|
||||
|
||||
if( ratio != 0 )
|
||||
{
|
||||
radius = std::max( sqrt( sq( radius ) * ratio ), sqrt( chordAfter ) / 2 );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
@ -1509,11 +1511,16 @@ void EDA_SHAPE::calcEdit( const VECTOR2I& aPosition )
|
|||
// Let 'l' be the length of the chord and 'm' the middle point of the chord
|
||||
double l = GetLineLength( m_start, m_end );
|
||||
VECTOR2D m = ( m_start + m_end ) / 2;
|
||||
double sqRadDiff = sq( radius ) - sq( l / 2 );
|
||||
|
||||
// Calculate 'd', the vector from the chord midpoint to the center
|
||||
VECTOR2D d;
|
||||
d.x = sqrt( sq( radius ) - sq( l / 2 ) ) * ( m_start.y - m_end.y ) / l;
|
||||
d.y = sqrt( sq( radius ) - sq( l / 2 ) ) * ( m_end.x - m_start.x ) / l;
|
||||
|
||||
if( l > 0 && sqRadDiff >= 0 )
|
||||
{
|
||||
d.x = sqrt( sqRadDiff ) * ( m_start.y - m_end.y ) / l;
|
||||
d.y = sqrt( sqRadDiff ) * ( m_end.x - m_start.x ) / l;
|
||||
}
|
||||
|
||||
VECTOR2I c1 = KiROUND( m + d );
|
||||
VECTOR2I c2 = KiROUND( m - d );
|
||||
|
|
|
@ -49,7 +49,7 @@ using namespace std::placeholders;
|
|||
// Few constants to avoid using bare numbers for point indices
|
||||
enum ARC_POINTS
|
||||
{
|
||||
ARC_CENTER, ARC_START, ARC_END
|
||||
ARC_START, ARC_END, ARC_CENTER
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -102,6 +102,12 @@ constexpr ret_type KiROUND( fp_type v )
|
|||
else
|
||||
return 0;
|
||||
}
|
||||
else if( std::isnan( v ) )
|
||||
{
|
||||
kimathLogOverflow( double( v ), typeid( ret_type ).name() );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ret_type( max_ret( ret ) );
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ enum RECT_LINES
|
|||
|
||||
enum ARC_POINTS
|
||||
{
|
||||
ARC_CENTER, ARC_START, ARC_MID, ARC_END
|
||||
ARC_START, ARC_MID, ARC_END, ARC_CENTER
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue