Pcbnew: avoid integer overflow when displaying local coordinates.

Minor cleanup in code.
This commit is contained in:
jean-pierre charras 2019-02-14 10:55:57 +01:00
parent 2cbbcfd3e0
commit e6a200b09e
3 changed files with 26 additions and 33 deletions

View File

@ -222,7 +222,6 @@ void SCH_BASE_FRAME::SetTitleBlock( const TITLE_BLOCK& aTitleBlock )
void SCH_BASE_FRAME::UpdateStatusBar() void SCH_BASE_FRAME::UpdateStatusBar()
{ {
wxString line; wxString line;
int dx, dy;
BASE_SCREEN* screen = GetScreen(); BASE_SCREEN* screen = GetScreen();
if( !screen ) if( !screen )
@ -246,18 +245,18 @@ void SCH_BASE_FRAME::UpdateStatusBar()
switch( GetUserUnits() ) switch( GetUserUnits() )
{ {
case INCHES: case INCHES:
absformatter = wxT( "X %.3f Y %.3f" ); absformatter = "X %.3f Y %.3f";
locformatter = wxT( "dx %.3f dy %.3f dist %.3f" ); locformatter = "dx %.3f dy %.3f dist %.3f";
break; break;
case MILLIMETRES: case MILLIMETRES:
absformatter = wxT( "X %.2f Y %.2f" ); absformatter = "X %.2f Y %.2f";
locformatter = wxT( "dx %.2f dy %.2f dist %.2f" ); locformatter = "dx %.2f dy %.2f dist %.2f";
break; break;
case UNSCALED_UNITS: case UNSCALED_UNITS:
absformatter = wxT( "X %f Y %f" ); absformatter = "X %f Y %f";
locformatter = wxT( "dx %f dy %f dist %f" ); locformatter = "dx %f dy %f dist %f";
break; break;
case DEGREES: case DEGREES:
@ -269,8 +268,8 @@ void SCH_BASE_FRAME::UpdateStatusBar()
SetStatusText( line, 2 ); SetStatusText( line, 2 );
// Display relative coordinates: // Display relative coordinates:
dx = GetCrossHairPosition().x - screen->m_O_Curseur.x; double dx = (double)GetCrossHairPosition().x - (double)screen->m_O_Curseur.x;
dy = GetCrossHairPosition().y - screen->m_O_Curseur.y; double dy = (double)GetCrossHairPosition().y - (double)screen->m_O_Curseur.y;
dXpos = To_User_Unit( GetUserUnits(), dx ); dXpos = To_User_Unit( GetUserUnits(), dx );
dYpos = To_User_Unit( GetUserUnits(), dy ); dYpos = To_User_Unit( GetUserUnits(), dy );

View File

@ -830,10 +830,6 @@ void PCB_BASE_FRAME::UpdateStatusBar()
if( !screen ) if( !screen )
return; return;
int dx;
int dy;
double dXpos;
double dYpos;
wxString line; wxString line;
wxString locformatter; wxString locformatter;
auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions(); auto displ_opts = (PCB_DISPLAY_OPTIONS*)GetDisplayOptions();
@ -842,27 +838,25 @@ void PCB_BASE_FRAME::UpdateStatusBar()
if( displ_opts->m_DisplayPolarCood ) // display polar coordinates if( displ_opts->m_DisplayPolarCood ) // display polar coordinates
{ {
double theta, ro; double dx = (double)GetCrossHairPosition().x - (double)screen->m_O_Curseur.x;
double dy = (double)GetCrossHairPosition().y - (double)screen->m_O_Curseur.y;
dx = GetCrossHairPosition().x - screen->m_O_Curseur.x; double theta = ArcTangente( -dy, dx ) / 10;
dy = GetCrossHairPosition().y - screen->m_O_Curseur.y; double ro = hypot( dx, dy );
theta = ArcTangente( -dy, dx ) / 10;
ro = hypot( dx, dy );
wxString formatter; wxString formatter;
switch( GetUserUnits() ) switch( GetUserUnits() )
{ {
case INCHES: case INCHES:
formatter = wxT( "r %.6f theta %.1f" ); formatter = "r %.6f theta %.1f";
break; break;
case MILLIMETRES: case MILLIMETRES:
formatter = wxT( "r %.6f theta %.1f" ); formatter = "r %.6f theta %.1f";
break; break;
case UNSCALED_UNITS: case UNSCALED_UNITS:
formatter = wxT( "r %f theta %f" ); formatter = "r %f theta %f";
break; break;
case DEGREES: case DEGREES:
@ -876,8 +870,8 @@ void PCB_BASE_FRAME::UpdateStatusBar()
} }
// Display absolute coordinates: // Display absolute coordinates:
dXpos = To_User_Unit( GetUserUnits(), GetCrossHairPosition().x ); double dXpos = To_User_Unit( GetUserUnits(), GetCrossHairPosition().x );
dYpos = To_User_Unit( GetUserUnits(), GetCrossHairPosition().y ); double dYpos = To_User_Unit( GetUserUnits(), GetCrossHairPosition().y );
// The following sadly is an if Eeschema/if Pcbnew // The following sadly is an if Eeschema/if Pcbnew
wxString absformatter; wxString absformatter;
@ -885,18 +879,18 @@ void PCB_BASE_FRAME::UpdateStatusBar()
switch( GetUserUnits() ) switch( GetUserUnits() )
{ {
case INCHES: case INCHES:
absformatter = wxT( "X %.6f Y %.6f" ); absformatter = "X %.6f Y %.6f";
locformatter = wxT( "dx %.6f dy %.6f dist %.4f" ); locformatter = "dx %.6f dy %.6f dist %.4f";
break; break;
case MILLIMETRES: case MILLIMETRES:
absformatter = wxT( "X %.6f Y %.6f" ); absformatter = "X %.6f Y %.6f";
locformatter = wxT( "dx %.6f dy %.6f dist %.3f" ); locformatter = "dx %.6f dy %.6f dist %.3f";
break; break;
case UNSCALED_UNITS: case UNSCALED_UNITS:
absformatter = wxT( "X %f Y %f" ); absformatter = "X %f Y %f";
locformatter = wxT( "dx %f dy %f dist %f" ); locformatter = "dx %f dy %f dist %f";
break; break;
case DEGREES: case DEGREES:
@ -910,8 +904,8 @@ void PCB_BASE_FRAME::UpdateStatusBar()
if( !displ_opts->m_DisplayPolarCood ) // display relative cartesian coordinates if( !displ_opts->m_DisplayPolarCood ) // display relative cartesian coordinates
{ {
// Display relative coordinates: // Display relative coordinates:
dx = GetCrossHairPosition().x - screen->m_O_Curseur.x; double dx = (double)GetCrossHairPosition().x - (double)screen->m_O_Curseur.x;
dy = GetCrossHairPosition().y - screen->m_O_Curseur.y; double dy = (double)GetCrossHairPosition().y - (double)screen->m_O_Curseur.y;
dXpos = To_User_Unit( GetUserUnits(), dx ); dXpos = To_User_Unit( GetUserUnits(), dx );
dYpos = To_User_Unit( GetUserUnits(), dy ); dYpos = To_User_Unit( GetUserUnits(), dy );

View File

@ -1826,4 +1826,4 @@ PCB_LAYER_ID DRAWING_TOOL::getDrawingLayer() const
} }
const unsigned int DRAWING_TOOL::WIDTH_STEP = 100000; const unsigned int DRAWING_TOOL::WIDTH_STEP = Millimeter2iu( 0.1 );