kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #19337
[PATCH] portability: replace round() with KiROUND()
The round() function is C98/C++11 only, which is why there is a special
KiROUND() function that is used almost everywhere for rounding.
This collects the remaining stragglers.
---
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 12e4502..d9e9eac 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<double>( gridTick ) * worldScale );
+ int gridScreenSizeDense = KiROUND( gridSize.x * worldScale );
+ int gridScreenSizeCoarse = KiROUND( gridSize.x * static_cast<double>( 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 b10bd94..2f528a9 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 f50dc0e..b73ac0c 100644
--- a/pcbnew/tools/edit_constraints.cpp
+++ b/pcbnew/tools/edit_constraints.cpp
@@ -27,6 +27,8 @@
#include <geometry/seg.h>
+#include <common.h>
+
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 026c9c7..56efa40 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 4bed351..1275dce 100644
--- a/pcbnew/tools/pcbnew_control.cpp
+++ b/pcbnew/tools/pcbnew_control.cpp
@@ -499,8 +499,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();
--
2.1.4
Follow ups