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,13 +1481,15 @@ void EDA_SHAPE::calcEdit( const VECTOR2I& aPosition )
|
||||||
m_end = aPosition;
|
m_end = aPosition;
|
||||||
|
|
||||||
v = m_start - m_end;
|
v = m_start - m_end;
|
||||||
|
|
||||||
double chordAfter = sq( v.x ) + sq( v.y );
|
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 )
|
if( ratio != 0 )
|
||||||
{
|
|
||||||
radius = std::max( sqrt( sq( radius ) * ratio ), sqrt( chordAfter ) / 2 );
|
radius = std::max( sqrt( sq( radius ) * ratio ), sqrt( chordAfter ) / 2 );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1507,13 +1509,18 @@ void EDA_SHAPE::calcEdit( const VECTOR2I& aPosition )
|
||||||
// Calculate center based on start, end, and radius
|
// Calculate center based on start, end, and radius
|
||||||
//
|
//
|
||||||
// Let 'l' be the length of the chord and 'm' the middle point of the chord
|
// Let 'l' be the length of the chord and 'm' the middle point of the chord
|
||||||
double l = GetLineLength( m_start, m_end );
|
double l = GetLineLength( m_start, m_end );
|
||||||
VECTOR2D m = ( m_start + m_end ) / 2;
|
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
|
// Calculate 'd', the vector from the chord midpoint to the center
|
||||||
VECTOR2D d;
|
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 c1 = KiROUND( m + d );
|
||||||
VECTOR2I c2 = 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
|
// Few constants to avoid using bare numbers for point indices
|
||||||
enum ARC_POINTS
|
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
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else if( std::isnan( v ) )
|
||||||
|
{
|
||||||
|
kimathLogOverflow( double( v ), typeid( ret_type ).name() );
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return ret_type( max_ret( ret ) );
|
return ret_type( max_ret( ret ) );
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ enum RECT_LINES
|
||||||
|
|
||||||
enum ARC_POINTS
|
enum ARC_POINTS
|
||||||
{
|
{
|
||||||
ARC_CENTER, ARC_START, ARC_MID, ARC_END
|
ARC_START, ARC_MID, ARC_END, ARC_CENTER
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue