From 1f1feb51d77e594460f63e52f6f2ce302f5f57a0 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 8 Dec 2022 03:58:36 +0300 Subject: [PATCH] Fix GetVectorSnapped45 on distances > 1 m. --- libs/kimath/include/geometry/geometry_utils.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libs/kimath/include/geometry/geometry_utils.h b/libs/kimath/include/geometry/geometry_utils.h index 7cbf4f0231..8220fcdff9 100644 --- a/libs/kimath/include/geometry/geometry_utils.h +++ b/libs/kimath/include/geometry/geometry_utils.h @@ -104,24 +104,25 @@ int GetCircleToPolyCorrection( int aMaxError ); template VECTOR2 GetVectorSnapped45( const VECTOR2& aVec, bool only45 = false ) { - auto newVec = aVec; - const VECTOR2 absVec { std::abs( aVec.x ), std::abs( aVec.y ) }; + auto newVec = aVec; + const VECTOR2 absVec{ std::abs( aVec.x ), std::abs( aVec.y ) }; - if ( !only45 && absVec.x > absVec.y * 2 ) + if( !only45 && absVec.x > VECTOR2::extended_type( absVec.y ) * 2 ) { // snap along x-axis newVec.y = 0; } - else if ( !only45 && absVec.y > absVec.x * 2 ) + else if( !only45 && absVec.y > VECTOR2::extended_type( absVec.x ) * 2 ) { // snap onto y-axis newVec.x = 0; } - else if ( absVec.x > absVec.y ) + else if( absVec.x > absVec.y ) { // snap away from x-axis towards 45 newVec.y = std::copysign( aVec.x, aVec.y ); - } else + } + else { // snap away from y-axis towards 45 newVec.x = std::copysign( aVec.y, aVec.x );