diff --git a/common/class_plotter.cpp b/common/class_plotter.cpp index 4aa13be8f8..7a64815945 100644 --- a/common/class_plotter.cpp +++ b/common/class_plotter.cpp @@ -387,7 +387,7 @@ void PLOTTER::segmentAsOval( const wxPoint& start, const wxPoint& end, int width else if( size.x == 0 ) orient = 900; else - orient = -(int) ( RAD2DEG( atan2( (double)size.y, (double)size.x ) ) * 10.0 ); + orient = -ArcTangente( size.y, size.x ); size.x = KiROUND( hypot( size.x, size.y ) ) + width; size.y = width; @@ -407,9 +407,7 @@ void PLOTTER::sketchOval( const wxPoint& pos, const wxSize& aSize, int orient, if( size.x > size.y ) { EXCHG( size.x, size.y ); - orient += 900; - if( orient >= 3600 ) - orient -= 3600; + orient = AddAngles( orient, 900 ); } deltaxy = size.y - size.x; /* distance between centers of the oval */ diff --git a/common/common_plotDXF_functions.cpp b/common/common_plotDXF_functions.cpp index 2b878b3295..0001f88110 100644 --- a/common/common_plotDXF_functions.cpp +++ b/common/common_plotDXF_functions.cpp @@ -423,9 +423,7 @@ void DXF_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int ori if( size.x > size.y ) { EXCHG( size.x, size.y ); - orient += 900; - if( orient >= 3600 ) - orient -= 3600; + orient = AddAngles( orient, 900 ); } sketchOval( pos, size, orient, -1 ); } diff --git a/common/common_plotGERBER_functions.cpp b/common/common_plotGERBER_functions.cpp index 3f34847429..ed15f1d507 100644 --- a/common/common_plotGERBER_functions.cpp +++ b/common/common_plotGERBER_functions.cpp @@ -287,12 +287,12 @@ void GERBER_PLOTTER::Arc( const wxPoint& aCenter, int aStAngle, int aEndAngle, { wxASSERT( outputFile ); wxPoint start, end; - start.x = aCenter.x + KiROUND( aRadius*cos( DEG2RAD( aStAngle/10.0 ) ) ); - start.y = aCenter.y - KiROUND( aRadius*sin( DEG2RAD( aStAngle/10.0 ) ) ); + start.x = aCenter.x + KiROUND( cosdecideg( aRadius, aStAngle ) ); + start.y = aCenter.y - KiROUND( sindecideg( aRadius, aStAngle ) ); SetCurrentLineWidth( aWidth ); MoveTo( start ); - end.x = aCenter.x + KiROUND( aRadius*cos( DEG2RAD( aEndAngle/10.0 ) ) ); - end.y = aCenter.y - KiROUND( aRadius*sin( DEG2RAD( aEndAngle/10.0 ) ) ); + end.x = aCenter.x + KiROUND( cosdecideg( aRadius, aEndAngle ) ); + end.y = aCenter.y - KiROUND( sindecideg( aRadius, aEndAngle ) ); DPOINT devEnd = userToDeviceCoordinates( end ); DPOINT devCenter = userToDeviceCoordinates( aCenter ) - userToDeviceCoordinates( start ); diff --git a/common/common_plotHPGL_functions.cpp b/common/common_plotHPGL_functions.cpp index 1c8b39742d..223b900679 100644 --- a/common/common_plotHPGL_functions.cpp +++ b/common/common_plotHPGL_functions.cpp @@ -401,8 +401,8 @@ void HPGL_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int ra // Calculate start point, wxPoint cmap; - cmap.x = int( centre.x + ( radius * cos( DEG2RAD( StAngle / 10.0 ) ) ) ); - cmap.y = int( centre.y - ( radius * sin( DEG2RAD( StAngle / 10.0 ) ) ) ); + cmap.x = centre.x + KiROUND( cosdecideg( radius, StAngle ) ); + cmap.y = centre.y - KiROUND( sindecideg( radius, StAngle ) ); DPOINT cmap_dev = userToDeviceCoordinates( cmap ); fprintf( outputFile, @@ -431,10 +431,8 @@ void HPGL_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int or */ if( size.x > size.y ) { - EXCHG( size.x, size.y ); orient += 900; - - if( orient >= 3600 ) - orient -= 3600; + EXCHG( size.x, size.y ); + orient = AddAngles( orient, 900 ); } deltaxy = size.y - size.x; // distance between centers of the oval diff --git a/common/common_plotPDF_functions.cpp b/common/common_plotPDF_functions.cpp index bee8eda74a..d48b716da1 100644 --- a/common/common_plotPDF_functions.cpp +++ b/common/common_plotPDF_functions.cpp @@ -219,23 +219,20 @@ void PDF_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int rad SetCurrentLineWidth( width ); // Usual trig arc plotting routine... - double alpha = DEG2RAD( StAngle / 10.0 ); - start.x = centre.x + (int) ( radius * cos( -alpha ) ); - start.y = centre.y + (int) ( radius * sin( -alpha ) ); + start.x = centre.x + KiROUND( cosdecideg( radius, -StAngle ) ); + start.y = centre.y + KiROUND( sindecideg( radius, -StAngle ) ); DPOINT pos_dev = userToDeviceCoordinates( start ); fprintf( workFile, "%g %g m ", pos_dev.x, pos_dev.y ); for( int ii = StAngle + delta; ii < EndAngle; ii += delta ) { - alpha = DEG2RAD( ii / 10.0 ); - end.x = centre.x + (int) ( radius * cos( -alpha ) ); - end.y = centre.y + (int) ( radius * sin( -alpha ) ); + end.x = centre.x + KiROUND( cosdecideg( radius, -ii ) ); + end.y = centre.y + KiROUND( sindecideg( radius, -ii ) ); pos_dev = userToDeviceCoordinates( end ); fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y ); } - alpha = DEG2RAD( EndAngle / 10.0 ); - end.x = centre.x + (int) ( radius * cos( -alpha ) ); - end.y = centre.y + (int) ( radius * sin( -alpha ) ); + end.x = centre.x + KiROUND( cosdecideg( radius, -EndAngle ) ); + end.y = centre.y + KiROUND( sindecideg( radius, -EndAngle ) ); pos_dev = userToDeviceCoordinates( end ); fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y ); diff --git a/common/common_plotPS_functions.cpp b/common/common_plotPS_functions.cpp index 43a8a27a90..c94a2f5af8 100644 --- a/common/common_plotPS_functions.cpp +++ b/common/common_plotPS_functions.cpp @@ -75,9 +75,7 @@ void PSLIKE_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int if( size.x > size.y ) { EXCHG( size.x, size.y ); - orient += 900; - if( orient >= 3600 ) - orient -= 3600; + orient = AddAngles( orient, 900 ); } delta = size.y - size.x; @@ -345,11 +343,6 @@ void PSLIKE_PLOTTER::computeTextParameters( const wxPoint& aPos, double *ctm_f, double *heightFactor ) { - // These are for the rotation matrix - double alpha = DEG2RAD( aOrient / 10.0 ); - double sinalpha = sin( alpha ); - double cosalpha = cos( alpha ); - // Compute the starting position (compensated for alignment) wxPoint start_pos = aPos; @@ -399,6 +392,10 @@ void PSLIKE_PLOTTER::computeTextParameters( const wxPoint& aPos, *wideningFactor = sz_dev.y / sz_dev.x; // The CTM transformation matrix + double alpha = DECIDEG2RAD( aOrient ); + double sinalpha = sin( alpha ); + double cosalpha = cos( alpha ); + *ctm_a = cosalpha; *ctm_b = sinalpha; *ctm_c = -sinalpha; diff --git a/common/common_plotSVG_functions.cpp b/common/common_plotSVG_functions.cpp index d5a039e441..e6544489fd 100644 --- a/common/common_plotSVG_functions.cpp +++ b/common/common_plotSVG_functions.cpp @@ -361,12 +361,12 @@ void SVG_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int rad start += centre_dev; end += centre_dev; - double theta1 = StAngle * M_PI / 1800.0; + double theta1 = DECIDEG2RAD( StAngle ); if( theta1 < 0 ) theta1 = theta1 + M_PI * 2; - double theta2 = EndAngle * M_PI / 1800.0; + double theta2 = DECIDEG2RAD( EndAngle ); if( theta2 < 0 ) theta2 = theta2 + M_PI * 2; diff --git a/common/trigo.cpp b/common/trigo.cpp index 44d0c17434..160458eeb7 100644 --- a/common/trigo.cpp +++ b/common/trigo.cpp @@ -199,7 +199,8 @@ double ArcTangente( int dy, int dx ) return 1800 - 450; } - return atan2( dy, dx ) / M_PI * 1800; + // Of course dy and dx are treated as double + return RAD2DECIDEG( atan2( dy, dx ) ); } @@ -232,7 +233,7 @@ void RotatePoint( int* pX, int* pY, double angle ) } else { - double fangle = DEG2RAD( angle / 10.0 ); + double fangle = DECIDEG2RAD( angle ); double sinus = sin( fangle ); double cosinus = cos( fangle ); double fpx = (*pY * sinus ) + (*pX * cosinus ); @@ -313,7 +314,7 @@ void RotatePoint( double* pX, double* pY, double angle ) } else { - double fangle = DEG2RAD( angle / 10.0 ); + double fangle = DECIDEG2RAD( angle ); double sinus = sin( fangle ); double cosinus = cos( fangle ); diff --git a/eeschema/database.cpp b/eeschema/database.cpp index 6aca6f8793..1fc1802311 100644 --- a/eeschema/database.cpp +++ b/eeschema/database.cpp @@ -7,7 +7,7 @@ #include "eda_doc.h" #include "kicad_string.h" #include "wxstruct.h" - +#include #include "protos.h" #include "class_library.h" #include "dialog_helpers.h" diff --git a/eeschema/transform.cpp b/eeschema/transform.cpp index 2f8b0571d1..6c40f5906c 100644 --- a/eeschema/transform.cpp +++ b/eeschema/transform.cpp @@ -74,15 +74,15 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const *aAngle2 += 1; } - x = cos( *aAngle1 * M_PI / 1800.0 ); - y = sin( *aAngle1 * M_PI / 1800.0 ); + x = cos( DECIDEG2RAD( *aAngle1 ) ); + y = sin( DECIDEG2RAD( *aAngle1 ) ); t = x * x1 + y * y1; y = x * x2 + y * y2; x = t; *aAngle1 = KiROUND( ArcTangente( y, x ) ); - x = cos( *aAngle2 * M_PI / 1800.0 ); - y = sin( *aAngle2 * M_PI / 1800.0 ); + x = cos( DECIDEG2RAD( *aAngle2 ) ); + y = sin( DECIDEG2RAD( *aAngle2 ) ); t = x * x1 + y * y1; y = x * x2 + y * y2; x = t; diff --git a/gerbview/class_aperture_macro.cpp b/gerbview/class_aperture_macro.cpp index b02f488e74..450b9458fc 100644 --- a/gerbview/class_aperture_macro.cpp +++ b/gerbview/class_aperture_macro.cpp @@ -176,8 +176,8 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, ConvertShapeToPolygon( aParent, polybuffer ); // shape rotation: - rotation = KiROUND( params[6].GetValue( tool ) * 10.0 ); - if( rotation ) + rotation = params[6].GetValue( tool ) * 10.0; + if( rotation != 0) { for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) RotatePoint( &polybuffer[ii], -rotation ); @@ -205,8 +205,8 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, ConvertShapeToPolygon( aParent, polybuffer ); // shape rotation: - rotation = KiROUND( params[5].GetValue( tool ) * 10.0 ); - if( rotation ) + rotation = params[5].GetValue( tool ) * 10.0; + if( rotation != 0 ) { for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) RotatePoint( &polybuffer[ii], -rotation ); @@ -234,8 +234,8 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, ConvertShapeToPolygon( aParent, polybuffer ); // shape rotation: - rotation = KiROUND( params[5].GetValue( tool ) * 10.0 ); - if( rotation ) + rotation = params[5].GetValue( tool ) * 10.0; + if( rotation != 0) { for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) RotatePoint( &polybuffer[ii], -rotation ); @@ -264,7 +264,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, ConvertShapeToPolygon( aParent, polybuffer ); // shape rotation: - rotation = KiROUND( params[5].GetValue( tool ) * 10.0 ); + rotation = params[5].GetValue( tool ) * 10.0; // Because a thermal shape has 4 identical sub-shapes, only one is created in polybuffer. // We must draw 4 sub-shapes rotated by 90 deg @@ -329,7 +329,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, // Draw the cross: ConvertShapeToPolygon( aParent, polybuffer ); - rotation = KiROUND( params[8].GetValue( tool ) * 10.0 ); + rotation = params[8].GetValue( tool ) * 10.0; for( unsigned ii = 0; ii < polybuffer.size(); ii++ ) { // shape rotation: @@ -352,7 +352,7 @@ void AM_PRIMITIVE::DrawBasicShape( GERBER_DRAW_ITEM* aParent, * type is not stored in parameters list, so the first parameter is exposure */ int numPoints = (int) params[1].GetValue( tool ); - rotation = KiROUND( params[numPoints * 2 + 4].GetValue( tool ) * 10.0 ); + rotation = params[numPoints * 2 + 4].GetValue( tool ) * 10.0; wxPoint pos; // Read points. numPoints does not include the starting point, so add 1. for( int i = 0; i 0) wxPoint pos, startpos; @@ -537,7 +536,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent, // outer arc startpos.x = outerRadius; startpos.y = 0; - angle_start = KiROUND( asin( (double) halfthickness / outerRadius ) * 1800 / M_PI ); + angle_start = RAD2DECIDEG( asin( (double) halfthickness / outerRadius ) ); angle_end = 900 - angle_start; // First point, near Y axis, outer arc diff --git a/gerbview/class_gerber_draw_item.cpp b/gerbview/class_gerber_draw_item.cpp index 354f5ba423..9def8a41e5 100644 --- a/gerbview/class_gerber_draw_item.cpp +++ b/gerbview/class_gerber_draw_item.cpp @@ -115,7 +115,7 @@ wxPoint GERBER_DRAW_ITEM::GetABPosition( const wxPoint& aXYPosition ) const abPos += m_layerOffset + m_imageParams->m_ImageOffset; abPos.x = KiROUND( abPos.x * m_drawScale.x ); abPos.y = KiROUND( abPos.y * m_drawScale.y ); - int rotation = KiROUND(m_lyrRotation*10) + (m_imageParams->m_ImageRotation*10); + int rotation = m_lyrRotation * 10 + m_imageParams->m_ImageRotation * 10; if( rotation ) RotatePoint( &abPos, -rotation ); @@ -142,7 +142,7 @@ wxPoint GERBER_DRAW_ITEM::GetXYPosition( const wxPoint& aABPosition ) if( !m_mirrorB ) NEGATE( xyPos.y ); - int rotation = KiROUND(m_lyrRotation*10) + (m_imageParams->m_ImageRotation*10); + int rotation = m_lyrRotation * 10 + m_imageParams->m_ImageRotation * 10; if( rotation ) RotatePoint( &xyPos, rotation ); diff --git a/gerbview/export_to_pcbnew.cpp b/gerbview/export_to_pcbnew.cpp index c7b0921997..e7087aad40 100644 --- a/gerbview/export_to_pcbnew.cpp +++ b/gerbview/export_to_pcbnew.cpp @@ -247,7 +247,7 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LA (double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) ); shape = ARC_SHAPE; - angle = KiROUND( (a - b) / M_PI * 1800.0 ); + angle = KiROUND( RAD2DECIDEG(a - b) ); seg_start = aGbrItem->m_ArcCentre; if( angle < 0 ) @@ -333,7 +333,7 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, seg_start = curr_start; wxPoint curr_end = start; RotatePoint( &curr_end, aGbrItem->m_ArcCentre, - -(int) (DELTA_ANGLE * ii * 1800 / M_PI) ); + -RAD2DECIDEG( DELTA_ANGLE * ii ) ); seg_end = curr_end; // Reverse Y axis: NEGATE( seg_start.y ); diff --git a/gerbview/gerbview_frame.cpp b/gerbview/gerbview_frame.cpp index 67792f8ce0..7585a1bf1b 100644 --- a/gerbview/gerbview_frame.cpp +++ b/gerbview/gerbview_frame.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/include/eda_text.h b/include/eda_text.h index 3ceb8da49e..202f9582d3 100644 --- a/include/eda_text.h +++ b/include/eda_text.h @@ -30,7 +30,7 @@ #ifndef EDA_TEXT_H_ #define EDA_TEXT_H_ -#include // NORMALIZE_ANGLE_POS( angle ); +#include // NORMALIZE_ANGLE_POS( angle ); #include // wxStringSplit #include // EDA_DRAW_MODE_T #include // EDA_RECT diff --git a/include/macros.h b/include/macros.h index eb0576ec4e..35634311c8 100644 --- a/include/macros.h +++ b/include/macros.h @@ -63,56 +63,10 @@ template inline void NEGATE( T &x ) { x = -x; } /// # of elements in an array #define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t -inline double DEG2RAD( double deg ) { return deg * M_PI / 180.0; } -inline double RAD2DEG( double rad ) { return rad * 180.0 / M_PI; } - -/// Normalize angle to be in the -360.0 .. 360.0: -template inline void NORMALIZE_ANGLE_360( T& Angle ) -{ - while( Angle < -3600 ) - Angle += 3600; - while( Angle > 3600 ) - Angle -= 3600; -} - -/// Normalize angle to be in the 0.0 .. 360.0 range: -template inline void NORMALIZE_ANGLE_POS( T& Angle ) -{ - while( Angle < 0 ) - Angle += 3600; - while( Angle >= 3600 ) - Angle -= 3600; -} - -template inline void NEGATE_AND_NORMALIZE_ANGLE_POS( T& Angle ) -{ - Angle = -Angle; - while( Angle < 0 ) - Angle += 3600; - while( Angle >= 3600 ) - Angle -= 3600; -} - -/// Normalize angle to be in the -90.0 .. 90.0 range -template inline void NORMALIZE_ANGLE_90( T& Angle ) -{ - while( Angle < -900 ) - Angle += 1800; - while( Angle > 900 ) - Angle -= 1800; -} - -/// Normalize angle to be in the -180.0 .. 180.0 range -template inline void NORMALIZE_ANGLE_180( T& Angle ) -{ - while( Angle <= -1800 ) - Angle += 3600; - while( Angle > 1800 ) - Angle -= 3600; -} - -/// Exchange two values; std::swap works only with arguments of the -// same type; here the compiler will figure out what to do (I hope) +/// Exchange two values +// std::swap works only with arguments of the same type (which is saner); +// here the compiler will figure out what to do (I hope to get rid of +// this soon or late) template inline void EXCHG( T& a, T2& b ) { T temp = a; diff --git a/include/trigo.h b/include/trigo.h index afffcf5b13..8d99ef56bc 100644 --- a/include/trigo.h +++ b/include/trigo.h @@ -155,4 +155,88 @@ inline double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB ) aPointA.y - aPointB.y ); } +// These are the usual degrees <-> radians conversion routines +inline double DEG2RAD( double deg ) { return deg * M_PI / 180.0; } +inline double RAD2DEG( double rad ) { return rad * 180.0 / M_PI; } + +// These are the same *but* work with the internal 'decidegrees' unit +inline double DECIDEG2RAD( double deg ) { return deg * M_PI / 1800.0; } +inline double RAD2DECIDEG( double rad ) { return rad * 1800.0 / M_PI; } + +/* These are templated over T (and not simply double) because eeschema + is still using int for angles in some place */ + +/// Normalize angle to be in the -360.0 .. 360.0: +template inline void NORMALIZE_ANGLE_360( T &Angle ) +{ + while( Angle < -3600 ) + Angle += 3600; + while( Angle > 3600 ) + Angle -= 3600; +} + +/// Normalize angle to be in the 0.0 .. 360.0 range: +template inline void NORMALIZE_ANGLE_POS( T &Angle ) +{ + while( Angle < 0 ) + Angle += 3600; + while( Angle >= 3600 ) + Angle -= 3600; +} + +/// Add two angles (keeping the result normalized). T2 is here +// because most of the time it's an int (and templates don't promote in +// that way) +template inline T AddAngles( T a1, T2 a2 ) +{ + a1 += a2; + NORMALIZE_ANGLE_POS( a1 ); + return a1; +} + +template inline void NEGATE_AND_NORMALIZE_ANGLE_POS( T &Angle ) +{ + Angle = -Angle; + while( Angle < 0 ) + Angle += 3600; + while( Angle >= 3600 ) + Angle -= 3600; +} + +/// Normalize angle to be in the -90.0 .. 90.0 range +template inline void NORMALIZE_ANGLE_90( T &Angle ) +{ + while( Angle < -900 ) + Angle += 1800; + while( Angle > 900 ) + Angle -= 1800; +} + +/// Normalize angle to be in the -180.0 .. 180.0 range +template inline void NORMALIZE_ANGLE_180( T &Angle ) +{ + while( Angle <= -1800 ) + Angle += 3600; + while( Angle > 1800 ) + Angle -= 3600; +} + +/** + * Circle generation utility: computes r * sin(a) + * Where a is in decidegrees, not in radians. + */ +inline double sindecideg( double r, double a ) +{ + return r * sin( DECIDEG2RAD( a ) ); +} + +/** + * Circle generation utility: computes r * cos(a) + * Where a is in decidegrees, not in radians. + */ +inline double cosdecideg( double r, double a ) +{ + return r * cos( DECIDEG2RAD( a ) ); +} + #endif diff --git a/pcbnew/autorouter/autorout.h b/pcbnew/autorouter/autorout.h index b1c4f1ab84..7a5ba1b0ab 100644 --- a/pcbnew/autorouter/autorout.h +++ b/pcbnew/autorouter/autorout.h @@ -209,7 +209,8 @@ void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, /* Same as above, but the rectangle is inclined angle angle. */ void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, - int angle, LAYER_MSK masque_layer, int color, int op_logic ); + int angle, LAYER_MSK masque_layer, + int color, int op_logic ); /* QUEUE.CPP */ void FreeQueue(); diff --git a/pcbnew/autorouter/graphpcb.cpp b/pcbnew/autorouter/graphpcb.cpp index 06e93f94e7..69d4408cd0 100644 --- a/pcbnew/autorouter/graphpcb.cpp +++ b/pcbnew/autorouter/graphpcb.cpp @@ -776,8 +776,8 @@ void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, for( ii = 1; ii < nb_segm; ii++ ) { angle = (3600 * ii) / nb_segm; - x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) ); - y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) ); + x1 = KiROUND( cosdecideg( radius, angle ) ); + y1 = KiROUND( sindecideg( radius, angle ) ); DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic ); x0 = x1; y0 = y1; @@ -827,8 +827,8 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, NORMALIZE_ANGLE_POS( angle ); - x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) ); - y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) ); + x1 = KiROUND( cosdecideg( radius, angle ) ); + y1 = KiROUND( cosdecideg( radius, angle ) ); DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic ); x0 = x1; y0 = y1; diff --git a/pcbnew/board_items_to_polygon_shape_transform.cpp b/pcbnew/board_items_to_polygon_shape_transform.cpp index 10636c5055..102df1fdfa 100644 --- a/pcbnew/board_items_to_polygon_shape_transform.cpp +++ b/pcbnew/board_items_to_polygon_shape_transform.cpp @@ -144,7 +144,7 @@ void MODULE::TransformGraphicShapesWithClearanceToPolygonSet( default: D( printf( "Error: Shape %d not implemented!\n", - ((EDGE_MODULE*) item)->m_Shape ); ) + ((EDGE_MODULE*) item)->GetShape() ); ) break; } break; @@ -828,7 +828,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, wxPoint intpoint = corner; intpoint.y -= aThermalGap / 4; corners_buffer.push_back( intpoint + shape_offset ); - RotatePoint( &corner, 90 ); + RotatePoint( &corner, 90 ); // 9 degrees of thermal fillet } else { @@ -850,7 +850,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, corner_end.x = (int) sqrt( ( (double) outer_radius * outer_radius ) - ( (double) corner_end.y * corner_end.y ) ); - RotatePoint( &corner_end, -90 ); + RotatePoint( &corner_end, -90 ); // 9 degrees of thermal fillet // calculate intermediate arc points till limit is reached while( (corner.y > corner_end.y) && (corner.x < corner_end.x) ) @@ -878,10 +878,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, } aCornerBuffer.back().end_contour = true; - angle += 1800; // this is calculate hole 3 - - if( angle >= 3600 ) - angle -= 3600; + angle = AddAngles( angle, 1800 ); // this is calculate hole 3 } // Create holes, that are the mirrored from the previous holes @@ -906,10 +903,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, } aCornerBuffer.back().end_contour = true; - angle += 1800; - - if( angle >= 3600 ) - angle -= 3600; + angle = AddAngles( angle, 1800 ); } } break; @@ -982,10 +976,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, } aCornerBuffer.back().end_contour = true; - angle += 1800; // this is calculate hole 3 - - if( angle >= 3600 ) - angle -= 3600; + angle = AddAngles( angle, 1800 ); // this is calculate hole 3 } // Create holes, that are the mirrored from the previous holes @@ -1008,10 +999,7 @@ void CreateThermalReliefPadPolygon( std::vector& aCornerBuffer, } aCornerBuffer.back().end_contour = true; - angle += 1800; - - if( angle >= 3600 ) - angle -= 3600; + angle = AddAngles( angle, 1800 ); } } diff --git a/pcbnew/class_dimension.cpp b/pcbnew/class_dimension.cpp index b644bd153a..474eaf01ad 100644 --- a/pcbnew/class_dimension.cpp +++ b/pcbnew/class_dimension.cpp @@ -307,7 +307,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) textPos.y = (m_crossBarF.y + m_featureLineGF.y) / 2; m_Text.SetTextPosition( textPos ); - double newAngle = -(angle * 1800 / M_PI); + double newAngle = -RAD2DECIDEG( angle ); NORMALIZE_ANGLE_POS( newAngle ); diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index a70dcf973c..f705d48d04 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -45,6 +45,7 @@ #include #include +#include #include #include diff --git a/pcbnew/class_netinfolist.cpp b/pcbnew/class_netinfolist.cpp index 54664e040a..955907ba9d 100644 --- a/pcbnew/class_netinfolist.cpp +++ b/pcbnew/class_netinfolist.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include #include #include diff --git a/pcbnew/class_pad_draw_functions.cpp b/pcbnew/class_pad_draw_functions.cpp index 215b25df33..cf32dbe6bb 100644 --- a/pcbnew/class_pad_draw_functions.cpp +++ b/pcbnew/class_pad_draw_functions.cpp @@ -716,7 +716,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( double( m_DeltaSize.x ), double( m_Size.x ) ); + angle = atan2( m_DeltaSize.x, 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 diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index 6604eb5718..d1d9678aa0 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -736,9 +736,9 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, } else { - /* atan2 is *not* the solution here, since can give upside + /* atan2 is *not* the solution here, since it can give upside down text. We want to work only in the first and fourth quadrant */ - angle = 10 * RAD2DEG( -atan( double( dy )/ double( dx ) ) ); + angle = RAD2DECIDEG( -atan( double( dy ) / double( dx ) ) ); } } @@ -921,8 +921,8 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, ( (SEGVIA*) this )->ReturnLayerPair( &layer_top, &layer_bottom ); // lines for the top layer - RotatePoint( &ax, &ay, layer_top * 3600 / brd->GetCopperLayerCount( ) ); - RotatePoint( &bx, &by, layer_top * 3600 / brd->GetCopperLayerCount( ) ); + RotatePoint( &ax, &ay, layer_top * 3600.0 / brd->GetCopperLayerCount( ) ); + RotatePoint( &bx, &by, layer_top * 3600.0 / brd->GetCopperLayerCount( ) ); GRLine( panel->GetClipBox(), aDC, m_Start.x + aOffset.x - ax, m_Start.y + aOffset.y - ay, m_Start.x + aOffset.x - bx, @@ -930,8 +930,8 @@ void SEGVIA::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, // lines for the bottom layer ax = 0; ay = radius; bx = 0; by = drill_radius; - RotatePoint( &ax, &ay, layer_bottom * 3600 / brd->GetCopperLayerCount( ) ); - RotatePoint( &bx, &by, layer_bottom * 3600 / brd->GetCopperLayerCount( ) ); + RotatePoint( &ax, &ay, layer_bottom * 3600.0 / brd->GetCopperLayerCount( ) ); + RotatePoint( &bx, &by, layer_bottom * 3600.0 / brd->GetCopperLayerCount( ) ); GRLine( panel->GetClipBox(), aDC, m_Start.x + aOffset.x - ax, m_Start.y + aOffset.y - ay, m_Start.x + aOffset.x - bx, diff --git a/pcbnew/dialogs/dialog_SVG_print.cpp b/pcbnew/dialogs/dialog_SVG_print.cpp index 0a962d35c5..e812b627ec 100644 --- a/pcbnew/dialogs/dialog_SVG_print.cpp +++ b/pcbnew/dialogs/dialog_SVG_print.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/dialogs/dialog_design_rules.cpp b/pcbnew/dialogs/dialog_design_rules.cpp index 208194fa79..07d6bef24e 100644 --- a/pcbnew/dialogs/dialog_design_rules.cpp +++ b/pcbnew/dialogs/dialog_design_rules.cpp @@ -40,6 +40,7 @@ #include #include +#include #include #include diff --git a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp index 98ef34ae8c..02be959e1f 100644 --- a/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp +++ b/pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp @@ -41,6 +41,7 @@ #include <3d_viewer.h> #include #include +#include #include #include diff --git a/pcbnew/dialogs/dialog_gendrill.cpp b/pcbnew/dialogs/dialog_gendrill.cpp index 958c72d326..fe53f3b8b0 100644 --- a/pcbnew/dialogs/dialog_gendrill.cpp +++ b/pcbnew/dialogs/dialog_gendrill.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/dragsegm.cpp b/pcbnew/dragsegm.cpp index a84a3b9a0e..7870710fd0 100644 --- a/pcbnew/dragsegm.cpp +++ b/pcbnew/dragsegm.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/drc_clearance_test_functions.cpp b/pcbnew/drc_clearance_test_functions.cpp index 99589fbd9f..e2cc04dc71 100644 --- a/pcbnew/drc_clearance_test_functions.cpp +++ b/pcbnew/drc_clearance_test_functions.cpp @@ -868,10 +868,7 @@ bool DRC::checkClearanceSegmToPad( const D_PAD* aPad, int aSegmentWidth, int aMi if( padHalfsize.x > padHalfsize.y ) { EXCHG( padHalfsize.x, padHalfsize.y ); - orient += 900; - - if( orient >= 3600 ) - orient -= 3600; + orient = AddAngles( orient, 900 ); } deltay = padHalfsize.y - padHalfsize.x; diff --git a/pcbnew/editedge.cpp b/pcbnew/editedge.cpp index 2bdebcd6f4..acc881c687 100644 --- a/pcbnew/editedge.cpp +++ b/pcbnew/editedge.cpp @@ -37,6 +37,7 @@ #include #include +#include #include #include diff --git a/pcbnew/export_vrml.cpp b/pcbnew/export_vrml.cpp index 47c8f95c05..e11187933e 100644 --- a/pcbnew/export_vrml.cpp +++ b/pcbnew/export_vrml.cpp @@ -487,7 +487,7 @@ static void export_vrml_oval_pad( LAYER_NUM layer, double xc, double yc, fan.c.x = xc; fan.c.y = yc; - double angle = orient / 1800.0 * M_PI; + double angle = DECIDEG2RAD( orient ); int divisions = SEGM_COUNT_PER_360 / 2; if( dy > dx ) @@ -1118,8 +1118,8 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, compose_quat( q1, q2, q1 ); // Note here aModule->GetOrientation() is in 0.1 degrees, - // so module rotation is aModule->GetOrientation() / 1800.0 - build_quat( 0, 0, 1, aModule->GetOrientation() / 1800.0 * M_PI, q2 ); + // so module rotation has to be converted to radians + build_quat( 0, 0, 1, DECIDEG2RAD( aModule->GetOrientation() ), q2 ); compose_quat( q1, q2, q1 ); from_quat( q1, rot ); diff --git a/pcbnew/footprint_wizard_frame.cpp b/pcbnew/footprint_wizard_frame.cpp index f1266e434f..73fe27b054 100644 --- a/pcbnew/footprint_wizard_frame.cpp +++ b/pcbnew/footprint_wizard_frame.cpp @@ -35,6 +35,7 @@ #include <3d_viewer.h> #include #include +#include #include #include diff --git a/pcbnew/gen_drill_report_files.cpp b/pcbnew/gen_drill_report_files.cpp index 462cf2a60f..4a9296c8c4 100644 --- a/pcbnew/gen_drill_report_files.cpp +++ b/pcbnew/gen_drill_report_files.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include diff --git a/pcbnew/gendrill_Excellon_writer.cpp b/pcbnew/gendrill_Excellon_writer.cpp index 3f44f48e17..1a83dfafba 100644 --- a/pcbnew/gendrill_Excellon_writer.cpp +++ b/pcbnew/gendrill_Excellon_writer.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include #include diff --git a/pcbnew/gpcb_plugin.cpp b/pcbnew/gpcb_plugin.cpp index 22cf403bea..42d85ec2c7 100644 --- a/pcbnew/gpcb_plugin.cpp +++ b/pcbnew/gpcb_plugin.cpp @@ -559,7 +559,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR, } // Negate angle (due to Y reversed axis) and convert it to internal units - angle = - angle * 1800.0 / M_PI; + angle = - RAD2DECIDEG( angle ); pad->SetOrientation( KiROUND( angle ) ); wxPoint padPos( (x1 + x2) / 2, (y1 + y2) / 2 ); diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index fe81b080e9..fc596e2bd8 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -34,6 +34,7 @@ #include <3d_viewer.h> #include #include +#include #include #include diff --git a/pcbnew/pad_edition_functions.cpp b/pcbnew/pad_edition_functions.cpp index 5483f3b272..51eab2a6f2 100644 --- a/pcbnew/pad_edition_functions.cpp +++ b/pcbnew/pad_edition_functions.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp index 82ec0db0d9..a1d21a6602 100644 --- a/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp +++ b/pcbnew/pcad2kicadpcb_plugin/pcb_arc.cpp @@ -121,8 +121,8 @@ void PCB_ARC::Parse( XNODE* aNode, if( lNode ) m_angle = StrToInt1Units( lNode->GetNodeContent() ); - m_startX = KiROUND( m_positionX + (double)r * cos( a * M_PI / 1800.0 ) ); - m_startY = KiROUND( m_positionY - (double)r * sin( a * M_PI / 1800.0 ) ); + m_startX = m_positionX + KiROUND( cosdecideg( r, a ) ); + m_startY = m_positionY - KiROUND( sindecideg( r, a ) ); } } diff --git a/pcbnew/pcbplot.cpp b/pcbnew/pcbplot.cpp index 38d3e86201..b15b7648c5 100644 --- a/pcbnew/pcbplot.cpp +++ b/pcbnew/pcbplot.cpp @@ -40,6 +40,7 @@ #include #include #include +#include /** Get the 'traditional' gerber extension depending on the layer diff --git a/pcbnew/plot_board_layers.cpp b/pcbnew/plot_board_layers.cpp index 81aeb6ca4f..7eb6e4bc10 100644 --- a/pcbnew/plot_board_layers.cpp +++ b/pcbnew/plot_board_layers.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/plot_brditems_plotter.cpp b/pcbnew/plot_brditems_plotter.cpp index 729048f178..2dcf0b10e1 100644 --- a/pcbnew/plot_brditems_plotter.cpp +++ b/pcbnew/plot_brditems_plotter.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/ratsnest.cpp b/pcbnew/ratsnest.cpp index b52a2f7021..00cec1cea0 100644 --- a/pcbnew/ratsnest.cpp +++ b/pcbnew/ratsnest.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp index 5e9d0a51e1..03e5193c91 100644 --- a/pcbnew/specctra.cpp +++ b/pcbnew/specctra.cpp @@ -56,6 +56,7 @@ #include #include +#include namespace DSN { diff --git a/pcbnew/specctra_export.cpp b/pcbnew/specctra_export.cpp index aa1139711d..a5560a8918 100644 --- a/pcbnew/specctra_export.cpp +++ b/pcbnew/specctra_export.cpp @@ -36,6 +36,7 @@ #include // DisplayError() #include // EDA_FileSelector() #include // RotatePoint() +#include #include // std::set #include // std::map diff --git a/pcbnew/specctra_import.cpp b/pcbnew/specctra_import.cpp index 5a45bfbe6a..66b3853f8c 100644 --- a/pcbnew/specctra_import.cpp +++ b/pcbnew/specctra_import.cpp @@ -36,6 +36,7 @@ #include // DisplayError() #include // EDA_FileSelector() #include +#include #include #include