diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index f0f12b588b..4d375578fe 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -1481,13 +1481,15 @@ 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; @@ -1507,13 +1509,18 @@ void EDA_SHAPE::calcEdit( const VECTOR2I& aPosition ) // Calculate center based on start, end, and radius // // 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; + 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 ); diff --git a/eeschema/tools/ee_point_editor.cpp b/eeschema/tools/ee_point_editor.cpp index 9b4074e52c..0a029022be 100644 --- a/eeschema/tools/ee_point_editor.cpp +++ b/eeschema/tools/ee_point_editor.cpp @@ -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 }; diff --git a/libs/kimath/include/math/util.h b/libs/kimath/include/math/util.h index f5626b9ce9..40417d1949 100644 --- a/libs/kimath/include/math/util.h +++ b/libs/kimath/include/math/util.h @@ -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 ) ); } diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 2cb55ec6a5..a2a6d7b77f 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -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 };