From 40ccc0bedf6f0a1e4a3141dba383b539befc56d7 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 17 Jul 2015 10:26:48 +0200 Subject: [PATCH] replace round() with KiROUND(), our function that is used almost everywhere for rounding, and detects int overflows in debug mode. --- common/gal/graphics_abstraction_layer.cpp | 16 ++++++++-------- pcbnew/dialogs/dialog_move_exact.cpp | 2 +- pcbnew/tools/edit_constraints.cpp | 4 +++- pcbnew/tools/grid_helper.cpp | 4 ++-- pcbnew/tools/pcbnew_control.cpp | 4 ++-- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/common/gal/graphics_abstraction_layer.cpp b/common/gal/graphics_abstraction_layer.cpp index 12e4502204..d9e9eac204 100644 --- a/common/gal/graphics_abstraction_layer.cpp +++ b/common/gal/graphics_abstraction_layer.cpp @@ -125,8 +125,8 @@ void GAL::DrawGrid() VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 ); VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize ); - int gridScreenSizeDense = round( gridSize.x * worldScale ); - int gridScreenSizeCoarse = round( gridSize.x * static_cast( gridTick ) * worldScale ); + int gridScreenSizeDense = KiROUND( gridSize.x * worldScale ); + int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast( gridTick ) * worldScale ); // Compute the line marker or point radius of the grid double marker = 2.0 * gridLineWidth / worldScale; @@ -136,10 +136,10 @@ void GAL::DrawGrid() if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold ) { // Compute grid variables - int gridStartX = round( worldStartPoint.x / gridSize.x ); - int gridEndX = round( worldEndPoint.x / gridSize.x ); - int gridStartY = round( worldStartPoint.y / gridSize.y ); - int gridEndY = round( worldEndPoint.y / gridSize.y ); + int gridStartX = KiROUND( worldStartPoint.x / gridSize.x ); + int gridEndX = KiROUND( worldEndPoint.x / gridSize.x ); + int gridStartY = KiROUND( worldStartPoint.y / gridSize.y ); + int gridEndY = KiROUND( worldEndPoint.y / gridSize.y ); assert( gridEndX >= gridStartX ); assert( gridEndY >= gridStartY ); @@ -231,8 +231,8 @@ void GAL::DrawGrid() VECTOR2D GAL::GetGridPoint( const VECTOR2D& aPoint ) const { - return VECTOR2D( round( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, - round( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); + return VECTOR2D( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, + KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); } const int GAL::MIN_DEPTH = -1024; diff --git a/pcbnew/dialogs/dialog_move_exact.cpp b/pcbnew/dialogs/dialog_move_exact.cpp index b10bd9466e..2f528a97b3 100644 --- a/pcbnew/dialogs/dialog_move_exact.cpp +++ b/pcbnew/dialogs/dialog_move_exact.cpp @@ -112,7 +112,7 @@ void DIALOG_MOVE_EXACT::OnPolarChanged( wxCommandEvent& event ) double r, q; ToPolarDeg( val.x, val.y, r, q ); - PutValueInLocalUnits( *m_xEntry, round( r / 10.0) * 10 ); + PutValueInLocalUnits( *m_xEntry, KiROUND( r / 10.0) * 10 ); m_yEntry->SetValue( wxString::FromDouble( q ) ); } else diff --git a/pcbnew/tools/edit_constraints.cpp b/pcbnew/tools/edit_constraints.cpp index f50dc0e596..b73ac0c5a8 100644 --- a/pcbnew/tools/edit_constraints.cpp +++ b/pcbnew/tools/edit_constraints.cpp @@ -27,6 +27,8 @@ #include +#include + void EC_VERTICAL::Apply( EDIT_POINT& aHandle ) { VECTOR2I point = aHandle.GetPosition(); @@ -50,7 +52,7 @@ void EC_45DEGREE::Apply( EDIT_POINT& aHandle ) double angle = lineVector.Angle(); // Find the closest angle, which is a multiple of 45 degrees - double newAngle = round( angle / ( M_PI / 4.0 ) ) * M_PI / 4.0; + double newAngle = KiROUND( angle / ( M_PI / 4.0 ) ) * M_PI / 4.0; VECTOR2I newLineVector = lineVector.Rotate( newAngle - angle ); aHandle.SetPosition( m_constrainer.GetPosition() + newLineVector ); diff --git a/pcbnew/tools/grid_helper.cpp b/pcbnew/tools/grid_helper.cpp index 026c9c7ab6..56efa406ca 100644 --- a/pcbnew/tools/grid_helper.cpp +++ b/pcbnew/tools/grid_helper.cpp @@ -96,8 +96,8 @@ VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const const VECTOR2D gridOffset( GetOrigin() ); const VECTOR2D gridSize( GetGrid() ); - VECTOR2I nearest( round( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, - round( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); + VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, + KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); if( !m_auxAxis ) return nearest; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 0df1769e50..8b5c3f0dfe 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -503,8 +503,8 @@ int PCBNEW_CONTROL::CursorControl( const TOOL_EVENT& aEvent ) // Handler cursor movement KIGFX::VIEW* view = getView(); newCursor = view->ToScreen( newCursor ); - newCursor.x = round( newCursor.x ); - newCursor.y = round( newCursor.y ); + newCursor.x = KiROUND( newCursor.x ); + newCursor.y = KiROUND( newCursor.y ); // Pan the screen if required const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();