# kicad-developers team mailing list archive

## Preliminary angle and distances sweep

```Still working on it, however this is what I've done till now; I'd like
to have opinions i.e. if I'm on the right track.

Basic ideas:

- Angles are being migrated to double unless in eeschema

- UI is still integer based (as discussed)

- The current angle unit is the decidegrees (but I've read in some
comment that there are plans to change this to degrees). The 'ideal'
units would be of course radians but then detecting the common
90/180/270 degrees rotation would be difficult (if not impossible).
Anyway it should be reasonably easy to find later the spots where this
10 factor is used.

- When going from double to int (geometrically) a KiROUND should be used

- Rounding should be done as early as possible:
i.e. intvar + KiROUND(fvar) is better than KiROUND(intvar + fvar)

Rationale: in this way a fixed point sum is done (even though
theorically there should be no loss of precision)

- Obviously nothing should break :D

- When possible distances should be computed using one of the existing
functions (GetLineLength, Distance, EuclideanNorm) or at least hypot (because
it's clearer)

- sqrt( x*x + y*y) is wrong with ints since the product can overflow (at least
one x and one y should be cast to double)

- When possible it's better to compare the distances squared

which use decidegrees instead of degrees. This clean up a lot of *10
and /10 stuff (also eases switch to another eventual degree unit)

- The pattern r * sin(a), r * cos(a) is widely used (mostly for
functions with accepts the angle directly in decidegrees. Result is
double so it should be rounded if necessary (I'm not so sure about
this... maybe it's better to return the rounded int?)

- Likewise the atan2 function is usefully replaced by the (preexisting)
ArcTangente one; the following are then equivalent:

orient = -(int) ( RAD2DEG( atan2( (double)size.y, (double)size.x ) ) * 10.0 );

orient = -ArcTangente( size.y, size.x );

The two double cast are not necessary anyway, but maybe they where
there to make notice of the implicit cast; I think they are noisy, but they
could be left. Also atan2(0, 0) gives 0 by specification (since forever,
IIRC) so it's not needed to check it as a special case.

- Another widely used pattern is this:

orient += 900;
if( orient >= 3600 )
orient -= 3600;

orient = ADD_ANGLES( orient, 900 );

Maybe the function name is nicer if lowercase? I'd like it better (also it's
a simple function, the other normalizations where macros).

- Try to use the angle normalization functions when they are available

- Lot and lot of degrees <-> radians converted to use the inline functions so that

double theta2 = EndAngle * M_PI / 1800.0;

becomes

double theta2 = DEG2RAD10( EndAngle );

I hope everyone think is a better expression.

- g_RotationAngle is an angle but remains an int since it's actually a UI
variable

- Some small functions in trigo.cpp moved as inline in trigo.h, using const
references when possible. Also I think that the previous DistanceLinePoint
was vulnerable to int overflow since the double cast was outside the
expression. I'd like a confirmation on this.

- I think that the only 'hardcoded' angles in decidegrees are 0, 900, 1800,
2700 and 3600, which is fine. Also there is the arrowhead half-angle of 27.5
degrees (I wonder from which standard this comes...)

- Most output function still keep their /10 factor for showing angles (there
are few of these, actually).

- s_thermalRot is actually a costant... kept it as a static variable

Also the patch is long but veeery boring :( all the points above repeated many
many times.

Need to recheck the whole thing and look if I missed something.

--
Lorenzo Marcantonio
Logos Srl
```
```=== modified file '3d-viewer/3d_draw.cpp'
--- 3d-viewer/3d_draw.cpp	2013-04-06 16:46:03 +0000
+++ 3d-viewer/3d_draw.cpp	2013-04-29 18:10:59 +0000
@@ -553,9 +553,8 @@

case S_CIRCLE:
{
-                int radius = KiROUND( hypot( double(segment->GetStart().x - segment->GetEnd().x),
-                                             double(segment->GetStart().y - segment->GetEnd().y) )
-                                    );
+                int radius = KiROUND( GetLineLength( segment->GetStart(),
+                                                     segment->GetEnd() ) );
thickness, segment->GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
@@ -587,9 +586,7 @@

case S_CIRCLE:
{
-                int radius = KiROUND( hypot( double(segment->GetStart().x - segment->GetEnd().x),
-                                             double(segment->GetStart().y - segment->GetEnd().y) )
-                                    );
+                int radius = KiROUND( GetLineLength( segment->GetStart(), segment->GetEnd() ) );
thickness, segment->GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
@@ -806,9 +803,7 @@

case S_CIRCLE:
{
-               int radius = KiROUND( hypot( double(m_Start.x - m_End.x),
-                                            double(m_Start.y - m_End.y) )
-                                    );
+               int radius = KiROUND( GetLineLength( m_Start, m_End ) );
thickness, GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
@@ -848,9 +843,7 @@

case S_CIRCLE:
{
-            int radius = KiROUND( hypot( double(m_Start.x - m_End.x),
-                                         double(m_Start.y - m_End.y) )
-                                );
+            int radius = KiROUND( GetLineLength( m_Start, m_End ) );
thickness, GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );

=== modified file '3d-viewer/3d_draw_basic_functions.cpp'
--- 3d-viewer/3d_draw_basic_functions.cpp	2013-04-25 07:05:33 +0000
+++ 3d-viewer/3d_draw_basic_functions.cpp	2013-04-29 11:37:43 +0000
@@ -370,17 +370,16 @@

void Draw3D_ArcSegment( const wxPoint&  aCenterPos, const wxPoint& aStartPoint,
-                        int aArcAngle, int aWidth, int aThickness,
+                        double aArcAngle, int aWidth, int aThickness,
int aZpos, double aBiuTo3DUnits )
{
const int   slice = SEGM_PER_CIRCLE;

std::vector <CPolyPt> cornerBuffer;
TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle,
-                            slice, aWidth );
+                           slice, aWidth );

Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits );
-
}

=== modified file '3d-viewer/3d_draw_basic_functions.h'
--- 3d-viewer/3d_draw_basic_functions.h	2012-09-12 11:11:30 +0000
+++ 3d-viewer/3d_draw_basic_functions.h	2013-04-29 09:42:12 +0000
@@ -85,7 +85,7 @@
* @param aBiuTo3DUnits = board internal units to 3D units scaling value
*/
void Draw3D_ArcSegment( const wxPoint&  aCenterPos, const wxPoint& aStartPoint,
-                        int aArcAngle, int aWidth, int aThickness,
+                        double aArcAngle, int aWidth, int aThickness,
int aZpos, double aBiuTo3DUnits );

=== modified file 'common/class_plotter.cpp'
--- common/class_plotter.cpp	2013-02-11 00:41:49 +0000
+++ common/class_plotter.cpp	2013-04-30 07:45:42 +0000
@@ -111,33 +111,29 @@
/**
* Generic fallback: arc rendered as a polyline
*/
-void PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
+void PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
FILL_T fill, int width )
{
wxPoint   start, end;
const int delta = 50;   // increment (in 0.1 degrees) to draw circles
-    double    alpha;

if( StAngle > EndAngle )
EXCHG( StAngle, EndAngle );

SetCurrentLineWidth( width );
/* Please NOTE the different sign due to Y-axis flip */
-    alpha   = DEG2RAD( StAngle / 10.0 );
-    start.x = centre.x + (int) ( radius * cos( -alpha ) );
-    start.y = centre.y + (int) ( radius * sin( -alpha ) );
MoveTo( start );
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 ) );
LineTo( end );
}

-    alpha = DEG2RAD( EndAngle / 10.0 );
-    end.x = centre.x + (int) ( radius * cos( -alpha ) );
-    end.y = centre.y + (int) ( radius * sin( -alpha ) );
FinishTo( end );
}

@@ -380,24 +376,23 @@
{
wxPoint center( (start.x + end.x) / 2, (start.y + end.y) / 2 );
wxSize  size( end.x - start.x, end.y - start.y );
-    int     orient;
+    double  orient;

if( size.y == 0 )
orient = 0;
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 = (int) sqrt( ( (double) size.x * size.x )
-                       + ( (double) size.y * size.y ) ) + width;
+    size.x = KiROUND( hypot( size.x, size.y ) ) + width;
size.y = width;

FlashPadOval( center, size, orient, tracemode );
}

-void PLOTTER::sketchOval( const wxPoint& pos, const wxSize& aSize, int orient,
+void PLOTTER::sketchOval( const wxPoint& pos, const wxSize& aSize, double orient,
int width )
{
SetCurrentLineWidth( width );
@@ -408,9 +403,7 @@
if( size.x > size.y )
{
EXCHG( size.x, size.y );
-        orient += 900;
-        if( orient >= 3600 )
-            orient -= 3600;
+        orient = ADD_ANGLES( orient, 900 );
}

deltaxy = size.y - size.x;       /* distance between centers of the oval */
@@ -470,8 +463,8 @@
}

-void PLOTTER::ThickArc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
-                        int width, EDA_DRAW_MODE_T tracemode )
+void PLOTTER::ThickArc( const wxPoint& centre, double StAngle, double EndAngle,
+                        int radius, int width, EDA_DRAW_MODE_T tracemode )
{
switch( tracemode )
{

=== modified file 'common/common_plotDXF_functions.cpp'
--- common/common_plotDXF_functions.cpp	2013-04-06 12:01:53 +0000
+++ common/common_plotDXF_functions.cpp	2013-04-30 07:46:17 +0000
@@ -389,7 +389,7 @@
/** Plot an arc in DXF format
* Filling is not supported
*/
-void DXF_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
+void DXF_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
FILL_T fill, int width )
{
wxASSERT( outputFile );
@@ -412,7 +412,7 @@
/**
* DXF oval pad: always done in sketch mode
*/
-void DXF_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int orient,
+void DXF_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
EDA_DRAW_MODE_T trace_mode )
{
wxASSERT( outputFile );
@@ -423,9 +423,7 @@
if( size.x > size.y )
{
EXCHG( size.x, size.y );
-        orient += 900;
-        if( orient >= 3600 )
-            orient -= 3600;
+        orient = ADD_ANGLES( orient, 900 );
}
sketchOval( pos, size, orient, -1 );
}
@@ -447,7 +445,7 @@
* DXF rectangular pad: alwayd done in sketch mode
*/
-                                int orient, EDA_DRAW_MODE_T trace_mode )
+                                double orient, EDA_DRAW_MODE_T trace_mode )
{
wxASSERT( outputFile );
wxSize size;
@@ -515,7 +513,7 @@
* DXF trapezoidal pad: only sketch mode is supported
*/
-                                  int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
+                                  double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
{
wxASSERT( outputFile );
wxPoint coord[4];       /* coord actual corners of a trapezoidal trace */
@@ -557,7 +555,7 @@
void DXF_PLOTTER::Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                        int                         aOrient,
+                        double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,

=== modified file 'common/common_plotGERBER_functions.cpp'
--- common/common_plotGERBER_functions.cpp	2012-10-13 18:54:33 +0000
+++ common/common_plotGERBER_functions.cpp	2013-04-30 07:29:20 +0000
@@ -282,17 +282,17 @@
}

-void GERBER_PLOTTER::Arc( const wxPoint& aCenter, int aStAngle, int aEndAngle,
+void GERBER_PLOTTER::Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
int aRadius, FILL_T aFill, int aWidth )
{
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 ) ) );
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 ) ) );
DPOINT devEnd = userToDeviceCoordinates( end );
DPOINT devCenter = userToDeviceCoordinates( aCenter )
- userToDeviceCoordinates( start );
@@ -370,7 +370,7 @@
/**
* Filled oval flashes are handled as aperture in the 90 degree positions only
*/
-void GERBER_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int orient,
+void GERBER_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
EDA_DRAW_MODE_T trace_mode )
{
wxASSERT( outputFile );
@@ -427,17 +427,17 @@
* Filled rect flashes are handled as aperture in the 90 degree positions only
*/
void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
-                                   int orient, EDA_DRAW_MODE_T trace_mode )
+                                   double orient, EDA_DRAW_MODE_T trace_mode )

{
wxASSERT( outputFile );
wxSize size( aSize );

-    /* Plot as flashed. */
-    switch( orient )
+    // Plot as an aperture flash
+    switch( int( orient ) )
{
case 900:
-    case 2700:        /* rotation of 90 degrees or 270 swaps dimensions */
+    case 2700:        // rotation of 90 degrees or 270 simply swaps sizes
EXCHG( size.x, size.y );

// Pass through
@@ -494,7 +494,7 @@
* they require aperture macros
*/
-                                     int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
+                                     double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )

{
// XXX to do: use an aperture macro to declare the pad

=== modified file 'common/common_plotHPGL_functions.cpp'
--- common/common_plotHPGL_functions.cpp	2013-02-04 00:53:48 +0000
+++ common/common_plotHPGL_functions.cpp	2013-04-30 07:46:51 +0000
@@ -381,7 +381,7 @@
* PU PY x, y; PD start_arc_X AA, start_arc_Y, angle, NbSegm; PU;
* Or PU PY x, y; PD start_arc_X AA, start_arc_Y, angle, PU;
*/
-void HPGL_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
+void HPGL_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
FILL_T fill, int width )
{
wxASSERT( outputFile );
@@ -401,8 +401,8 @@

// 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 ) ) ) );
DPOINT  cmap_dev = userToDeviceCoordinates( cmap );

fprintf( outputFile,
@@ -419,7 +419,7 @@

*/
-void HPGL_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int orient,
+void HPGL_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
EDA_DRAW_MODE_T trace_mode )
{
wxASSERT( outputFile );
@@ -431,10 +431,8 @@
*/
if( size.x > size.y )
{
-        EXCHG( size.x, size.y ); orient += 900;
-
-        if( orient >= 3600 )
-            orient -= 3600;
+        EXCHG( size.x, size.y );
+        orient = ADD_ANGLES( orient, 900 );
}

deltaxy = size.y - size.x;     // distance between centers of the oval
@@ -501,7 +499,7 @@

-                                 int orient, EDA_DRAW_MODE_T trace_mode )
+                                 double orient, EDA_DRAW_MODE_T trace_mode )
{
wxASSERT( outputFile );
wxSize  size;
@@ -618,7 +616,7 @@

-                                   int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
+                                   double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
{
wxASSERT( outputFile );
wxPoint polygone[4];        // coordinates of corners relatives to the pad

=== modified file 'common/common_plotPDF_functions.cpp'
--- common/common_plotPDF_functions.cpp	2012-10-13 18:54:33 +0000
+++ common/common_plotPDF_functions.cpp	2013-04-30 08:41:57 +0000
@@ -201,7 +201,7 @@
* The PDF engine can't directly plot arcs, it uses the base emulation.
* So no filled arcs (not a great loss... )
*/
-void PDF_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
+void PDF_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
FILL_T fill, int width )
{
wxASSERT( workFile );
@@ -219,23 +219,20 @@
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 ) );
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 ) );
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 ) );
pos_dev = userToDeviceCoordinates( end );
fprintf( workFile, "%g %g l ", pos_dev.x, pos_dev.y );

@@ -738,7 +735,7 @@
void PDF_PLOTTER::Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                        int                         aOrient,
+                        double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,

=== modified file 'common/common_plotPS_functions.cpp'
--- common/common_plotPS_functions.cpp	2013-04-04 21:35:01 +0000
+++ common/common_plotPS_functions.cpp	2013-04-30 07:47:06 +0000
@@ -64,7 +64,7 @@
}

-void PSLIKE_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, int orient,
+void PSLIKE_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
EDA_DRAW_MODE_T modetrace )
{
wxASSERT( outputFile );
@@ -75,9 +75,7 @@
if( size.x > size.y )
{
EXCHG( size.x, size.y );
-        orient += 900;
-        if( orient >= 3600 )
-            orient -= 3600;
+        orient = ADD_ANGLES( orient, 900 );
}

delta = size.y - size.x;
@@ -117,7 +115,7 @@

void PSLIKE_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
-                                   int orient, EDA_DRAW_MODE_T trace_mode )
+                                   double orient, EDA_DRAW_MODE_T trace_mode )
{
static std::vector< wxPoint > cornerList;
wxSize size( aSize );
@@ -161,7 +159,7 @@

-                                     int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
+                                     double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
{
static std::vector< wxPoint > cornerList;
cornerList.clear();
@@ -345,11 +343,6 @@
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 @@
*wideningFactor = sz_dev.y / sz_dev.x;

// The CTM transformation matrix
+    double alpha = DEG2RAD10( aOrient );
+    double sinalpha = sin( alpha );
+    double cosalpha = cos( alpha );
+
*ctm_a = cosalpha;
*ctm_b = sinalpha;
*ctm_c = -sinalpha;
@@ -474,8 +471,8 @@
}

-void PS_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
-                      FILL_T fill, int width )
+void PS_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int radius, FILL_T fill, int width )
{
wxASSERT( outputFile );
@@ -808,7 +805,7 @@
void PS_PLOTTER::Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-		       int                         aOrient,
+		       double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,

=== modified file 'common/common_plotSVG_functions.cpp'
--- common/common_plotSVG_functions.cpp	2013-04-27 02:12:57 +0000
+++ common/common_plotSVG_functions.cpp	2013-04-30 07:17:39 +0000
@@ -321,7 +321,7 @@
}

-void SVG_PLOTTER::Arc( const wxPoint& centre, int StAngle, int EndAngle, int radius,
+void SVG_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
FILL_T fill, int width )
{
/* Draws an arc of a circle, centred on (xc,yc), with starting point
@@ -347,7 +347,7 @@

if( !plotMirror )
{
-        int tmp = StAngle;
+        double tmp  = StAngle;
StAngle     = -EndAngle;
EndAngle    = -tmp;
}
@@ -361,12 +361,12 @@
start += centre_dev;
end += centre_dev;

-    double theta1 = StAngle * M_PI / 1800.0;
+    double theta1 = DEG2RAD10( StAngle );

if( theta1 < 0 )
theta1 = theta1 + M_PI * 2;

-    double theta2 = EndAngle * M_PI / 1800.0;
+    double theta2 = DEG2RAD10( EndAngle );

if( theta2 < 0 )
theta2 = theta2 + M_PI * 2;
@@ -550,7 +550,7 @@
void SVG_PLOTTER::Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                        int                         aOrient,
+                        double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,

=== modified file 'common/convert_basic_shapes_to_polygon.cpp'
--- common/convert_basic_shapes_to_polygon.cpp	2012-08-23 19:15:58 +0000
+++ common/convert_basic_shapes_to_polygon.cpp	2013-04-29 17:38:55 +0000
@@ -29,6 +29,7 @@
#include <fctsys.h>
#include <trigo.h>
#include <macros.h>
+#include <common.h>
#include <convert_basic_shapes_to_polygon.h>

/**
@@ -85,7 +86,6 @@
wxPoint endp   = aEnd - aStart; // end point coordinate for the same segment starting at (0,0)
wxPoint startp = aStart;
wxPoint corner;
-    int     seg_len;
CPolyPt polypoint;

// normalize the position in order to have endp.x >= 0;
@@ -95,8 +95,8 @@
startp = aEnd;
}

-    int delta_angle = ArcTangente( endp.y, endp.x );    // delta_angle is in 0.1 degrees
-    seg_len = (int) sqrt( ( (double) endp.y * endp.y ) + ( (double) endp.x * endp.x ) );
+    double delta_angle = ArcTangente( endp.y, endp.x ); // delta_angle is in 0.1 degrees
+    int seg_len = KiROUND( EuclideanNorm( endp ) );

int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree

@@ -158,7 +158,7 @@
* @param aWidth = width (thickness) of the line
*/
void TransformArcToPolygon( std::vector <CPolyPt>& aCornerBuffer,
-                            wxPoint aCentre, wxPoint aStart, int aArcAngle,
+                            wxPoint aCentre, wxPoint aStart, double aArcAngle,
int aCircleToSegmentsCount, int aWidth )
{
wxPoint arc_start, arc_end;

=== modified file 'common/drawtxt.cpp'
--- common/drawtxt.cpp	2013-04-11 17:40:20 +0000
+++ common/drawtxt.cpp	2013-04-29 09:47:00 +0000
@@ -266,7 +266,7 @@
const wxPoint& aPos,
EDA_COLOR_T aColor,
const wxString& aText,
-                      int aOrient,
+                      double aOrient,
const wxSize& aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,
@@ -566,7 +566,7 @@
enum EDA_COLOR_T aColor1,
enum EDA_COLOR_T aColor2,
const wxString &aText,
-                          int aOrient,
+                          double aOrient,
const wxSize &aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,
@@ -611,7 +611,7 @@
void PLOTTER::Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                    int                         aOrient,
+                    double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,

=== modified file 'common/eda_text.cpp'
--- common/eda_text.cpp	2013-04-09 16:00:46 +0000
+++ common/eda_text.cpp	2013-04-30 09:09:30 +0000
@@ -29,8 +29,8 @@

#include <eda_text.h>
#include <drawtxt.h>
+#include <class_drawpanel.h>     // EDA_DRAW_PANEL
#include <trigo.h>               // RotatePoint
-#include <class_drawpanel.h>     // EDA_DRAW_PANEL

// Conversion to application internal units defined at build time.

=== modified file 'common/gr_basic.cpp'
--- common/gr_basic.cpp	2013-04-09 17:16:53 +0000
+++ common/gr_basic.cpp	2013-04-29 17:19:13 +0000
@@ -746,7 +746,7 @@
}
else
{
-            int delta_angle = ArcTangente( dy, dx );
+            double delta_angle = ArcTangente( dy, dx );
dwx = 0;
dwy = width;
RotatePoint( &dwx, &dwy, -delta_angle );
@@ -1075,7 +1075,7 @@
y0 = ClipBox->GetY();
xm = ClipBox->GetRight();
ym = ClipBox->GetBottom();
-        r  = (int) hypot( x1 - xc, y1 - yc );
+        r  = KiROUND( Distance( x1, y1, xc, yc ) );
if( xc < ( x0 - r ) )
return;
if( yc < ( y0 - r ) )
@@ -1107,8 +1107,8 @@
wxDC*     DC,
int       x,
int       y,
-                  int       StAngle,
-                  int       EndAngle,
+                  double    StAngle,
+                  double    EndAngle,
int       r,
int       width,
EDA_COLOR_T       Color,
@@ -1153,7 +1153,8 @@

void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y,
-                  int StAngle, int EndAngle, int r, EDA_COLOR_T Color, EDA_COLOR_T BgColor )
+                  double StAngle, double EndAngle, int r,
+                  EDA_COLOR_T Color, EDA_COLOR_T BgColor )
{
GRFilledArc( ClipBox, DC, x, y, StAngle, EndAngle, r, 0, Color, BgColor );
}
@@ -1162,8 +1163,8 @@
/*
* Draw an arc in drawing space.
*/
-void GRArc( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, int StAngle,
-            int EndAngle, int r, EDA_COLOR_T Color )
+void GRArc( EDA_RECT* ClipBox, wxDC* DC, int xc, int yc, double StAngle,
+            double EndAngle, int r, EDA_COLOR_T Color )
{
int x1, y1, x2, y2;

@@ -1210,8 +1211,8 @@
wxDC*     DC,
int       x,
int       y,
-            int       StAngle,
-            int       EndAngle,
+            double    StAngle,
+            double    EndAngle,
int       r,
int       width,
EDA_COLOR_T       Color )

=== modified file 'common/pcbcommon.cpp'
--- common/pcbcommon.cpp	2013-04-07 11:55:18 +0000
+++ common/pcbcommon.cpp	2013-04-29 11:00:56 +0000
@@ -55,6 +55,7 @@

DISPLAY_OPTIONS DisplayOpt;      // Display options for board items

+// This will be always be 450 or 900 (by UI design) at the moment
int    g_RotationAngle;

int    g_AnchorColor        = BLUE;

=== modified file 'common/trigo.cpp'
--- common/trigo.cpp	2013-01-27 10:06:09 +0000
+++ common/trigo.cpp	2013-04-30 07:47:52 +0000
@@ -29,7 +29,8 @@
{
return (double) x * x;
}
-bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist )
+bool TestSegmentHit( const wxPoint &aRefPoint, wxPoint aStart,
+                     wxPoint aEnd, int aDist )
{
// test for vertical or horizontal segment
if( aEnd.x == aStart.x )
@@ -84,7 +85,7 @@
// the distance should be carefully calculated
if( (aStart.x - aRefPoint.x) <= aDist )
{
-            double dd = square( aRefPoint.x - aStart.x) +
+            double dd = square( aRefPoint.x - aStart.x ) +
square( aRefPoint.y - aStart.y );
if( dd <= square( aDist ) )
return true;
@@ -92,8 +93,8 @@

if( (aRefPoint.x - aEnd.x) <= aDist )
{
-            double dd = square(aRefPoint.x - aEnd.x) +
-                        square( aRefPoint.y - aEnd.y);
+            double dd = square( aRefPoint.x - aEnd.x ) +
+                        square( aRefPoint.y - aEnd.y );
if( dd <= square( aDist ) )
return true;
}
@@ -157,10 +158,8 @@
}

-int ArcTangente( int dy, int dx )
+double ArcTangente( int dy, int dx )
{
-    double fangle;
-
if( dy == 0 )
{
if( dx >= 0 )
@@ -193,8 +192,8 @@
return 1800 - 450;
}

-    fangle = atan2( (double) dy, (double) dx ) / M_PI * 1800;
-    return KiROUND( fangle );
+    // Of course dy and dx are treated as double
+    return RAD2DEG10( atan2( dy, dx ) );
}

@@ -202,11 +201,7 @@
{
int tmp;

-    while( angle < 0 )
-        angle += 3600;
-
-    while( angle >= 3600 )
-        angle -= 3600;
+    NORMALIZE_ANGLE_POS( angle );

// Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
if( angle == 0 )
@@ -231,7 +226,7 @@
}
else
{
-        double fangle = DEG2RAD( angle / 10.0 );
+        double fangle = DEG2RAD10( angle );
double sinus = sin( fangle );
double cosinus = cos( fangle );
double fpx = (*pY * sinus ) + (*pX * cosinus );
@@ -287,11 +282,7 @@
{
double tmp;

-    while( angle < 0 )
-        angle += 3600;
-
-    while( angle >= 3600 )
-        angle -= 3600;
+    NORMALIZE_ANGLE_POS( angle );

// Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
if( angle == 0 )
@@ -316,7 +307,7 @@
}
else
{
-        double fangle = DEG2RAD( angle / 10.0 );
+        double fangle = DEG2RAD10( angle );
double sinus = sin( fangle );
double cosinus = cos( fangle );

@@ -327,37 +318,3 @@
}
}

-
-double EuclideanNorm( wxPoint vector )
-{
-    return hypot( (double) vector.x, (double) vector.y );
-}
-
-double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint )
-{
-    return fabs( (double) ( (linePointB.x - linePointA.x) * (linePointA.y - referencePoint.y) -
-                 (linePointA.x - referencePoint.x ) * (linePointB.y - linePointA.y) )
-                  / EuclideanNorm( linePointB - linePointA ) );
-}
-
-
-bool HitTestPoints( wxPoint pointA, wxPoint pointB, double threshold )
-{
-    wxPoint vectorAB = pointB - pointA;
-    double  distance = EuclideanNorm( vectorAB );
-
-    return distance < threshold;
-}
-
-
-double CrossProduct( wxPoint vectorA, wxPoint vectorB )
-{
-    return (double)vectorA.x * vectorB.y - (double)vectorA.y * vectorB.x;
-}
-
-
-double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB )
-{
-    return hypot( (double) aPointA.x - (double) aPointB.x,
-                  (double) aPointA.y - (double) aPointB.y );
-}

=== modified file 'eeschema/database.cpp'
--- eeschema/database.cpp	2013-04-09 17:49:01 +0000
+++ eeschema/database.cpp	2013-04-30 09:53:47 +0000
@@ -7,7 +7,7 @@
#include "eda_doc.h"
#include "wxstruct.h"
-
+#include <macros.h>
#include "protos.h"
#include "class_library.h"
#include "dialog_helpers.h"

=== modified file 'eeschema/lib_arc.cpp'
--- eeschema/lib_arc.cpp	2013-04-09 17:49:01 +0000
+++ eeschema/lib_arc.cpp	2013-04-29 09:23:34 +0000
@@ -748,7 +748,7 @@
// artifacts left behind from the initial draw.
int dx, dy;
int cX, cY;
-        int angle;
+        double angle;

cX = aPosition.x;
cY = aPosition.y;
@@ -757,7 +757,7 @@
dy = m_ArcEnd.y - m_ArcStart.y;
cX -= m_ArcStart.x;
cY -= m_ArcStart.y;
-        angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
+        angle = ArcTangente( dy, dx );
RotatePoint( &dx, &dy, angle );     /* The segment dx, dy is horizontal
* -> Length = dx, dy = 0 */
RotatePoint( &cX, &cY, angle );
@@ -786,11 +786,9 @@

m_Radius = KiROUND( EuclideanNorm( centerStartVector ) );

-    m_t1 = (int) ( atan2( (double) centerStartVector.y,
-                          (double) centerStartVector.x ) * 1800 / M_PI );
-
-    m_t2 = (int) ( atan2( (double) centerEndVector.y,
-                          (double) centerEndVector.x ) * 1800 / M_PI );
+    // Angles in eeschema are still integers
+    m_t1 = KiROUND( ArcTangente( centerStartVector.y, centerStartVector.x ) );
+    m_t2 = KiROUND( ArcTangente( centerEndVector.y, centerEndVector.x ) );

NORMALIZE_ANGLE_POS( m_t1 );
NORMALIZE_ANGLE_POS( m_t2 );  // angles = 0 .. 3600

=== modified file 'eeschema/lib_circle.cpp'
--- eeschema/lib_circle.cpp	2013-04-09 17:49:01 +0000
+++ eeschema/lib_circle.cpp	2013-04-29 12:23:14 +0000
@@ -107,8 +107,7 @@

wxPoint relpos = aPosRef - aTransform.TransformCoordinate( m_Pos );

-    int dist = KiROUND( sqrt( ( (double) relpos.x * relpos.x ) +
-                              ( (double) relpos.y * relpos.y ) ) );
+    int dist = KiROUND( EuclideanNorm( relpos ) );

if( abs( dist - m_Radius ) <= aThreshold )
return true;
@@ -348,7 +347,7 @@

int dx = m_Pos.x - aPosition.x;
int dy = m_Pos.y - aPosition.y;
-        m_Radius = KiROUND( sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) ) );
+        m_Radius = KiROUND( hypot( dx, dy ) );
}
else
{

=== modified file 'eeschema/sch_base_frame.cpp'
--- eeschema/sch_base_frame.cpp	2012-09-12 09:53:11 +0000
+++ eeschema/sch_base_frame.cpp	2013-04-29 12:23:38 +0000
@@ -159,7 +159,7 @@
}

// We already decided the formatter above
-    line.Printf( locformatter, dXpos, dYpos, sqrt( dXpos * dXpos + dYpos * dYpos ) );
+    line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
SetStatusText( line, 3 );

// refresh units display

=== modified file 'eeschema/transform.cpp'
--- eeschema/transform.cpp	2012-01-23 04:33:36 +0000
+++ eeschema/transform.cpp	2013-04-30 07:20:09 +0000
@@ -1,6 +1,8 @@

#include <macros.h>
#include <transform.h>
+#include <common.h>
+#include <trigo.h>

TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform )
@@ -72,19 +74,19 @@
*aAngle2 += 1;
}

-    x = cos( *aAngle1 * M_PI / 1800.0 );
-    y = sin( *aAngle1 * M_PI / 1800.0 );
+    x = cos( DEG2RAD( *aAngle1 ) );
+    y = sin( DEG2RAD( *aAngle1 ) );
t = x * x1 + y * y1;
y = x * x2 + y * y2;
x = t;
-    *aAngle1 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 );
+    *aAngle1 = KiROUND( ArcTangente( y, x ) );

-    x = cos( *aAngle2 * M_PI / 1800.0 );
-    y = sin( *aAngle2 * M_PI / 1800.0 );
+    x = cos( DEG2RAD( *aAngle2 ) );
+    y = sin( DEG2RAD( *aAngle2 ) );
t = x * x1 + y * y1;
y = x * x2 + y * y2;
x = t;
-    *aAngle2 = (int) ( atan2( y, x ) * 1800.0 / M_PI + 0.5 );
+    *aAngle2 = KiROUND( ArcTangente( y, x ) );

NORMALIZE_ANGLE_POS( *aAngle1 );
NORMALIZE_ANGLE_POS( *aAngle2 );

=== modified file 'gerbview/class_aperture_macro.cpp'
--- gerbview/class_aperture_macro.cpp	2012-09-22 11:19:37 +0000
+++ gerbview/class_aperture_macro.cpp	2013-04-30 07:11:16 +0000
@@ -444,7 +444,7 @@
wxPoint end = mapPt( params[4].GetValue( tool ),
params[5].GetValue( tool ), m_GerbMetric );
wxPoint delta = end - start;
-        int     len   = KiROUND( hypot( delta.x, delta.y ) );
+        int     len   = KiROUND( EuclideanNorm( delta ) );

// To build the polygon, we must create a horizonta polygon starting to "start"
// and rotate it to have it end point to "end"
@@ -459,7 +459,7 @@
aBuffer.push_back( currpt );

// Rotate rectangle and move it to the actual start point
-        int angle = KiROUND( atan2( (double) delta.y, (double) delta.x ) * 1800.0 / M_PI );
+        double angle = ArcTangente( delta.y, delta.x );

for( unsigned ii = 0; ii < 4; ii++ )
{
@@ -512,17 +512,15 @@
int outerRadius   = scaletoIU( params[2].GetValue( tool ), m_GerbMetric ) / 2;
int innerRadius   = scaletoIU( params[3].GetValue( tool ), m_GerbMetric ) / 2;
int halfthickness = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2;
-        int angle_start   = KiROUND( asin(
-                                         (double) halfthickness / innerRadius ) * 1800 / M_PI );
+        double angle_start = RAD2DEG10( asin( (double) halfthickness / innerRadius ) );

// Draw shape in the first cadrant (X and Y > 0)
wxPoint pos, startpos;

// Inner arc
-        int angle_end = 900 - angle_start;
-        int angle;
-        for( angle = angle_start; angle < angle_end; angle += 100 )
+        double angle_end = 900 - angle_start;
+        for( double angle = angle_start; angle < angle_end; angle += 100 )
{
pos = startpos;
RotatePoint( &pos, angle );
@@ -537,11 +535,11 @@
// outer arc
startpos.y  = 0;
-        angle_start = KiROUND( asin( (double) halfthickness / outerRadius ) * 1800 / M_PI );
angle_end   = 900 - angle_start;

// First point, near Y axis, outer arc
-        for( angle = angle_end; angle > angle_start; angle -= 100 )
+        for( double angle = angle_end; angle > angle_start; angle -= 100 )
{
pos = startpos;
RotatePoint( &pos, angle );

=== modified file 'gerbview/class_gerber_draw_item.cpp'
--- gerbview/class_gerber_draw_item.cpp	2013-04-04 21:35:01 +0000
+++ gerbview/class_gerber_draw_item.cpp	2013-04-29 11:57:28 +0000
@@ -360,8 +360,7 @@
break;

case GBR_CIRCLE:
-        radius = KiROUND(hypot( (double) ( m_End.x - m_Start.x ),
-                                (double) ( m_End.y - m_Start.y ) ));
+        radius = KiROUND( GetLineLength( m_Start, m_End ) );

halfPenWidth = m_Size.x >> 1;

=== modified file 'gerbview/draw_gerber_screen.cpp'
--- gerbview/draw_gerber_screen.cpp	2013-03-31 13:27:46 +0000
+++ gerbview/draw_gerber_screen.cpp	2013-04-29 09:46:37 +0000
@@ -353,7 +353,8 @@
{
wxPoint     pos;
-    int         width, orient;
+    int         width;
+    double      orient;
wxString    Line;

=== modified file 'gerbview/export_to_pcbnew.cpp'
--- gerbview/export_to_pcbnew.cpp	2013-04-10 07:03:19 +0000
+++ gerbview/export_to_pcbnew.cpp	2013-04-30 07:11:34 +0000
@@ -233,6 +233,8 @@
#define SEG_SHAPE   0
#define ARC_SHAPE   2
int     shape   = SEG_SHAPE;
+
+    // please note: the old PCB format only has integer support for angles
int     angle   = 0;
wxPoint seg_start, seg_end;

@@ -247,7 +249,7 @@
(double) ( aGbrItem->m_End.x - aGbrItem->m_ArcCentre.x ) );

shape       = ARC_SHAPE;
-        angle       = KiROUND( (a - b) / M_PI * 1800.0 );
+        angle       = KiROUND( RAD2DEG10(a - b) );
seg_start   = aGbrItem->m_ArcCentre;

if( angle < 0 )

=== modified file 'gerbview/gerbview_frame.cpp'
--- gerbview/gerbview_frame.cpp	2013-04-09 17:49:01 +0000
+++ gerbview/gerbview_frame.cpp	2013-04-30 11:14:35 +0000
@@ -32,6 +32,7 @@
#include <class_drawpanel.h>
#include <build_version.h>
#include <macros.h>
+#include <trigo.h>
#include <base_units.h>
#include <colors_selection.h>
#include <class_gbr_layer_box_selector.h>
@@ -802,14 +803,10 @@
dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x;
dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y;

-        if( dx==0 && dy==0 )
-            theta = 0.0;
-        else
-            theta = atan2( (double) -dy, (double) dx );
-
-        theta = theta * 180.0 / M_PI;
-
-        ro = sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
+        // atan2 in the 0,0 case already returns 0
+        theta = RAD2DEG( atan2( (double) -dy, (double) dx ) );
+
+        ro = hypot( dx, dy );
wxString formatter;
switch( g_UserUnit )
{
@@ -868,7 +865,7 @@
dYpos = To_User_Unit( g_UserUnit, dy );

// We already decided the formatter above
-        line.Printf( locformatter, dXpos, dYpos, sqrt( dXpos * dXpos + dYpos * dYpos ) );
+        line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
SetStatusText( line, 3 );
}
}

=== modified file 'gerbview/rs274d.cpp'
--- gerbview/rs274d.cpp	2013-04-01 05:53:38 +0000
+++ gerbview/rs274d.cpp	2013-04-29 09:09:11 +0000
@@ -339,8 +339,8 @@
* angle is trigonometrical (counter-clockwise),
* and axis is the X,Y gerber coordinates
*/
-    int start_angle = KiROUND(atan2( (double) start.y, (double) start.x ) * 1800 / M_PI);
-    int end_angle = KiROUND(atan2( (double) end.y, (double) end.x ) * 1800 / M_PI);
+    double start_angle = ArcTangente( start.y, start.x );
+    double end_angle   = ArcTangente( end.y, end.x );

// dummyTrack has right geometric parameters, but
// fillArcGBRITEM calculates arc parameters for a draw function that expects
@@ -350,7 +350,7 @@
if( start_angle > end_angle )
end_angle += 3600;

-    int arc_angle = start_angle - end_angle;
+    double arc_angle = start_angle - end_angle;
// Approximate arc by 36 segments per 360 degree
const int increment_angle = 3600 / 36;
int count = std::abs( arc_angle / increment_angle );
@@ -361,7 +361,7 @@
wxPoint start_arc = start;
for( int ii = 0; ii <= count; ii++ )
{
-        int rot;
+        double rot;
wxPoint end_arc = start;
if( aClockwise )
rot = ii * increment_angle; // rot is in 0.1 deg

=== modified file 'include/convert_basic_shapes_to_polygon.h'
--- include/convert_basic_shapes_to_polygon.h	2012-08-23 19:15:58 +0000
+++ include/convert_basic_shapes_to_polygon.h	2013-04-29 11:37:28 +0000
@@ -79,7 +79,7 @@
* @param aWidth = width (thickness) of the line
*/
void TransformArcToPolygon( std::vector <CPolyPt>& aCornerBuffer,
-                            wxPoint aCentre, wxPoint aStart, int aArcAngle,
+                            wxPoint aCentre, wxPoint aStart, double aArcAngle,
int aCircleToSegmentsCount, int aWidth );

#endif     // CONVERT_BASIC_SHAPES_TO_POLYGON_H

=== modified file 'include/drawtxt.h'
--- include/drawtxt.h	2013-04-11 17:40:20 +0000
+++ include/drawtxt.h	2013-04-29 09:43:49 +0000
@@ -94,7 +94,7 @@
const wxPoint &aPos,
enum EDA_COLOR_T aColor,
const wxString &aText,
-                      int aOrient,
+                      double aOrient,
const wxSize &aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,
@@ -118,7 +118,7 @@
enum EDA_COLOR_T aColor1,
enum EDA_COLOR_T aColor2,
const wxString &aText,
-                          int aOrient,
+                          double aOrient,
const wxSize &aSize,
enum EDA_TEXT_HJUSTIFY_T aH_justify,
enum EDA_TEXT_VJUSTIFY_T aV_justify,

=== modified file 'include/eda_text.h'
--- include/eda_text.h	2013-04-09 16:00:46 +0000
+++ include/eda_text.h	2013-04-30 08:46:14 +0000
@@ -30,7 +30,7 @@
#ifndef EDA_TEXT_H_
#define EDA_TEXT_H_

-#include <macros.h>                 // NORMALIZE_ANGLE_POS( angle );
+#include <trigo.h>                 // NORMALIZE_ANGLE_POS( angle );
#include <common.h>                 // wxStringSplit
#include <gr_basic.h>               // EDA_DRAW_MODE_T
#include <base_struct.h>            // EDA_RECT

=== modified file 'include/gr_basic.h'
--- include/gr_basic.h	2013-04-09 16:00:46 +0000
+++ include/gr_basic.h	2013-04-29 10:58:43 +0000
@@ -203,10 +203,10 @@
void GRFilledCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, EDA_COLOR_T aColor );
void GRCircle( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aPos, int aRadius, int aWidth, EDA_COLOR_T aColor );

-void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int StAngle,
-            int EndAngle, int r, EDA_COLOR_T Color );
-void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int StAngle,
-            int EndAngle, int r, int width, EDA_COLOR_T Color );
+void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
+            double EndAngle, int r, EDA_COLOR_T Color );
+void GRArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
+            double EndAngle, int r, int width, EDA_COLOR_T Color );
void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
int xc, int yc, EDA_COLOR_T Color );
void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
@@ -214,9 +214,9 @@
void GRArc1( EDA_RECT* aClipBox, wxDC* aDC, wxPoint aStart, wxPoint aEnd,
wxPoint aCenter, int aWidth, EDA_COLOR_T aColor );
void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y,
-                  int StAngle, int EndAngle, int r, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
-void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, int StAngle,
-                  int EndAngle, int r, int width, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
+                  double StAngle, double EndAngle, int r, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
+void GRFilledArc( EDA_RECT* ClipBox, wxDC* DC, int x, int y, double StAngle,
+                  double EndAngle, int r, int width, EDA_COLOR_T Color, EDA_COLOR_T BgColor );
void GRCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, int width, EDA_COLOR_T Color );

void GRFillCSegm( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,

=== modified file 'include/macros.h'
--- include/macros.h	2013-04-28 15:43:26 +0000
+++ include/macros.h	2013-04-30 08:35:13 +0000
@@ -57,62 +57,16 @@
#endif
}

-// This really need a function? anyway is used *a lot* of times
-template<class T> inline void NEGATE( T& x ) { x = -x; }
+// This really needs a function? well, it is used *a lot* of times
+template<class T> 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; }
-
-/// Normalize angle to be in the -360.0 .. 360.0:
-template<class T> 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<class T> inline void NORMALIZE_ANGLE_POS( T& Angle )
-{
-    while( Angle < 0 )
-        Angle += 3600;
-    while( Angle >= 3600 )
-        Angle -= 3600;
-}
-
-template<class T> 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<class T> 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<class T> 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<class T, class T2> inline void EXCHG( T& a, T2& b )
{
T temp = a;

=== modified file 'include/plot_common.h'
--- include/plot_common.h	2013-04-05 08:55:46 +0000
+++ include/plot_common.h	2013-04-29 11:27:28 +0000
@@ -153,8 +153,8 @@
int width = DEFAULT_LINE_WIDTH ) = 0;
virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
int width = DEFAULT_LINE_WIDTH ) = 0;
-    virtual void Arc( const wxPoint& centre, int StAngle, int EndAngle, int rayon,
-                      FILL_T fill, int width = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );

/**
* moveto/lineto primitive, moves the 'pen' to the specified direction
@@ -214,8 +214,8 @@
// Higher level primitives -- can be drawn as line, sketch or 'filled'
virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
EDA_DRAW_MODE_T tracemode );
-    virtual void ThickArc( const wxPoint& centre, int StAngle, int EndAngle, int rayon,
-                           int width, EDA_DRAW_MODE_T tracemode );
+    virtual void ThickArc( const wxPoint& centre, double StAngle, double EndAngle,
+                           int rayon, int width, EDA_DRAW_MODE_T tracemode );
virtual void ThickRect( const wxPoint& p1, const wxPoint& p2, int width,
EDA_DRAW_MODE_T tracemode );
virtual void ThickCircle( const wxPoint& pos, int diametre, int width,
@@ -224,10 +224,10 @@
// Flash primitives
virtual void FlashPadCircle( const wxPoint& pos, int diametre,
EDA_DRAW_MODE_T trace_mode ) = 0;
-    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, int orient,
+    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
EDA_DRAW_MODE_T trace_mode ) = 0;
virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
-                               int orient, EDA_DRAW_MODE_T trace_mode ) = 0;
+                               double orient, EDA_DRAW_MODE_T trace_mode ) = 0;

@@ -238,7 +238,7 @@
* @param aTrace_Mode = FILLED or SKETCH
*/
-                                 int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode ) = 0;
+                                 double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode ) = 0;

/**
@@ -247,7 +247,7 @@
virtual void Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                       int                         aOrient,
+                       double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,
@@ -297,7 +297,7 @@
// Helper function for sketched filler segment
void segmentAsOval( const wxPoint& start, const wxPoint& end, int width,
EDA_DRAW_MODE_T tracemode );
-    void sketchOval( const wxPoint& pos, const wxSize& size, int orient,
+    void sketchOval( const wxPoint& pos, const wxSize& size, double orient,
int width );

// Coordinate and scaling conversion functions
@@ -402,17 +402,17 @@

virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
EDA_DRAW_MODE_T tracemode );
-    virtual void Arc( const wxPoint& centre, int StAngle, int EndAngle, int rayon,
-                      FILL_T fill, int width = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );
virtual void PenTo( const wxPoint& pos, char plume );
virtual void FlashPadCircle( const wxPoint& pos, int diametre,
EDA_DRAW_MODE_T trace_mode );
-    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, int orient,
+    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
EDA_DRAW_MODE_T trace_mode );
virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
-                               int orient, EDA_DRAW_MODE_T trace_mode );
+                               double orient, EDA_DRAW_MODE_T trace_mode );
-                                 int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );
+                                 double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );

protected:
void penControl( char plume );
@@ -459,12 +459,12 @@
// Pad routines are handled with lower level primitives
virtual void FlashPadCircle( const wxPoint& pos, int diametre,
EDA_DRAW_MODE_T trace_mode );
-    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, int orient,
+    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
EDA_DRAW_MODE_T trace_mode );
virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
-                               int orient, EDA_DRAW_MODE_T trace_mode );
+                               double orient, EDA_DRAW_MODE_T trace_mode );
-                                 int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );
+                                 double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );

/** The SetColor implementation is split with the subclasses:
* The PSLIKE computes the rgb values, the subclass emits the
@@ -543,8 +543,8 @@
int width = DEFAULT_LINE_WIDTH );
virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
int width = DEFAULT_LINE_WIDTH );
-    virtual void Arc( const wxPoint& centre, int StAngle, int EndAngle,
-              int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );

virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH );
@@ -556,7 +556,7 @@
virtual void Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                       int                         aOrient,
+                       double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,
@@ -610,8 +610,8 @@
int width = DEFAULT_LINE_WIDTH );
virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
int width = DEFAULT_LINE_WIDTH );
-    virtual void Arc( const wxPoint& centre, int StAngle, int EndAngle,
-              int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );

virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH);
@@ -621,7 +621,7 @@
virtual void Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                       int                         aOrient,
+                       double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,
@@ -677,8 +677,8 @@
int width = DEFAULT_LINE_WIDTH );
virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
int width = DEFAULT_LINE_WIDTH );
-    virtual void Arc( const wxPoint& centre, int StAngle, int EndAngle,
-              int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );

virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH );
@@ -690,7 +690,7 @@
virtual void Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                       int                         aOrient,
+                       double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,
@@ -786,21 +786,21 @@
int width = DEFAULT_LINE_WIDTH );
virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill,
int width = DEFAULT_LINE_WIDTH );
-    virtual void Arc( const wxPoint& aCenter, int aStAngle, int aEndAngle, int aRadius,
-                      FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
+                      int aRadius, FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH );
virtual void PlotPoly( const std::vector< wxPoint >& aCornerList,
FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH );

virtual void PenTo( const wxPoint& pos, char plume );
virtual void FlashPadCircle( const wxPoint& pos, int diametre,
EDA_DRAW_MODE_T trace_mode );
-    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, int orient,
+    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
EDA_DRAW_MODE_T trace_mode );
virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
-                               int orient, EDA_DRAW_MODE_T trace_mode );
+                               double orient, EDA_DRAW_MODE_T trace_mode );

-                                 int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );
+                                 double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );

virtual void SetLayerPolarity( bool aPositive );

@@ -877,22 +877,22 @@
FILL_T aFill, int aWidth = DEFAULT_LINE_WIDTH );
virtual void ThickSegment( const wxPoint& start, const wxPoint& end, int width,
EDA_DRAW_MODE_T tracemode );
-    virtual void Arc( const wxPoint& centre, int StAngle, int EndAngle, int rayon,
-                      FILL_T fill, int width = DEFAULT_LINE_WIDTH );
+    virtual void Arc( const wxPoint& centre, double StAngle, double EndAngle,
+                      int rayon, FILL_T fill, int width = DEFAULT_LINE_WIDTH );
virtual void PenTo( const wxPoint& pos, char plume );
virtual void FlashPadCircle( const wxPoint& pos, int diametre,
EDA_DRAW_MODE_T trace_mode );
-    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, int orient,
+    virtual void FlashPadOval( const wxPoint& pos, const wxSize& size, double orient,
EDA_DRAW_MODE_T trace_mode );
virtual void FlashPadRect( const wxPoint& pos, const wxSize& size,
-                               int orient, EDA_DRAW_MODE_T trace_mode );
+                               double orient, EDA_DRAW_MODE_T trace_mode );
-                                 int aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );
+                                 double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode );

virtual void Text( const wxPoint&              aPos,
enum EDA_COLOR_T            aColor,
const wxString&             aText,
-                       int                         aOrient,
+                       double                      aOrient,
const wxSize&               aSize,
enum EDA_TEXT_HJUSTIFY_T    aH_justify,
enum EDA_TEXT_VJUSTIFY_T    aV_justify,

=== modified file 'include/trigo.h'
--- include/trigo.h	2013-01-26 17:49:48 +0000
+++ include/trigo.h	2013-04-30 10:18:13 +0000
@@ -28,7 +28,8 @@

#ifndef TRIGO_H
#define TRIGO_H
-
+#include <math.h>
+#include <wx/gdicmn.h> // For wxPoint

/*
* Calculate the new point of coord coord pX, pY,
@@ -46,7 +47,7 @@
* Calculates the new coord point point
* for a rotation angle in (1 / 10 degree)
*/
-static inline void RotatePoint( wxPoint* point, double angle )
+inline void RotatePoint( wxPoint* point, double angle )
{
RotatePoint( &point->x, &point->y, angle );
}
@@ -64,34 +65,68 @@
/* Return the arc tangent of 0.1 degrees coord vector dx, dy
* between -1800 and 1800
* Equivalent to atan2 (but faster for calculations if
- * the angle is 0 to -1800, or + - 900
+ * the angle is 0 to -1800, or + - 900)
+ * Lorenzo: In fact usually atan2 already has to do these optimizations
+ * (due to the discontinuity in tan) but this function also returns
*/
-int ArcTangente( int dy, int dx );
+double ArcTangente( int dy, int dx );
+
+//! @brief Euclidean norm of a 2D vector
+//! @param vector Two-dimensional vector
+//! @return Euclidean norm of the vector
+inline double EuclideanNorm( const wxPoint &vector )
+{
+    // Warning, this is working with doubles
+    return hypot( vector.x, vector.y );
+}

//! @brief Compute the distance between a line and a reference point
//! Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
//! @param linePointA Point on line
//! @param linePointB Point on line
//! @param referencePoint Reference point
-double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint );
-
-//! @brief Euclidean norm of a 2D vector
-//! @param vector Two-dimensional vector
-//! @return Euclidean norm of the vector
-double EuclideanNorm( wxPoint vector );
+inline double DistanceLinePoint( const wxPoint &linePointA,
+                                 const wxPoint &linePointB,
+                                 const wxPoint &referencePoint )
+{
+    // The multiple double casts are redundant. However in the previous
+    // definition the cast was (implicitly) done too late, just before
+    // the division (EuclideanNorm gives a double so from int it would
+    // be promoted); that means that the whole expression were
+    // vulnerable to overflow during int multiplications
+    return fabs( ( double(linePointB.x - linePointA.x) *
+                   double(linePointA.y - referencePoint.y) -
+                   double(linePointA.x - referencePoint.x ) *
+                   double(linePointB.y - linePointA.y) )
+            / EuclideanNorm( linePointB - linePointA ) );
+}

//! @brief Test, if two points are near each other
//! @param pointA First point
//! @param pointB Second point
//! @param threshold The maximum distance
//! @return True or false
-bool HitTestPoints( wxPoint pointA, wxPoint pointB, double threshold );
+inline bool HitTestPoints( const wxPoint &pointA, const wxPoint &pointB, double threshold )
+{
+    wxPoint vectorAB = pointB - pointA;
+
+    // Compare the distances squared. The double is needed to avoid
+    // overflow during int multiplication
+    double sqdistance = (double)vectorAB.x * vectorAB.x +
+                        (double)vectorAB.y * vectorAB.y;
+
+    return sqdistance < threshold * threshold;
+}

//! @brief Determine the cross product
//! @param vectorA Two-dimensional vector
//! @param vectorB Two-dimensional vector
-double CrossProduct( wxPoint vectorA, wxPoint vectorB );
-
+inline double CrossProduct( const wxPoint &vectorA, const wxPoint &vectorB )
+{
+    // As before the cast is to avoid int overflow
+    return (double)vectorA.x * vectorB.y - (double)vectorA.y * vectorB.x;
+}

/**
* Function TestSegmentHit
@@ -102,13 +137,103 @@
* @param aEnd is the second end-point of the line segment
* @param aDist = maximum distance for hit
*/
-bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist );
+bool TestSegmentHit( const wxPoint &aRefPoint, wxPoint aStart,
+                     wxPoint aEnd, int aDist );

/**
* Function GetLineLength
* returns the length of a line segment defined by \a aPointA and \a aPointB.
- * @return Length of a line.
- */
-double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB );
+ * See also EuclideanNorm and Distance for the single vector or four
+ * scalar versions
+ * @return Length of a line (as double)
+ */
+inline double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB )
+{
+    // Implicitly casted to double
+    return hypot( aPointA.x - aPointB.x,
+                  aPointA.y - aPointB.y );
+}
+
+// These are the usual degrees <-> radians conversion routines
+inline double DEG2RAD( double deg ) { return deg * M_PI / 180.0; }
+
+// These are the same *but* work with the internal 'decidegrees' unit
+inline double DEG2RAD10( double deg ) { return deg * M_PI / 1800.0; }
+
+/* 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 <class T> 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 <class T> inline void NORMALIZE_ANGLE_POS( T &Angle )
+{
+    while( Angle < 0 )
+        Angle += 3600;
+    while( Angle >= 3600 )
+        Angle -= 3600;
+}
+
+/// Add two angles (keeping the result normalized)
+template <class T, class T2> inline T ADD_ANGLES( T a1, T2 a2 )
+{
+    a1 += a2;
+    NORMALIZE_ANGLE_POS( a1 );
+    return a1;
+}
+
+template <class T> 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 <class T> 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 <class T> 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 sin10radius( double r, double a )
+{
+    return r * sin( DEG2RAD10( a ) );
+}
+
+/**
+ * Circle generation utility: computes r * cos(a)
+ * Where a is in decidegrees, not in radians.
+ */
+inline double cos10radius( double r, double a )
+{
+    return r * cos( DEG2RAD10( a ) );
+}

#endif

=== modified file 'include/wxBasePcbFrame.h'
--- include/wxBasePcbFrame.h	2013-04-25 16:29:35 +0000
+++ include/wxBasePcbFrame.h	2013-04-29 11:23:40 +0000
@@ -291,7 +291,7 @@
MODULE* Create_1_Module( const wxString& aModuleName );

void Edit_Module( MODULE* module, wxDC* DC );
-    void Rotate_Module( wxDC* DC, MODULE* module, int angle, bool incremental );
+    void Rotate_Module( wxDC* DC, MODULE* module, double angle, bool incremental );

/**
* Function PlaceModule

=== modified file 'include/wxPcbStruct.h'
--- include/wxPcbStruct.h	2013-04-25 16:29:35 +0000
+++ include/wxPcbStruct.h	2013-04-29 11:26:21 +0000
@@ -1482,7 +1482,7 @@
* @param include_fixe = true to orient locked footprints
* @return true if some footprints modified, false if no change
*/
-    bool ReOrientModules( const wxString& ModuleMask, int Orient, bool include_fixe );
+    bool ReOrientModules( const wxString& ModuleMask, double Orient, bool include_fixe );
void LockModule( MODULE* aModule, bool aLocked );
void AutoMoveModulesOnPcb( bool PlaceModulesHorsPcb );

=== modified file 'pcbnew/autorouter/autorout.h'
--- pcbnew/autorouter/autorout.h	2013-04-04 21:35:01 +0000
+++ pcbnew/autorouter/autorout.h	2013-04-29 11:35:17 +0000
@@ -209,7 +209,8 @@

/* 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 );
+                           double angle, LAYER_MSK masque_layer,
+                           int color, int op_logic );

/* QUEUE.CPP */
void FreeQueue();

=== modified file 'pcbnew/autorouter/graphpcb.cpp'
--- pcbnew/autorouter/graphpcb.cpp	2013-04-06 12:28:02 +0000
+++ pcbnew/autorouter/graphpcb.cpp	2013-04-30 07:49:20 +0000
@@ -35,7 +35,7 @@
#include <macros.h>
#include <trigo.h>
#include <pcbcommon.h>
-
+#include <math_for_graphics.h>
#include <class_board.h>
#include <class_track.h>

@@ -47,7 +47,7 @@

void TraceArc( int ux0, int uy0,
int ux1, int uy1,
-               int ArcAngle,
+               double ArcAngle,
int lg, LAYER_NUM layer, int color,
int op_logic );

@@ -125,7 +125,7 @@
{
TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy,
shape_pos.x + dx, shape_pos.y + dy,
}
}
@@ -531,7 +531,7 @@

void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
-                           int angle, LAYER_MSK aLayerMask, int color, int op_logic )
+                           double angle, LAYER_MSK aLayerMask, int color, int op_logic )
{
int  row, col;
int  cx, cy;    // Center of rectangle
@@ -561,8 +561,7 @@

cx    = (ux0 + ux1) / 2;
cy    = (uy0 + uy1) / 2;
-    radius = (int) sqrt( (double) ( cx - ux0 ) * ( cx - ux0 )
-                       + (double) ( cy - uy0 ) * ( cy - uy0 ) );
+    radius = KiROUND( Distance( ux0, uy0, cx, cy ) );

// Calculating coordinate limits belonging to the rectangle.
row_max = ( cy + radius ) / RoutingMatrix.m_GridRouting;
@@ -631,7 +630,6 @@
int  row_max, col_max, row_min, col_min;
int  demi_pas;

-    int  angle;
int  cx, cy, dx, dy;

RoutingMatrix.SetCellOperation( op_logic );
@@ -687,9 +685,10 @@
dx = ux1 - ux0;
dy = uy1 - uy0;

+    double angle;
if( dx )
{
-        angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
+        angle = ArcTangente( dy, dx );
}
else
{
@@ -758,7 +757,7 @@
int ii;
int angle;

-    radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) );
+    radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );

y0 = y1 = 0;
@@ -777,8 +776,8 @@
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 ) ) );
DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
x0 = x1;
y0 = y1;
@@ -793,17 +792,17 @@
* center = ux0,uy0, starting at ux1, uy1.  Coordinates are in
* PCB units.
*/
-void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
+void TraceArc( int ux0, int uy0, int ux1, int uy1, double ArcAngle, int lg,
LAYER_NUM layer, int color, int op_logic )
{
int x0, y0,             // Starting point of the current segment trace
x1, y1;             // End point
int ii;
-    int angle, StAngle;
-
-
-    radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) );
+    double angle, StAngle;
+
+
+    radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );

x0 = ux1 - ux0;
y0 = uy1 - uy0;
@@ -813,7 +812,7 @@
lg = 1;

nb_segm = ( 2 * radius ) / lg;
-    nb_segm = ( nb_segm * abs( ArcAngle ) ) / 3600;
+    nb_segm = ( nb_segm * std::abs( ArcAngle ) ) / 3600;

if( nb_segm < 5 )
nb_segm = 5;
@@ -826,14 +825,10 @@
angle  = ( ArcAngle * ii ) / nb_segm;
angle += StAngle;

-        while( angle >= 3600 )
-            angle -= 3600;
-
-        while( angle < 0 )
-            angle += 3600;
-
-        x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) );
-        y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) );
+        NORMALIZE_ANGLE_POS( angle );
+
DrawSegmentQcq( x0 + ux0, y0 + uy0, x1 + ux0, y1 + uy0, lg, layer, color, op_logic );
x0 = x1;
y0 = y1;

=== modified file 'pcbnew/autorouter/routing_matrix.cpp'
--- pcbnew/autorouter/routing_matrix.cpp	2013-04-04 21:35:01 +0000
+++ pcbnew/autorouter/routing_matrix.cpp	2013-04-29 10:51:16 +0000
@@ -317,12 +317,12 @@

TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge,
-                                  uy1 + marge, (int) (PtText->GetOrientation()),
+                                  uy1 + marge, PtText->GetOrientation(),

TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge,
ux1 + via_marge, uy1 + via_marge,
-                                  (int) (PtText->GetOrientation()),
+                                  PtText->GetOrientation(),
}
break;

=== modified file 'pcbnew/basepcbframe.cpp'
--- pcbnew/basepcbframe.cpp	2013-04-09 16:00:46 +0000
+++ pcbnew/basepcbframe.cpp	2013-04-29 12:25:30 +0000
@@ -563,14 +563,10 @@
dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x;
dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y;

-        if( dx==0 && dy==0 )
-            theta = 0.0;
-        else
-            theta = atan2( (double) -dy, (double) dx );
-
-        theta = theta * 180.0 / M_PI;
-
-        ro = sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
+        // atan2(0,0) gives 0
+        theta = RAD2DEG( atan2( (double) -dy, (double) dx ) );
+
+        ro = hypot( dx, dy );
wxString formatter;
switch( g_UserUnit )
{
@@ -661,7 +657,7 @@
#endif

// We already decided the formatter above
-        line.Printf( locformatter, dXpos, dYpos, sqrt( dXpos * dXpos + dYpos * dYpos ) );
+        line.Printf( locformatter, dXpos, dYpos, hypot( dXpos, dYpos ) );
SetStatusText( line, 3 );
}
}

=== modified file 'pcbnew/board_items_to_polygon_shape_transform.cpp'
--- pcbnew/board_items_to_polygon_shape_transform.cpp	2013-03-18 19:36:07 +0000
+++ pcbnew/board_items_to_polygon_shape_transform.cpp	2013-04-30 07:54:23 +0000
@@ -245,7 +245,7 @@
double                   aCorrectionFactor )
{
wxPoint corner_position;
-    int     angle;
+    double  angle;
int     dx = (m_Size.x / 2) + aClearanceValue;
int     dy = (m_Size.y / 2) + aClearanceValue;

@@ -404,7 +404,7 @@
int                   aMinThicknessValue,
int                   aCircleToSegmentsCount,
double                aCorrectionFactor,
-                                       int                   aThermalRot )
+                                       double                aThermalRot )
{
wxPoint corner, corner_end;
@@ -499,8 +499,8 @@

// Now, add the 4 holes ( each is the pattern, rotated by 0, 90, 180 and 270  deg
// aThermalRot = 450 (45.0 degrees orientation) work fine.
-            int th_angle  = aThermalRot;
+            double th_angle  = aThermalRot;

for( unsigned ihole = 0; ihole < 4; ihole++ )
{
@@ -604,7 +604,7 @@

/* Create 2 holes, rotated by pad rotation.
*/
-            int angle = aPad.GetOrientation() + supp_angle;
+            double angle = aPad.GetOrientation() + supp_angle;

for( int irect = 0; irect < 2; irect++ )
{
@@ -617,10 +617,7 @@
}

aCornerBuffer.back().end_contour = true;
-                angle += 1800;       // this is calculate hole 3
-
-                if( angle >= 3600 )
-                    angle -= 3600;
+                angle = ADD_ANGLES( angle, 1800 ); // this is calculate hole 3
}

// Create holes, that are the mirrored from the previous holes
@@ -645,10 +642,7 @@
}

aCornerBuffer.back().end_contour = true;
-                angle += 1800;
-
-                if( angle >= 3600 )
-                    angle -= 3600;
+                angle = ADD_ANGLES( angle, 1800 );
}
}
break;
@@ -692,7 +686,7 @@
corners_buffer.push_back( wxPoint( -copper_thickness.x / 2, -(dy - aThermalGap / 4) ) );
corners_buffer.push_back( wxPoint( -(aThermalGap / 4 + copper_thickness.x / 2), -dy ) );

int rounding_radius = (int) ( aThermalGap * aCorrectionFactor );    // Corner rounding radius
int angle_pg;                                                       // Polygon increment angle

@@ -721,10 +715,7 @@
}

aCornerBuffer.back().end_contour = true;
-                angle += 1800;       // this is calculate hole 3
-
-                if( angle >= 3600 )
-                    angle -= 3600;
+                angle = ADD_ANGLES( angle, 1800 );       // this is calculate hole 3
}

// Create holes, that are the mirrored from the previous holes
@@ -747,10 +738,7 @@
}

aCornerBuffer.back().end_contour = true;
-                angle += 1800;
-
-                if( angle >= 3600 )
-                    angle -= 3600;
+                angle = ADD_ANGLES( angle, 1800 );
}

}

=== modified file 'pcbnew/class_dimension.cpp'
--- pcbnew/class_dimension.cpp	2013-04-09 17:49:01 +0000
+++ pcbnew/class_dimension.cpp	2013-04-30 07:36:14 +0000
@@ -266,12 +266,12 @@
if( m_featureLineGO.y == m_crossBarO.y )
hy = 0;

-        angle_f     = angle + (M_PI * 27.5 / 180);
-        arrow_up_X  = (int) ( arrowz * cos( angle_f ) );
-        arrow_up_Y  = (int) ( arrowz * sin( angle_f ) );
-        angle_f     = angle - (M_PI * 27.5 / 180);
-        arrow_dw_X  = (int) ( arrowz * cos( angle_f ) );
-        arrow_dw_Y  = (int) ( arrowz * sin( angle_f ) );
+        angle_f     = angle + DEG2RAD( 27.5 );
+        arrow_up_X  = wxRound( arrowz * cos( angle_f ) );
+        arrow_up_Y  = wxRound( arrowz * sin( angle_f ) );
+        angle_f     = angle - DEG2RAD( 27.5 );
+        arrow_dw_X  = wxRound( arrowz * cos( angle_f ) );
+        arrow_dw_Y  = wxRound( arrowz * sin( angle_f ) );
}

m_arrowG1O.x    = m_crossBarO.x;
@@ -310,13 +310,9 @@
textPos.y  = (m_crossBarF.y + m_featureLineGF.y) / 2;
m_Text.SetTextPosition( textPos );

-    double newAngle = -(angle * 1800 / M_PI);
-
-    if( newAngle < 0 )
-        newAngle += 3600;
-
-    if( newAngle >= 3600 )
-        newAngle -= 3600;
+    double newAngle = -RAD2DEG10( angle );
+
+    NORMALIZE_ANGLE_POS( newAngle );

if( newAngle > 900  &&  newAngle < 2700 )
newAngle -= 1800;

=== modified file 'pcbnew/class_drawsegment.cpp'
--- pcbnew/class_drawsegment.cpp	2013-04-18 17:03:47 +0000
+++ pcbnew/class_drawsegment.cpp	2013-04-30 07:51:35 +0000
@@ -45,6 +45,7 @@

#include <pcbnew.h>
#include <protos.h>
+#include <math_for_graphics.h>

#include <class_board.h>
#include <class_module.h>
@@ -138,16 +139,13 @@
const double DRAWSEGMENT::GetArcAngleStart() const
{
// due to the Y axis orient atan2 needs - y value
-    double angleStart = atan2( (double)(GetArcStart().y - GetCenter().y),
-                               (double)(GetArcStart().x - GetCenter().x) );
-    // angleStart is in radians, convert it in 1/10 degrees
-    angleStart = angleStart / M_PI * 1800.0;
+    double angleStart = ArcTangente( GetArcStart().y - GetCenter().y,
+                                     GetArcStart().x - GetCenter().x );

// Normalize it to 0 ... 360 deg, to avoid discontinuity for angles near 180 deg
// because 180 deg and -180 are very near angles when ampping betewwen -180 ... 180 deg.
// and this is not easy to handle in calculations
-    if( angleStart < 0 )
-        angleStart += 3600.0;
+    NORMALIZE_ANGLE_POS( angleStart );

return angleStart;
}
@@ -156,7 +154,7 @@
{
NORMALIZE_ANGLE_360( aAngle );

-    m_Angle = (int) aAngle;
+    m_Angle = aAngle;
}

@@ -215,7 +213,7 @@
switch( m_Shape )
{
case S_CIRCLE:
-        radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
+        radius = KiROUND( Distance( ux0, uy0, dx, dy ) );

if( mode == LINE )
{
@@ -234,9 +232,9 @@
break;

case S_ARC:
-        int StAngle, EndAngle;
-        radius    = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
-        StAngle  = (int) ArcTangente( dy - uy0, dx - ux0 );
+        double StAngle, EndAngle;
+        radius   = KiROUND( Distance( ux0, uy0, dx, dy ) );
+        StAngle  = ArcTangente( dy - uy0, dx - ux0 );
EndAngle = StAngle + m_Angle;

if( !panel->GetPrintMirrored() )
@@ -336,7 +334,7 @@

case S_ARC:
aList.push_back( MSG_PANEL_ITEM( shape, _( "Arc" ), RED ) );
-        msg.Printf( wxT( "%.1f" ), (double)m_Angle/10 );
+        msg.Printf( wxT( "%.1f" ), m_Angle / 10 );
aList.push_back( MSG_PANEL_ITEM( _("Angle"), msg, RED ) );
break;

@@ -434,7 +432,7 @@
{
wxPoint relPos = aPosition - GetCenter();
-            int dist  = (int) hypot( (double) relPos.x, (double) relPos.y );
+            int dist   = KiROUND( EuclideanNorm( relPos ) );

if( abs( radius - dist ) <= ( m_Width / 2 ) )
{
@@ -449,8 +447,7 @@
// and > arc angle if arc angle < 0 (CCW arc)
double arc_angle_start = GetArcAngleStart();    // Always 0.0 ... 360 deg, in 0.1 deg

-                double arc_hittest = atan2( (double) relPos.y, (double) relPos.x );
-                arc_hittest = arc_hittest / M_PI * 1800;    // angles are in 1/10 deg
+                double arc_hittest = ArcTangente( relPos.y, relPos.x );

// Calculate relative angle between the starting point of the arc, and the test point
arc_hittest -= arc_angle_start;

=== modified file 'pcbnew/class_drawsegment.h'
--- pcbnew/class_drawsegment.h	2013-01-12 17:32:24 +0000
+++ pcbnew/class_drawsegment.h	2013-04-29 20:04:55 +0000
@@ -33,6 +33,8 @@

#include <class_board_item.h>
#include <PolyLine.h>
+#include <math_for_graphics.h>
+#include <trigo.h>

@@ -134,7 +136,7 @@
*/
{
-        double radius = hypot( (double) (m_End.x - m_Start.x), (double) (m_End.y - m_Start.y) );
+        double radius = GetLineLength( m_Start, m_End );
}

@@ -184,9 +186,7 @@
*/
double  GetLength() const
{
-        wxPoint delta = GetEnd() - GetStart();
-
-        return hypot( double( delta.x ), double( delta.y ) );
+        return GetLineLength( GetStart(), GetEnd() );
}

virtual void Move( const wxPoint& aMoveVector )

=== modified file 'pcbnew/class_edge_mod.cpp'
--- pcbnew/class_edge_mod.cpp	2013-04-09 17:49:01 +0000
+++ pcbnew/class_edge_mod.cpp	2013-04-29 17:46:14 +0000
@@ -40,6 +40,7 @@
#include <colors_selection.h>
#include <richio.h>
#include <macros.h>
+#include <math_for_graphics.h>
#include <wxBasePcbFrame.h>
#include <pcbcommon.h>
#include <msgpanel.h>
@@ -163,7 +164,7 @@
break;

case S_CIRCLE:
-        radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
+        radius = KiROUND( Distance( ux0, uy0, dx, dy ) );

if( typeaff == LINE )
{
@@ -185,8 +186,8 @@
break;

case S_ARC:
-        radius   = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
-        StAngle  = (int) ArcTangente( dy - uy0, dx - ux0 );
+        radius   = KiROUND( Distance( ux0, uy0, dx, dy ) );
+        StAngle  = ArcTangente( dy - uy0, dx - ux0 );
EndAngle = StAngle + m_Angle;

if( StAngle > EndAngle )

=== modified file 'pcbnew/class_module.cpp'
--- pcbnew/class_module.cpp	2013-04-25 16:29:35 +0000
+++ pcbnew/class_module.cpp	2013-04-29 11:09:39 +0000
@@ -495,7 +495,7 @@

aList.push_back( MSG_PANEL_ITEM( _( "Stat" ), msg, MAGENTA ) );

-    msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 );
+    msg.Printf( wxT( "%.1f" ), m_Orient / 10 );
aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), msg, BROWN ) );

// Controls on right side of the dialog

@@ -551,14 +551,14 @@
aList.push_back( MSG_PANEL_ITEM( _( "Drill X / Y" ), Line, RED ) );
}

-    int module_orient = module ? module->GetOrientation() : 0;
+    double module_orient = module ? module->GetOrientation() : 0;

if( module_orient )
Line.Printf( wxT( "%3.1f(+%3.1f)" ),
-                     (double) ( m_Orient - module_orient ) / 10,
-                     (double) module_orient / 10 );
+                     ( m_Orient - module_orient ) / 10,
+                     module_orient / 10 );
else
-        Line.Printf( wxT( "%3.1f" ), (double) m_Orient / 10 );
+        Line.Printf( wxT( "%3.1f" ), m_Orient / 10 );

aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), Line, LIGHTBLUE ) );

@@ -586,7 +586,6 @@
bool D_PAD::HitTest( const wxPoint& aPosition )
{
int     dx, dy;
-    double  dist;

wxPoint shape_pos = ReturnShapePos();

@@ -604,9 +603,7 @@
{
-        dist = hypot( delta.x, delta.y );
-
-        if( KiROUND( dist ) <= dx )
+        if( KiROUND( EuclideanNorm( delta ) ) <= dx )
return true;

break;

@@ -298,7 +298,7 @@
*                        inflate, < 0 deflate
* @param aRotation = full rotation of the polygon
*/
-    void BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const;
+    void BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, double aRotation ) const;

/**
* Function BuildSegmentFromOvalShape

@@ -311,7 +311,7 @@
{
wxPoint coord[4];
int     delta_cx, delta_cy;
-    int     angle = m_Orient;
+    double  angle = m_Orient;
int     seg_width;

@@ -527,8 +527,8 @@
RotatePoint( &tpos, shape_pos, angle );

-    /* Draw text with an angle between -90 deg and + 90 deg */
-    int t_angle = angle;
+    // Draw text with an angle between -90 deg and + 90 deg
+    double t_angle = angle;
NORMALIZE_ANGLE_90( t_angle );

/* Note: in next calculations, texte size is calculated for 3 or more
@@ -628,7 +628,7 @@
}

{
return;

=== modified file 'pcbnew/class_pcb_text.cpp'
--- pcbnew/class_pcb_text.cpp	2013-04-29 16:35:07 +0000
+++ pcbnew/class_pcb_text.cpp	2013-04-30 06:25:04 +0000
@@ -136,7 +136,7 @@
else
aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );

-    msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 );
+    msg.Printf( wxT( "%.1f" ), m_Orient / 10 );
aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, DARKGREEN ) );

msg = ::CoordinateToString( m_Thickness );

=== modified file 'pcbnew/class_text_mod.cpp'
--- pcbnew/class_text_mod.cpp	2013-04-09 17:49:01 +0000
+++ pcbnew/class_text_mod.cpp	2013-04-29 11:10:52 +0000
@@ -144,7 +144,7 @@

m_Pos0 = m_Pos - module->GetPosition();

-    int angle = module->GetOrientation();
+    double angle = module->GetOrientation();

RotatePoint( &m_Pos0.x, &m_Pos0.y, -angle );
}
@@ -206,7 +206,7 @@
{
// Calculate area without text fields:
EDA_RECT text_area;
-    int      angle = GetDrawRotation();
+    double   angle = GetDrawRotation();
wxPoint  textstart, textend;

text_area = GetTextRect();
@@ -294,7 +294,7 @@

// Draw the text proper, with the right attributes
wxSize size   = m_Size;
-    int    orient = GetDrawRotation();
+    double orient = GetDrawRotation();

// If the text is mirrored : negate size.x (mirror / Y axis)
if( m_Mirror )
@@ -324,12 +324,10 @@

/* Return text rotation for drawings and plotting
*/
-int TEXTE_MODULE::GetDrawRotation() const
+double TEXTE_MODULE::GetDrawRotation() const
{
-    int     rotation;
MODULE* module = (MODULE*) m_Parent;
-
-    rotation = m_Orient;
+    double  rotation = m_Orient;

if( module )
rotation += module->GetOrientation();
@@ -385,7 +383,7 @@

aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );

-    msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 );
+    msg.Printf( wxT( "%.1f" ), m_Orient / 10 );
aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), msg, DARKGREEN ) );

msg = ::CoordinateToString( m_Thickness );

=== modified file 'pcbnew/class_text_mod.h'
--- pcbnew/class_text_mod.h	2013-04-07 11:55:18 +0000
+++ pcbnew/class_text_mod.h	2013-04-29 10:33:17 +0000
@@ -98,7 +98,7 @@

int GetLength() const;        // text length

-    int GetDrawRotation() const;  // Return text rotation for drawings and plotting
+    double GetDrawRotation() const;  // Return text rotation for drawings and plotting

/**
* Function GetTextRect

=== modified file 'pcbnew/class_track.cpp'
--- pcbnew/class_track.cpp	2013-04-28 15:43:26 +0000
+++ pcbnew/class_track.cpp	2013-04-30 09:25:28 +0000
@@ -33,6 +33,7 @@
#include <gr_basic.h>
#include <common.h>
#include <trigo.h>
+#include <macros.h>
#include <class_drawpanel.h>
#include <class_pcb_screen.h>
#include <drawtxt.h>
@@ -295,7 +296,7 @@
{
double dist = hypot( (double)dx, (double) dy );

-        if( min_dist >= (int) dist )
+        if( min_dist >= KiROUND( dist ) )
result |= STARTPOINT;
}

@@ -311,7 +312,7 @@
{
double dist = hypot( (double) dx, (double) dy );

-        if( min_dist >= (int) dist )
+        if( min_dist >= KiROUND( dist ) )
result |= ENDPOINT;
}

@@ -618,8 +619,7 @@

if( m_Shape == S_CIRCLE )
{
-        radius = (int) hypot( (double) ( m_End.x - m_Start.x ),
-                              (double) ( m_End.y - m_Start.y ) );
+        radius = KiROUND( GetLineLength( m_Start, m_End ) );

if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
{
@@ -691,7 +691,7 @@

#define THRESHOLD 10

-    int len = int( hypot( (m_End.x - m_Start.x), (m_End.y - m_Start.y) ) );
+    int len = KiROUND( GetLineLength( m_Start, m_End ) );

if( len < THRESHOLD * m_Width )
return;
@@ -722,7 +722,7 @@

// Calculate angle: if the track segment is vertical, angle = 90 degrees
// If horizontal 0 degrees, otherwise compute it
-        int angle;                              // angle is in 0.1 degree
+        double angle;                              // angle is in 0.1 degree

if( dy == 0 )        // Horizontal segment
{
@@ -736,9 +736,9 @@
}
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 = RAD2DEG10( -atan( double( dy )/ double( dx ) ) );
}
}

=== modified file 'pcbnew/class_track.h'
--- pcbnew/class_track.h	2013-04-09 17:16:53 +0000
+++ pcbnew/class_track.h	2013-04-29 17:41:18 +0000
@@ -34,6 +34,7 @@
#include <class_board_item.h>
#include <class_board_connected_item.h>
#include <PolyLine.h>
+#include <trigo.h>

class TRACK;
@@ -155,10 +156,7 @@
*/
double GetLength() const
{
-        double dx = m_Start.x - m_End.x;
-        double dy = m_Start.y - m_End.y;
-
-        return hypot( dx, dy );
+        return GetLineLength( m_Start, m_End );
}

/* Display on screen: */

=== modified file 'pcbnew/connect.cpp'
--- pcbnew/connect.cpp	2013-03-30 17:24:04 +0000
+++ pcbnew/connect.cpp	2013-04-29 12:05:13 +0000
@@ -348,7 +348,7 @@
// We have a good candidate: calculate the actual distance
// between ends, which should be <= dist max.
wxPoint delta = tracks_candidates[ii]->GetPoint() - position;
-            int dist = (int) hypot( (double) delta.x, (double) delta.y );
+            int dist = KiROUND( EuclideanNorm( delta ) );

if( dist > dist_max )
continue;

=== modified file 'pcbnew/dialogs/dialog_SVG_print.cpp'
--- pcbnew/dialogs/dialog_SVG_print.cpp	2013-04-25 07:05:33 +0000
+++ pcbnew/dialogs/dialog_SVG_print.cpp	2013-04-30 12:05:40 +0000
@@ -36,6 +36,7 @@
#include <base_units.h>
#include <convert_from_iu.h>
#include <wildcards_and_files_ext.h>
+#include <macros.h>

#include <pcbnew.h>
#include <pcbplot.h>

=== modified file 'pcbnew/dialogs/dialog_design_rules.cpp'
--- pcbnew/dialogs/dialog_design_rules.cpp	2013-03-04 16:04:53 +0000
+++ pcbnew/dialogs/dialog_design_rules.cpp	2013-04-30 11:42:44 +0000
@@ -40,6 +40,7 @@

#include <pcbnew_id.h>
#include <class_track.h>
+#include <macros.h>

#include <dialog_design_rules.h>
#include <wx/generic/gridctrl.h>

=== modified file 'pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp'
--- pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp	2013-04-28 13:34:59 +0000
+++ pcbnew/dialogs/dialog_edit_module_for_Modedit.cpp	2013-04-30 11:50:22 +0000
@@ -41,6 +41,7 @@
#include <3d_viewer.h>
#include <wxPcbStruct.h>
#include <base_units.h>
+#include <macros.h>

#include <class_module.h>
#include <class_text_mod.h>

=== modified file 'pcbnew/dialogs/dialog_edit_module_text.cpp'
--- pcbnew/dialogs/dialog_edit_module_text.cpp	2013-04-25 16:29:35 +0000
+++ pcbnew/dialogs/dialog_edit_module_text.cpp	2013-04-29 10:51:16 +0000
@@ -122,7 +122,7 @@
msg.Printf( format,
GetChars( m_module->GetReference() ),
GetChars( m_module->GetValue() ),
-                    (float) m_module->GetOrientation() / 10 );
+                    m_module->GetOrientation() / 10 );
}
else
{
@@ -165,7 +165,7 @@
PutValueInLocalUnits( *m_TxtWidthCtlr, m_currentText->GetThickness() );

-    int text_orient = m_currentText->GetOrientation();
+    double text_orient = m_currentText->GetOrientation();
NORMALIZE_ANGLE_90( text_orient );

if( (text_orient != 0) )

=== modified file 'pcbnew/dialogs/dialog_gendrill.cpp'
--- pcbnew/dialogs/dialog_gendrill.cpp	2013-04-28 09:10:54 +0000
+++ pcbnew/dialogs/dialog_gendrill.cpp	2013-04-30 11:55:05 +0000
@@ -32,6 +32,7 @@
#include <wxPcbStruct.h>
#include <pcbplot.h>
#include <gendrill_Excellon_writer.h>
+#include <macros.h>

#include <class_board.h>
#include <class_track.h>

=== modified file 'pcbnew/dialogs/dialog_graphic_item_properties.cpp'
--- pcbnew/dialogs/dialog_graphic_item_properties.cpp	2013-04-09 16:00:46 +0000
+++ pcbnew/dialogs/dialog_graphic_item_properties.cpp	2013-04-30 14:01:36 +0000
@@ -126,7 +126,10 @@
m_StartPointYLabel->SetLabel(_("Center Y"));
m_EndPointXLabel->SetLabel(_("Start Point X"));
m_EndPointYLabel->SetLabel(_("Start Point Y"));
-        msg << m_Item->GetAngle();
+
+        // Here the angle is a double, but the UI is still working
+        // with integers
+        msg << int( m_Item->GetAngle() );
m_Angle_Ctrl->SetValue(msg);
break;

=== modified file 'pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp'
--- pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp	2013-04-09 16:00:46 +0000
+++ pcbnew/dialogs/dialog_graphic_item_properties_for_Modedit.cpp	2013-04-30 14:02:00 +0000
@@ -128,7 +128,9 @@
m_StartPointYLabel->SetLabel(_("Center Y"));
m_EndPointXLabel->SetLabel(_("Start Point X"));
m_EndPointYLabel->SetLabel(_("Start Point Y"));
-        msg << m_item->GetAngle();
+        // Here the angle is a double, but the UI is still working
+        // with integers
+        msg << int( m_item->GetAngle() );
m_Angle_Ctrl->SetValue(msg);
break;

=== modified file 'pcbnew/dialogs/dialog_orient_footprints.cpp'
--- pcbnew/dialogs/dialog_orient_footprints.cpp	2013-04-25 16:29:35 +0000
+++ pcbnew/dialogs/dialog_orient_footprints.cpp	2013-04-29 11:25:51 +0000
@@ -110,12 +110,13 @@
}

-bool PCB_EDIT_FRAME::ReOrientModules( const wxString& ModuleMask, int Orient, bool include_fixe )
+bool PCB_EDIT_FRAME::ReOrientModules( const wxString& ModuleMask, double Orient,
+                                      bool include_fixe )
{
wxString line;
bool modified = false;

-    line.Printf( _( "OK to set footprints orientation to %.1f degrees ?" ), (double)Orient / 10 );
+    line.Printf( _( "OK to set footprints orientation to %.1f degrees ?" ), Orient / 10 );

if( !IsOK( this, line ) )
return false;

@@ -280,7 +280,7 @@
m_staticModuleSideValue->SetLabel( _( "Back side (footprint is mirrored)" ) );
}

-        msg.Printf( wxT( "%.1f" ), (double) module->GetOrientation() / 10 );
+        msg.Printf( wxT( "%.1f" ), module->GetOrientation() / 10 );
m_staticModuleRotValue->SetLabel( msg );
}

=== modified file 'pcbnew/dragsegm.cpp'
--- pcbnew/dragsegm.cpp	2013-03-30 17:24:04 +0000
+++ pcbnew/dragsegm.cpp	2013-04-30 12:11:37 +0000
@@ -34,6 +34,7 @@
#include <gr_basic.h>
#include <class_drawpanel.h>
#include <wxBasePcbFrame.h>
+#include <macros.h>

#include <drag.h>
#include <pcbnew.h>
@@ -359,7 +360,7 @@

if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist )
{
-                int dist = (int) hypot( (double) delta.x, (double) delta.y );
+                int dist = KiROUND( EuclideanNorm( delta ) );

if( dist <= maxdist )
{
@@ -377,7 +378,7 @@

if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist )
{
-                int dist = (int) hypot( (double) delta.x, (double) delta.y );
+                int dist = KiROUND( EuclideanNorm( delta ) );

if( dist <= maxdist )
flag |= ENDPOINT;

=== modified file 'pcbnew/drc_clearance_test_functions.cpp'
--- pcbnew/drc_clearance_test_functions.cpp	2013-03-31 13:27:46 +0000
+++ pcbnew/drc_clearance_test_functions.cpp	2013-04-30 07:52:52 +0000
@@ -354,15 +354,13 @@
// If the reference segment is a via, we test it here
if( aRefSeg->Type() == PCB_VIA_T )
{
-            int angle = 0;  // angle du segment a tester;
-
delta = track->GetEnd() - track->GetStart();
segStartPoint = aRefSeg->GetStart() - track->GetStart();

if( track->Type() == PCB_VIA_T )
{
// Test distance between two vias, i.e. two circles, trivial case
-                if( (int) hypot( segStartPoint.x, segStartPoint.y ) < w_dist )
+                if( EuclideanNorm( segStartPoint ) < w_dist )
{
m_currentMarker = fillMarker( aRefSeg, track,
DRCE_VIA_NEAR_VIA, m_currentMarker );
@@ -371,8 +369,8 @@
}
else    // test via to segment
{
-                // Compute l'angle
-                angle = ArcTangente( delta.y, delta.x );
+                // Compute l'angle du segment a tester;
+                double angle = ArcTangente( delta.y, delta.x );

// Compute new coordinates ( the segment become horizontal)
RotatePoint( &delta, angle );
@@ -527,8 +525,8 @@
segEndPoint   = track->GetEnd();
delta = segEndPoint - segStartPoint;

-                    /* Compute the segment orientation (angle) en 0,1 degre */
-                    int angle = ArcTangente( delta.y, delta.x );
+                    // Compute the segment orientation (angle) en 0,1 degre
+                    double angle = ArcTangente( delta.y, delta.x );

// Compute the segment lenght: delta.x = lenght after rotation
RotatePoint( &delta, angle );
@@ -572,7 +570,7 @@
{
int     dist;

// Get the clerance between the 2 pads. this is the min distance between aRefPad and aPad
@@ -580,7 +578,7 @@

+    dist = KiROUND( EuclideanNorm( relativePadPos ) );

// Quick test: Clearance is OK if the bounding circles are further away than "dist_min"
@@ -804,7 +802,7 @@
{
-    int     orient;
+    double  orient;
wxPoint startPoint, endPoint;
int     seuil;
int     deltay;
@@ -868,10 +866,7 @@
{
-            orient += 900;
-
-            if( orient >= 3600 )
-                orient -= 3600;
+            orient = ADD_ANGLES( orient, 900 );
}

@@ -1017,7 +1012,7 @@
if( aCentre.x > aLength )   // aCentre is after the ending point
aCentre.x -= aLength;   // move aCentre to the starting point of the segment

-        if( hypot( aCentre.x, aCentre.y ) < aRadius )
+        if( EuclideanNorm( aCentre ) < aRadius )
// distance between aCentre and the starting point or the ending point is < aRadius
return false;
}

=== modified file 'pcbnew/drc_marker_functions.cpp'
--- pcbnew/drc_marker_functions.cpp	2013-01-13 00:04:00 +0000
+++ pcbnew/drc_marker_functions.cpp	2013-04-29 12:08:15 +0000
@@ -77,10 +77,8 @@
// distance from end of aTrack.
position = track->GetStart();

-            double dToEnd = hypot( endPos.x - aTrack->GetEnd().x,
-                                   endPos.y - aTrack->GetEnd().y );
-            double dToStart = hypot( position.x - aTrack->GetEnd().x,
-                                     position.y - aTrack->GetEnd().y );
+            double dToEnd = GetLineLength( endPos, aTrack->GetEnd() );
+            double dToStart = GetLineLength( position, aTrack->GetEnd() );

if( dToEnd < dToStart )
position = endPos;

=== modified file 'pcbnew/drc_stuff.h'
--- pcbnew/drc_stuff.h	2012-09-12 17:28:55 +0000
+++ pcbnew/drc_stuff.h	2013-04-29 11:13:00 +0000
@@ -179,7 +179,7 @@
* so we store the ref segment length (the end point relative to these axis)
* and the segment orientation (used to rotate other coordinates)
*/
-    int m_segmAngle;        // Ref segm orientation in 0,1 degre
+    double m_segmAngle;     // Ref segm orientation in 0,1 degre
int m_segmLength;       // length of the reference segment

/* variables used in checkLine to test DRC segm to segm:

=== modified file 'pcbnew/edgemod.cpp'
--- pcbnew/edgemod.cpp	2013-04-09 16:00:46 +0000
+++ pcbnew/edgemod.cpp	2013-04-29 10:21:40 +0000
@@ -314,7 +314,6 @@
STROKE_T     type_edge )
{
MODULE* module = GetBoard()->m_Modules;
-    int     angle  = 0;

if( module == NULL )
return NULL;
@@ -331,7 +330,7 @@

// Update characteristics of the segment or arc.
aEdge->SetFlags( IS_NEW );
-        aEdge->SetAngle( angle );
+        aEdge->SetAngle( 0 );
aEdge->SetShape( type_edge );

if( aEdge->GetShape() == S_ARC )

=== modified file 'pcbnew/editedge.cpp'
--- pcbnew/editedge.cpp	2013-04-09 17:49:01 +0000
+++ pcbnew/editedge.cpp	2013-04-30 12:15:10 +0000
@@ -37,6 +37,7 @@

#include <pcbnew.h>
#include <protos.h>
+#include <macros.h>

#include <class_board.h>
#include <class_drawsegment.h>

=== modified file 'pcbnew/edtxtmod.cpp'
--- pcbnew/edtxtmod.cpp	2013-04-07 11:55:18 +0000
+++ pcbnew/edtxtmod.cpp	2013-04-29 10:51:16 +0000
@@ -54,7 +54,7 @@
// to dialog_edit mod_text.cpp
static wxPoint TextInitialPosition;     // Mouse cursor initial position for
// undo/abort move command
-static int     TextInitialOrientation;  // module text initial orientation for
+static double  TextInitialOrientation;  // module text initial orientation for
// undo/abort move+rot command+rot

@@ -233,7 +233,7 @@
if( Module )
{
// Prepare undo command (a rotation can be made while moving)
-            int tmp = Text->GetOrientation();
+            double tmp = Text->GetOrientation();
Text->SetOrientation( TextInitialOrientation );

if( IsType( PCB_FRAME_TYPE ) )

@@ -498,7 +498,6 @@
MODULE*     module;
const char* layer;
-    int         orient;
wxString    pinname;
const char* mirror = "0";

@@ -531,7 +530,7 @@
if( pinname.IsEmpty() )
pinname = wxT( "none" );

-            orient = pad->GetOrientation() - module->GetOrientation();
+            double orient = pad->GetOrientation() - module->GetOrientation();
NORMALIZE_ANGLE_POS( orient );

// Bottom side modules use the flipped padstack
@@ -563,7 +562,7 @@
TEXTE_MODULE* textmod;
const char*   mirror;
const char*   flip;
-        int           orient = module->GetOrientation();
+        double        orient = module->GetOrientation();

if( module->GetFlag() )
{
@@ -598,7 +597,7 @@

for( int ii = 0; ii < 2; ii++ )
{
-            int      orient = textmod->GetOrientation();
+            double   orient = textmod->GetOrientation();
SILKSCREEN_N_BACK : SILKSCREEN_N_FRONT];

@@ -1058,9 +1057,7 @@

case S_CIRCLE:
{
-                    int radius = (int) hypot(
-                        (double) ( PtEdge->m_End0.x - PtEdge->m_Start0.x ),
-                        (double) ( PtEdge->m_End0.y - PtEdge->m_Start0.y ) );
+                    int radius = KiROUND( GetLineLength( PtEdge->m_End0, PtEdge->m_Start0 ) );
fprintf( aFile, "CIRCLE %g %g %g\n",
PtEdge->m_Start0.x / SCALE_FACTOR,
Yaxis_sign * PtEdge->m_Start0.y / SCALE_FACTOR,

=== modified file 'pcbnew/export_vrml.cpp'
--- pcbnew/export_vrml.cpp	2013-04-04 21:35:01 +0000
+++ pcbnew/export_vrml.cpp	2013-04-30 07:20:09 +0000
@@ -420,7 +420,7 @@

static void export_vrml_slot( TRIANGLEBAG& triangles, //{{{
LAYER_NUM top_layer, LAYER_NUM bottom_layer, double xc, double yc,
-                              double dx, double dy, int orient )
+                              double dx, double dy, double orient )
{
double capx, capy; // Cap center
VLoop  loop;
@@ -428,7 +428,7 @@

loop.z_top    = layer_z[top_layer];
loop.z_bottom = layer_z[bottom_layer];
-    double angle = orient / 1800.0 * M_PI;
+    double angle  = DEG2RAD10( orient );

if( dy > dx )
{
@@ -479,14 +479,14 @@

static void export_vrml_oval_pad( LAYER_NUM layer, double xc, double yc,
-                                  double dx, double dy, int orient )
+                                  double dx, double dy, double orient )
{
double  capx, capy; // Cap center
FLAT_FAN fan;

fan.c.x = xc;
fan.c.y = yc;
-    double angle = orient / 1800.0 * M_PI;
+    double angle = DEG2RAD10( orient );
int divisions = SEGM_COUNT_PER_360 / 2;

if( dy > dx )
@@ -538,7 +538,7 @@

double divisions = arc_angle*M_PI/180.0 / count;

-    double outer_radius = hypot( arc_starty - centery, arc_startx - centerx )
+    double outer_radius = Distance( arc_startx, arc_starty, centerx, centery )
+ ( width / 2);

@@ -568,7 +568,7 @@
loop.z_bottom = layer_z[bottom_layer];

double start_angle = atan2( arc_starty - centery, arc_startx - centerx );
-    double radius = hypot( arc_starty - centery, arc_startx - centerx );
+    double radius = Distance( arc_startx, arc_starty, centerx, centery );

int count = KiROUND( arc_angle / 360.0 * SEGM_COUNT_PER_360 );

@@ -617,7 +617,7 @@
case S_CIRCLE:
export_vrml_hole( layer_triangles[layer],
FIRST_COPPER_LAYER, LAST_COPPER_LAYER, x, y,
-                              hypot( xf - x, yf - y ) / 2 );
+                              Distance( xf, yf, x, y ) / 2 );
break;

default:
@@ -905,7 +905,8 @@
// Oblong hole (slot)
export_vrml_slot( layer_triangles[EDGE_N],
FIRST_COPPER_LAYER, LAST_COPPER_LAYER,
-                              hole_x, hole_y, hole_drill_w, hole_drill_h, aPad->GetOrientation() );
+                              hole_x, hole_y, hole_drill_w, hole_drill_h,
}
else
{
@@ -1109,15 +1110,15 @@

// Do some quaternion munching
double q1[4], q2[4], rot[4];
-        build_quat( 1, 0, 0, rotx / 180.0 * M_PI, q1 );
-        build_quat( 0, 1, 0, roty / 180.0 * M_PI, q2 );
+        build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
+        build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
compose_quat( q1, q2, q1 );
-        build_quat( 0, 0, 1, rotz / 180.0 * M_PI, q2 );
+        build_quat( 0, 0, 1, DEG2RAD( rotz ), q2 );
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, DEG2RAD10( aModule->GetOrientation() ), q2 );
compose_quat( q1, q2, q1 );
from_quat( q1, rot );

@@ -1140,7 +1141,7 @@
else    // In normal mode, Y axis is reversed in Pcbnew.
NEGATE(offsety);

-        RotatePoint(&offsetx, &offsety, aModule->GetOrientation());
+        RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );

fprintf( aOutputFile, "  translation %g %g %g\n",
(offsetx + aModule->GetPosition().x) * boardIU2WRML,

=== modified file 'pcbnew/footprint_wizard_frame.cpp'
--- pcbnew/footprint_wizard_frame.cpp	2013-03-16 03:27:48 +0000
+++ pcbnew/footprint_wizard_frame.cpp	2013-04-30 12:09:25 +0000
@@ -35,6 +35,7 @@
#include <3d_viewer.h>
#include <pcbcommon.h>
#include <msgpanel.h>
+#include <macros.h>

#include <class_board.h>
#include <class_module.h>

=== modified file 'pcbnew/gen_drill_report_files.cpp'
--- pcbnew/gen_drill_report_files.cpp	2013-03-31 13:27:46 +0000
+++ pcbnew/gen_drill_report_files.cpp	2013-04-30 12:31:29 +0000
@@ -34,6 +34,7 @@
#include <drawtxt.h>
#include <confirm.h>
+#include <macros.h>

#include <class_board.h>

=== modified file 'pcbnew/gen_modules_placefile.cpp'
--- pcbnew/gen_modules_placefile.cpp	2013-04-10 07:23:20 +0000
+++ pcbnew/gen_modules_placefile.cpp	2013-04-29 12:20:22 +0000
@@ -485,7 +485,7 @@
sprintf( text, " %9.4f  %9.4f  %8.1f    ",
module_pos.x * conv_unit,
-module_pos.y * conv_unit,
-                 double(list[ii].m_Module->GetOrientation()) / 10 );
+                 list[ii].m_Module->GetOrientation() / 10 );

LAYER_NUM layer = list[ii].m_Module->GetLayer();

@@ -640,7 +640,7 @@
module_pos.y * conv_unit );
fputs( line, rptfile );

-            sprintf( line, "orientation  %.2f\n", (double) Module->GetOrientation() / 10 );
+            sprintf( line, "orientation  %.2f\n", Module->GetOrientation() / 10 );

if( Module->GetLayer() == LAYER_N_FRONT )
strcat( line, "layer component\n" );
@@ -675,7 +675,7 @@
fputs( line, rptfile );

sprintf( line, "orientation  %.2f\n",
-                         double(pad->GetOrientation() - Module->GetOrientation()) / 10 );
+                         (pad->GetOrientation() - Module->GetOrientation()) / 10 );
fputs( line, rptfile );

static const char* shape_name[6] = { "???", "Circ", "Rect", "Oval", "Trap", "Spec" };
@@ -751,7 +751,7 @@
switch( PtDrawSegment->GetShape() )
{
case S_CIRCLE:
-        radius = hypot( dx - ux0, dy - uy0 );
+        radius = Distance( ux0, uy0, dx, dy );
fprintf( rptfile, "\$CIRCLE \n" );
fprintf( rptfile, "centre %.6lf %.6lf\n", ux0, uy0 );
@@ -764,7 +764,7 @@
int endx = PtDrawSegment->GetEnd().x;
int endy = PtDrawSegment->GetEnd().y;

-            radius = hypot( dx - ux0, dy - uy0 );
+            radius = Distance( ux0, uy0, dx, dy );
RotatePoint( &endx,
&endy,
PtDrawSegment->GetStart().x,

=== modified file 'pcbnew/gendrill_Excellon_writer.cpp'
--- pcbnew/gendrill_Excellon_writer.cpp	2013-03-18 19:36:07 +0000
+++ pcbnew/gendrill_Excellon_writer.cpp	2013-04-30 12:36:31 +0000
@@ -39,6 +39,7 @@

#include <plot_common.h>
#include <trigo.h>
+#include <macros.h>
#include <wxPcbStruct.h>
#include <appl_wxstruct.h>

=== modified file 'pcbnew/gendrill_Excellon_writer.h'
--- pcbnew/gendrill_Excellon_writer.h	2013-04-28 09:10:54 +0000
+++ pcbnew/gendrill_Excellon_writer.h	2013-04-29 11:07:13 +0000
@@ -67,7 +67,7 @@
int m_Hole_Diameter;            // hole value, and for oblong: min(hole size x, hole size y)
int m_Tool_Reference;           // Tool reference for this hole = 1 ... n (values <=0 must not be used)
wxSize m_Hole_Size;             // hole size for oblong holes
-    int m_Hole_Orient;              // Hole rotation (= pad rotation) for oblong holes
+    double m_Hole_Orient;           // Hole rotation (= pad rotation) for oblong holes
int m_Hole_Shape;               // hole shape: round (0) or oval (1)
wxPoint m_Hole_Pos;             // hole position
LAYER_NUM m_Hole_Bottom_Layer;  // hole starting layer (usually back layer)

@@ -229,7 +229,7 @@

// Search and copy the name of library reference.
MODULE* Module_Ref = module;

// Prepare an undo list:
if( aSaveForUndo )
@@ -252,7 +252,7 @@
continue;

continue;

=== modified file 'pcbnew/gpcb_plugin.cpp'
--- pcbnew/gpcb_plugin.cpp	2013-04-10 15:08:01 +0000
+++ pcbnew/gpcb_plugin.cpp	2013-04-29 12:09:50 +0000
@@ -564,7 +564,7 @@

wxPoint padPos( (x1 + x2) / 2, (y1 + y2) / 2 );

-            pad->SetSize( wxSize( KiROUND( hypot( (double)delta.x, (double)delta.y ) ) + width,
+            pad->SetSize( wxSize( KiROUND( EuclideanNorm( delta ) ) + width,
width ) );

=== modified file 'pcbnew/magnetic_tracks_functions.cpp'
--- pcbnew/magnetic_tracks_functions.cpp	2013-03-31 13:27:46 +0000
+++ pcbnew/magnetic_tracks_functions.cpp	2013-04-29 20:35:11 +0000
@@ -251,11 +251,8 @@
// a new track and that new track is parallel to the track the
// mouse is on. Find the nearest end point of the track under mouse
// to the mouse and return that.
-                double distStart = hypot( double( curpos->x - track->GetStart().x ),
-                                          double( curpos->y - track->GetStart().y ));
-
-                double distEnd   = hypot( double( curpos->x - track->GetEnd().x ),
-                                          double( curpos->y - track->GetEnd().y ));
+                double distStart = GetLineLength( *curpos, track->GetStart() );
+                double distEnd   = GetLineLength( *curpos, track->GetEnd() );

// if track not via, or if its a via dragging but not with its adjacent track
if( currTrack->Type() != PCB_VIA_T

=== modified file 'pcbnew/modules.cpp'
--- pcbnew/modules.cpp	2013-03-28 06:40:19 +0000
+++ pcbnew/modules.cpp	2013-04-29 11:25:45 +0000
@@ -432,7 +432,7 @@
* If DC == NULL, the component does not redraw.
* Otherwise, it erases and redraws turns
*/
-void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, int angle, bool incremental )
+void PCB_BASE_FRAME::Rotate_Module( wxDC* DC, MODULE* module, double angle, bool incremental )
{
if( module == NULL )
return;

=== modified file 'pcbnew/modview_frame.cpp'
--- pcbnew/modview_frame.cpp	2013-04-11 18:29:56 +0000
+++ pcbnew/modview_frame.cpp	2013-04-30 11:24:29 +0000
@@ -34,6 +34,7 @@
#include <3d_viewer.h>
#include <pcbcommon.h>
#include <msgpanel.h>
+#include <macros.h>

#include <class_board.h>
#include <class_module.h>

=== modified file 'pcbnew/muonde.cpp'
--- pcbnew/muonde.cpp	2013-04-25 16:29:35 +0000
+++ pcbnew/muonde.cpp	2013-04-29 12:28:31 +0000
@@ -104,8 +104,8 @@

wxPoint poly[5];
wxPoint pt    = Mself.m_End - Mself.m_Start;
-    int     angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI );
-    int     len   = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
+    double  angle = -ArcTangente( pt.y, pt.x );
+    int     len   = KiROUND( EuclideanNorm( pt ) );

// calculate corners
pt.x = 0; pt.y = len / 4;
@@ -125,8 +125,8 @@

Mself.m_End = aPanel->GetScreen()->GetCrossHairPosition();
pt    = Mself.m_End - Mself.m_Start;
-    angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI );
-    len   = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
+    angle = -ArcTangente( pt.y, pt.x );
+    len   = KiROUND( EuclideanNorm( pt ) );

// calculate new corners
pt.x = 0; pt.y = len / 4;
@@ -195,7 +195,7 @@
Mself.m_End = GetScreen()->GetCrossHairPosition();

wxPoint pt = Mself.m_End - Mself.m_Start;
-    int     min_len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
+    int     min_len = KiROUND( EuclideanNorm( pt ) );
Mself.lng = min_len;

// Enter the desired length.
@@ -398,8 +398,8 @@

wxPoint pt       = aEndPoint - aStartPoint;
-    int     angle    = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI );
-    int     min_len  = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) );
+    double  angle    = -ArcTangente( pt.y, pt.x );
+    int     min_len  = KiROUND( EuclideanNorm( pt ) );
int     segm_len = 0;           // length of segments
int     full_len;               // full len of shape (sum of lenght of all segments + arcs)

@@ -32,6 +32,7 @@
#include <class_drawpanel.h>
#include <confirm.h>
#include <trigo.h>
+#include <macros.h>
#include <wxBasePcbFrame.h>

#include <pcbnew.h>

@@ -93,12 +93,11 @@
&endX, &endY, aActualConversion );

-        int alpha1  = ArcTangente( m_startY - m_positionY, m_startX - m_positionX );
-        int alpha2  = ArcTangente( endY - m_positionY, endX - m_positionX );
+        double alpha1  = ArcTangente( m_startY - m_positionY, m_startX - m_positionX );
+        double alpha2  = ArcTangente( endY - m_positionY, endX - m_positionX );
m_angle = alpha1 - alpha2;

-        if( m_angle < 0 )
-            m_angle = 3600 + m_angle;
+        NORMALIZE_ANGLE_POS( m_angle );
}
else if( aNode->GetName() == wxT( "arc" ) )
{
@@ -122,8 +121,8 @@
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( cos10radius( r, a ) );
+        m_startY = m_positionY - KiROUND( sin10radius( r, a ) );
}
}

@@ -41,7 +41,7 @@
public:
int m_startX;
int m_startY;
-    int m_angle;
+    double m_angle;
int m_width;

PCB_ARC( PCB_CALLBACKS* aCallbacks, BOARD* aBoard );

=== modified file 'pcbnew/pcbplot.cpp'
--- pcbnew/pcbplot.cpp	2013-04-18 21:21:26 +0000
+++ pcbnew/pcbplot.cpp	2013-04-30 12:50:08 +0000
@@ -40,6 +40,7 @@
#include <pcb_plot_params.h>
#include <wx/ffile.h>
#include <dialog_plot.h>
+#include <macros.h>

/** Get the 'traditional' gerber extension depending on the layer

=== modified file 'pcbnew/plot_board_layers.cpp'
--- pcbnew/plot_board_layers.cpp	2013-03-31 13:27:46 +0000
+++ pcbnew/plot_board_layers.cpp	2013-04-30 12:51:54 +0000
@@ -37,6 +37,7 @@
#include <trigo.h>
#include <wxBasePcbFrame.h>
#include <pcbcommon.h>
+#include <macros.h>

#include <class_board.h>
#include <class_module.h>

=== modified file 'pcbnew/plot_brditems_plotter.cpp'
--- pcbnew/plot_brditems_plotter.cpp	2013-03-31 13:27:46 +0000
+++ pcbnew/plot_brditems_plotter.cpp	2013-04-30 12:54:25 +0000
@@ -33,6 +33,7 @@
#include <base_struct.h>
#include <drawtxt.h>
#include <trigo.h>
+#include <macros.h>
#include <wxBasePcbFrame.h>
#include <pcbcommon.h>

@@ -208,7 +209,8 @@
{
wxSize  size;
wxPoint pos;
-    int     orient, thickness;
+    double  orient;
+    int     thickness;

if( aColor == WHITE )
aColor = LIGHTGRAY;
@@ -388,15 +390,13 @@
break;

case S_CIRCLE:
-        radius = (int) hypot( (double) ( end.x - pos.x ),
-                              (double) ( end.y - pos.y ) );
+        radius = KiROUND( GetLineLength( end, pos ) );
m_plotter->ThickCircle( pos, radius * 2, thickness, GetMode() );
break;

case S_ARC:
{
-        radius = (int) hypot( (double) ( end.x - pos.x ),
-                                  (double) ( end.y - pos.y ) );
+        radius = KiROUND( GetLineLength( end, pos ) );

double startAngle  = ArcTangente( end.y - pos.y, end.x - pos.x );

@@ -448,7 +448,8 @@
// Plot a PCB Text, i;e. a text found on a copper or technical layer
void BRDITEMS_PLOTTER::PlotTextePcb( TEXTE_PCB* pt_texte )
{
-    int     orient, thickness;
+    double  orient;
+    int     thickness;
wxPoint pos;
wxSize  size;

@@ -587,7 +588,8 @@
void BRDITEMS_PLOTTER::PlotDrawSegment(  DRAWSEGMENT* aSeg )
{
int     thickness;
-    int     radius = 0, StAngle = 0, EndAngle = 0;
+    double  StAngle = 0, EndAngle = 0;

return;
@@ -607,14 +609,12 @@
switch( aSeg->GetShape() )
{
case S_CIRCLE:
-        radius = (int) hypot( (double) ( end.x - start.x ),
-                              (double) ( end.y - start.y ) );
+        radius = KiROUND( GetLineLength( end, start ) );
m_plotter->ThickCircle( start, radius * 2, thickness, GetMode() );
break;

case S_ARC:
-        radius = (int) hypot( (double) ( end.x - start.x ),
-                              (double) ( end.y - start.y ) );
+        radius = KiROUND( GetLineLength( end, start ) );
StAngle  = ArcTangente( end.y - start.y, end.x - start.x );
EndAngle = StAngle + aSeg->GetAngle();
m_plotter->ThickArc( start, -EndAngle, -StAngle, radius, thickness, GetMode() );

=== modified file 'pcbnew/ratsnest.cpp'
--- pcbnew/ratsnest.cpp	2013-03-18 19:36:07 +0000
+++ pcbnew/ratsnest.cpp	2013-04-30 12:58:23 +0000
@@ -9,6 +9,7 @@
#include <class_drawpanel.h>
#include <colors_selection.h>
#include <wxBasePcbFrame.h>
+#include <macros.h>

#include <class_board.h>
#include <class_module.h>

=== modified file 'pcbnew/specctra.cpp'
--- pcbnew/specctra.cpp	2013-04-29 16:35:07 +0000
+++ pcbnew/specctra.cpp	2013-04-30 13:03:06 +0000
@@ -56,6 +56,7 @@
#include <class_track.h>

#include <specctra.h>
+#include <macros.h>

namespace DSN {

=== modified file 'pcbnew/specctra_export.cpp'
--- pcbnew/specctra_export.cpp	2013-04-29 16:35:07 +0000
+++ pcbnew/specctra_export.cpp	2013-04-30 14:03:08 +0000
@@ -36,6 +36,7 @@
#include <confirm.h>            // DisplayError()
#include <gestfich.h>           // EDA_FileSelector()
#include <trigo.h>              // RotatePoint()
+#include <macros.h>

#include <set>                  // std::set
#include <map>                  // std::map
@@ -682,16 +683,15 @@
// lexer/beautifier, and the spec is not clear that this is
// required.  Fixed point floats are all that should be needed.

-                double  radius = hypot( double( graphic->GetStart().x - graphic->GetEnd().x ),
-                                        double( graphic->GetStart().y - graphic->GetEnd().y ) );
+                double radius = GetLineLength( graphic->GetStart(), graphic->GetEnd() );

// better if evenly divisible into 360
const int DEGREE_INTERVAL = 18;         // 18 means 20 line segments

{

point += graphic->m_Start0;     // an offset

@@ -906,7 +906,7 @@
error << _("Unable to find the next segment with an endpoint of ");
error << prevPt;
error << wxChar('\n');
-                error << _("Edit Edges_Pcb segments, making them contiguous.");
+                error << _("Edit Edge.Cuts segments, making them contiguous.");
ThrowIOError( error );
}
}
@@ -1371,8 +1371,8 @@
// module is flipped from bottom side, set side to T_back
if( module->GetFlag() )
{
-                int angle = 1800 - module->GetOrientation();
-                NORMALIZE_ANGLE_POS(angle);
+                double angle = 1800 - module->GetOrientation();
+                NORMALIZE_ANGLE_POS( angle );
place->SetRotation( angle/10.0 );

place->side = T_back;

=== modified file 'pcbnew/specctra_import.cpp'
--- pcbnew/specctra_import.cpp	2013-04-29 16:35:07 +0000
+++ pcbnew/specctra_import.cpp	2013-04-30 13:09:26 +0000
@@ -36,6 +36,7 @@
#include <confirm.h>            // DisplayError()
#include <gestfich.h>           // EDA_FileSelector()
#include <wxPcbStruct.h>
+#include <macros.h>

#include <class_board.h>
#include <class_module.h>

=== modified file 'pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp'
--- pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp	2013-03-20 14:50:12 +0000
+++ pcbnew/zones_convert_brd_items_to_polygons_with_Boost.cpp	2013-04-29 20:52:59 +0000
@@ -65,8 +65,8 @@

extern void BuildUnconnectedThermalStubsPolygonList( std::vector<CPolyPt>& aCornerBuffer,
BOARD* aPcb, ZONE_CONTAINER* aZone,
-                                                      double aArcCorrection,
+                                                     double aArcCorrection,

extern void Test_For_Copper_Island_And_Remove( BOARD*          aPcb,
ZONE_CONTAINER* aZone_container );
@@ -78,14 +78,14 @@
int                   aMinThicknessValue,
int                   aCircleToSegmentsCount,
double                aCorrectionFactor,
-                                           int                   aThermalRot );
+                                           double                aThermalRot );

// Exported function
KI_POLYGON_SET&        aKiPolyList );

// Local Variables:
-static int s_thermalRot = 450;  // angle of stubs in thermal reliefs for round pads
+static double s_thermalRot = 450;  // angle of stubs in thermal reliefs for round pads

// how many segments are used to create a polygon from a circle:
static int s_CircleToSegmentsCount = ARC_APPROX_SEGMENTS_COUNT_LOW_DEF;   /* default value. the real value will be changed to

=== modified file 'pcbnew/zones_convert_to_polygons_aux_functions.cpp'
--- pcbnew/zones_convert_to_polygons_aux_functions.cpp	2013-03-18 19:36:07 +0000
+++ pcbnew/zones_convert_to_polygons_aux_functions.cpp	2013-04-29 09:26:15 +0000
@@ -55,7 +55,7 @@
BOARD*                aPcb,
ZONE_CONTAINER*       aZone,
double                aArcCorrection,
{
std::vector<wxPoint> corners_buffer;    // a local polygon buffer to store one stub
corners_buffer.reserve( 4 );
@@ -138,7 +138,7 @@

// This is a CIRCLE pad tweak
// for circle pads, the thermal stubs orientation is 45 deg
{
endpoint.x     = (int) ( endpoint.x * aArcCorrection );

=== modified file 'polygon/PolyLine.cpp'
--- polygon/PolyLine.cpp	2013-04-06 05:01:48 +0000
+++ polygon/PolyLine.cpp	2013-04-30 07:39:54 +0000
@@ -1047,8 +1047,8 @@
// generate arc
for( int ic = 0; ic < num; ic++ )
{
-        int x   = KiROUND( xc + radius * cos( theta ) );
-        int y   = KiROUND( yc + radius * sin( theta ) );
+        int x   = xc + KiROUND( radius * cos( theta ) );
+        int y   = yc + KiROUND( radius * sin( theta ) );
AppendCorner( x, y );
theta += th_d;
}

```

Attachment: smime.p7s
Description: S/MIME cryptographic signature