replace round() with KiROUND(), our function that is used almost everywhere for rounding, and detects int overflows in debug mode.

This commit is contained in:
unknown 2015-07-17 10:26:48 +02:00 committed by jean-pierre charras
parent 3372b77b43
commit 40ccc0bedf
5 changed files with 16 additions and 14 deletions

View File

@ -125,8 +125,8 @@ void GAL::DrawGrid()
VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 ); VECTOR2D worldStartPoint = screenWorldMatrix * VECTOR2D( 0.0, 0.0 );
VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize ); VECTOR2D worldEndPoint = screenWorldMatrix * VECTOR2D( screenSize );
int gridScreenSizeDense = round( gridSize.x * worldScale ); int gridScreenSizeDense = KiROUND( gridSize.x * worldScale );
int gridScreenSizeCoarse = round( gridSize.x * static_cast<double>( gridTick ) * worldScale ); int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast<double>( gridTick ) * worldScale );
// Compute the line marker or point radius of the grid // Compute the line marker or point radius of the grid
double marker = 2.0 * gridLineWidth / worldScale; double marker = 2.0 * gridLineWidth / worldScale;
@ -136,10 +136,10 @@ void GAL::DrawGrid()
if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold ) if( std::max( gridScreenSizeDense, gridScreenSizeCoarse ) > gridDrawThreshold )
{ {
// Compute grid variables // Compute grid variables
int gridStartX = round( worldStartPoint.x / gridSize.x ); int gridStartX = KiROUND( worldStartPoint.x / gridSize.x );
int gridEndX = round( worldEndPoint.x / gridSize.x ); int gridEndX = KiROUND( worldEndPoint.x / gridSize.x );
int gridStartY = round( worldStartPoint.y / gridSize.y ); int gridStartY = KiROUND( worldStartPoint.y / gridSize.y );
int gridEndY = round( worldEndPoint.y / gridSize.y ); int gridEndY = KiROUND( worldEndPoint.y / gridSize.y );
assert( gridEndX >= gridStartX ); assert( gridEndX >= gridStartX );
assert( gridEndY >= gridStartY ); assert( gridEndY >= gridStartY );
@ -231,8 +231,8 @@ void GAL::DrawGrid()
VECTOR2D GAL::GetGridPoint( const VECTOR2D& aPoint ) const VECTOR2D GAL::GetGridPoint( const VECTOR2D& aPoint ) const
{ {
return VECTOR2D( round( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, return VECTOR2D( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
round( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
} }
const int GAL::MIN_DEPTH = -1024; const int GAL::MIN_DEPTH = -1024;

View File

@ -112,7 +112,7 @@ void DIALOG_MOVE_EXACT::OnPolarChanged( wxCommandEvent& event )
double r, q; double r, q;
ToPolarDeg( val.x, val.y, 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 ) ); m_yEntry->SetValue( wxString::FromDouble( q ) );
} }
else else

View File

@ -27,6 +27,8 @@
#include <geometry/seg.h> #include <geometry/seg.h>
#include <common.h>
void EC_VERTICAL::Apply( EDIT_POINT& aHandle ) void EC_VERTICAL::Apply( EDIT_POINT& aHandle )
{ {
VECTOR2I point = aHandle.GetPosition(); VECTOR2I point = aHandle.GetPosition();
@ -50,7 +52,7 @@ void EC_45DEGREE::Apply( EDIT_POINT& aHandle )
double angle = lineVector.Angle(); double angle = lineVector.Angle();
// Find the closest angle, which is a multiple of 45 degrees // 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 ); VECTOR2I newLineVector = lineVector.Rotate( newAngle - angle );
aHandle.SetPosition( m_constrainer.GetPosition() + newLineVector ); aHandle.SetPosition( m_constrainer.GetPosition() + newLineVector );

View File

@ -96,8 +96,8 @@ VECTOR2I GRID_HELPER::Align( const VECTOR2I& aPoint ) const
const VECTOR2D gridOffset( GetOrigin() ); const VECTOR2D gridOffset( GetOrigin() );
const VECTOR2D gridSize( GetGrid() ); const VECTOR2D gridSize( GetGrid() );
VECTOR2I nearest( round( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x, VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / gridSize.x ) * gridSize.x + gridOffset.x,
round( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y ); KiROUND( ( aPoint.y - gridOffset.y ) / gridSize.y ) * gridSize.y + gridOffset.y );
if( !m_auxAxis ) if( !m_auxAxis )
return nearest; return nearest;

View File

@ -503,8 +503,8 @@ int PCBNEW_CONTROL::CursorControl( const TOOL_EVENT& aEvent )
// Handler cursor movement // Handler cursor movement
KIGFX::VIEW* view = getView(); KIGFX::VIEW* view = getView();
newCursor = view->ToScreen( newCursor ); newCursor = view->ToScreen( newCursor );
newCursor.x = round( newCursor.x ); newCursor.x = KiROUND( newCursor.x );
newCursor.y = round( newCursor.y ); newCursor.y = KiROUND( newCursor.y );
// Pan the screen if required // Pan the screen if required
const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize(); const VECTOR2I& screenSize = view->GetGAL()->GetScreenPixelSize();