kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #22688
[PATCH 03/11] Clarify atan2 overloads
In the C++ standard, this function is only defined for floating point
types, and integers cannot be implicitly converted. Using explicit
conversions avoids a GCC specific extension to the standard library.
---
common/trigo.cpp | 2 +-
gerbview/gerbview_frame.cpp | 2 +-
include/math/vector2d.h | 2 +-
pcbnew/class_dimension.cpp | 2 +-
pcbnew/class_dimension.h | 2 +-
pcbnew/class_drawsegment.cpp | 7 ++++---
pcbnew/class_pad_draw_functions.cpp | 4 ++--
7 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/common/trigo.cpp b/common/trigo.cpp
index 4f29125..b6be203 100644
--- a/common/trigo.cpp
+++ b/common/trigo.cpp
@@ -310,7 +310,7 @@ double ArcTangente( int dy, int dx )
}
// Of course dy and dx are treated as double
- return RAD2DECIDEG( atan2( dy, dx ) );
+ return RAD2DECIDEG( atan2( (double) dy, (double) dx ) );
}
diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp
index 68ddadc..4a5852b 100644
--- a/gerbview/gerbview_frame.cpp
+++ b/gerbview/gerbview_frame.cpp
@@ -755,7 +755,7 @@ void GERBVIEW_FRAME::UpdateStatusBar()
dy = GetCrossHairPosition().y - screen->m_O_Curseur.y;
// atan2 in the 0,0 case returns 0
- theta = RAD2DEG( atan2( -dy, dx ) );
+ theta = RAD2DEG( atan2( (double) -dy, (double) dx ) );
ro = hypot( dx, dy );
wxString formatter;
diff --git a/include/math/vector2d.h b/include/math/vector2d.h
index bba2a4a..764534a 100644
--- a/include/math/vector2d.h
+++ b/include/math/vector2d.h
@@ -298,7 +298,7 @@ typename VECTOR2<T>::extended_type VECTOR2<T>::SquaredEuclideanNorm() const
template <class T>
double VECTOR2<T>::Angle() const
{
- return atan2( y, x );
+ return atan2( (double) y, (double) x );
}
diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp
index 0367c14..262ae7a 100644
--- a/pcbnew/class_dimension.cpp
+++ b/pcbnew/class_dimension.cpp
@@ -252,7 +252,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
// Calculate dimension value
measure = KiROUND( hypot( deltax, deltay ) );
- angle = atan2( deltay, deltax );
+ angle = atan2( (double)deltay, (double)deltax );
// Calculation of parameters X and Y dimensions of the arrows and lines.
hx = hy = ii;
diff --git a/pcbnew/class_dimension.h b/pcbnew/class_dimension.h
index d12a597..93e5e8b 100644
--- a/pcbnew/class_dimension.h
+++ b/pcbnew/class_dimension.h
@@ -166,7 +166,7 @@ public:
{
wxPoint delta( m_featureLineDO - m_featureLineGO );
- return atan2( delta.y, delta.x );
+ return atan2( (double)delta.y, (double)delta.x );
}
/**
diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp
index bd1ac73..c9ceb6f 100644
--- a/pcbnew/class_drawsegment.cpp
+++ b/pcbnew/class_drawsegment.cpp
@@ -391,8 +391,8 @@ void DRAWSEGMENT::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Length" ), msg, DARKGREEN ) );
// angle counter-clockwise from 3'o-clock
- const double deg = RAD2DEG( atan2( m_Start.y - m_End.y,
- m_End.x - m_Start.x ) );
+ const double deg = RAD2DEG( atan2( (double)( m_Start.y - m_End.y ),
+ (double)( m_End.x - m_Start.x ) ) );
msg.Printf( wxT( "%.1f" ), deg );
aList.push_back( MSG_PANEL_ITEM( _( "Angle" ), msg, DARKGREEN ) );
}
@@ -564,7 +564,8 @@ bool DRAWSEGMENT::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy
case S_ARC:
radius = hypot( (double)( GetEnd().x - GetStart().x ),
(double)( GetEnd().y - GetStart().y ) );
- theta = std::atan2( GetEnd().y - GetStart().y , GetEnd().x - GetStart().x );
+ theta = std::atan2( (double)( GetEnd().y - GetStart().y ),
+ (double)( GetEnd().x - GetStart().x ) );
//Approximate the arc with two lines. This should be accurate enough for selection.
p1.x = radius * std::cos( theta + M_PI/4 ) + GetStart().x;
diff --git a/pcbnew/class_pad_draw_functions.cpp b/pcbnew/class_pad_draw_functions.cpp
index f26bc00..d3e5cab 100644
--- a/pcbnew/class_pad_draw_functions.cpp
+++ b/pcbnew/class_pad_draw_functions.cpp
@@ -690,7 +690,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue,
if( delta.y ) // lower and upper segment is horizontal
{
// Calculate angle of left (or right) segment with vertical axis
- angle = atan2( m_DeltaSize.y, m_Size.y );
+ angle = atan2( (double) m_DeltaSize.y, (double) m_Size.y );
// left and right sides are moved by aInflateValue.x in their perpendicular direction
// We must calculate the corresponding displacement on the horizontal axis
@@ -706,7 +706,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue,
else if( delta.x ) // left and right segment is vertical
{
// Calculate angle of lower (or upper) segment with horizontal axis
- angle = atan2( m_DeltaSize.x, m_Size.x );
+ angle = atan2( (double) m_DeltaSize.x, (double) m_Size.x );
// lower and upper sides are moved by aInflateValue.x in their perpendicular direction
// We must calculate the corresponding displacement on the vertical axis
Follow ups
References