diff --git a/common/eda_shape.cpp b/common/eda_shape.cpp index a6ed0dbfb9..636add5293 100644 --- a/common/eda_shape.cpp +++ b/common/eda_shape.cpp @@ -1532,7 +1532,7 @@ 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 = m_start.Distance( m_end ); VECTOR2D m = ( m_start + m_end ) / 2; - double sqRadDiff = ( radius * radius ) - 0.25; + double sqRadDiff = ( radius * radius ) - ( l * l ) / 4.0; // Calculate 'd', the vector from the chord midpoint to the center VECTOR2D d; diff --git a/libs/kimath/include/math/vector2d.h b/libs/kimath/include/math/vector2d.h index aa1cb51864..0e697230dd 100644 --- a/libs/kimath/include/math/vector2d.h +++ b/libs/kimath/include/math/vector2d.h @@ -272,7 +272,13 @@ T VECTOR2::EuclideanNorm() const { // 45° are common in KiCad, so we can optimize the calculation if( std::abs( x ) == std::abs( y ) ) + { + if( std::is_integral::value ) + return KiROUND( std::abs( x ) * M_SQRT2 ); + return static_cast( std::abs( x ) * M_SQRT2 ); + } + if( x == 0 ) return static_cast( std::abs( y ) ); if( y == 0 ) diff --git a/pcbnew/tools/pcb_point_editor.cpp b/pcbnew/tools/pcb_point_editor.cpp index 5fd33f48b4..89ca90f681 100644 --- a/pcbnew/tools/pcb_point_editor.cpp +++ b/pcbnew/tools/pcb_point_editor.cpp @@ -1473,7 +1473,7 @@ void PCB_POINT_EDITOR::updateItem( BOARD_COMMIT* aCommit ) case PAD_SHAPE::CIRCLE: { VECTOR2I end = m_editPoints->Point( 0 ).GetPosition(); - int diameter = ( end - pad->GetPosition() ).SquaredEuclideanNorm(); + int diameter = 2 * ( end - pad->GetPosition() ).EuclideanNorm(); pad->SetSize( VECTOR2I( diameter, diameter ) ); break;