Commit 0e903dba authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Angle and distances cleanup (preparing for angles in doubles)

- Removed spurious int casts (these are truncated anyway and will break
  doubles)

- Applied the Distance, GetLineLength, EuclideanNorm, DEG2RAD, RAD2DEG
  ArcTangente and NORMALIZE* functions where possible

- ArcTangente now returns double and handles the 0,0 case like atan2, so
  it's no longer necessary to check for it before calling

- Small functions in trigo moved as inline
parent 000ec33a
...@@ -60,15 +60,15 @@ void S3D_MASTER::Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices ) ...@@ -60,15 +60,15 @@ void S3D_MASTER::Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices )
aVertices[ii].y *= m_MatScale.y; aVertices[ii].y *= m_MatScale.y;
aVertices[ii].z *= m_MatScale.z; aVertices[ii].z *= m_MatScale.z;
/* adjust rotation */ // adjust rotation
if( m_MatRotation.x ) if( m_MatRotation.x )
RotatePoint( &aVertices[ii].y, &aVertices[ii].z, (int) (m_MatRotation.x * 10) ); RotatePoint( &aVertices[ii].y, &aVertices[ii].z, m_MatRotation.x * 10 );
if( m_MatRotation.y ) if( m_MatRotation.y )
RotatePoint( &aVertices[ii].z, &aVertices[ii].x, (int) (m_MatRotation.y * 10) ); RotatePoint( &aVertices[ii].z, &aVertices[ii].x, m_MatRotation.y * 10 );
if( m_MatRotation.z ) if( m_MatRotation.z )
RotatePoint( &aVertices[ii].x, &aVertices[ii].y, (int) (m_MatRotation.z * 10) ); RotatePoint( &aVertices[ii].x, &aVertices[ii].y, m_MatRotation.z * 10 );
/* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
#define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB)
......
...@@ -553,9 +553,8 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) ...@@ -553,9 +553,8 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment )
case S_CIRCLE: case S_CIRCLE:
{ {
int radius = KiROUND( hypot( double(segment->GetStart().x - segment->GetEnd().x), int radius = KiROUND( GetLineLength( segment->GetStart(),
double(segment->GetStart().y - segment->GetEnd().y) ) segment->GetEnd() ) );
);
Draw3D_ZaxisCylinder( segment->GetStart(), radius, Draw3D_ZaxisCylinder( segment->GetStart(), radius,
thickness, segment->GetWidth(), thickness, segment->GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits ); zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
...@@ -587,9 +586,8 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment ) ...@@ -587,9 +586,8 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment )
case S_CIRCLE: case S_CIRCLE:
{ {
int radius = KiROUND( hypot( double(segment->GetStart().x - segment->GetEnd().x), int radius = KiROUND( GetLineLength( segment->GetStart(),
double(segment->GetStart().y - segment->GetEnd().y) ) segment->GetEnd() ) );
);
Draw3D_ZaxisCylinder( segment->GetStart(), radius, Draw3D_ZaxisCylinder( segment->GetStart(), radius,
thickness, segment->GetWidth(), thickness, segment->GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits ); zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
...@@ -806,9 +804,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) ...@@ -806,9 +804,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas )
case S_CIRCLE: case S_CIRCLE:
{ {
int radius = KiROUND( hypot( double(m_Start.x - m_End.x), int radius = KiROUND( GetLineLength( m_Start, m_End ) );
double(m_Start.y - m_End.y) )
);
Draw3D_ZaxisCylinder( m_Start, radius, Draw3D_ZaxisCylinder( m_Start, radius,
thickness, GetWidth(), thickness, GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits ); zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
...@@ -848,9 +844,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas ) ...@@ -848,9 +844,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas )
case S_CIRCLE: case S_CIRCLE:
{ {
int radius = KiROUND( hypot( double(m_Start.x - m_End.x), int radius = KiROUND( GetLineLength( m_Start, m_End ) );
double(m_Start.y - m_End.y) )
);
Draw3D_ZaxisCylinder( m_Start, radius, Draw3D_ZaxisCylinder( m_Start, radius,
thickness, GetWidth(), thickness, GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits ); zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
......
...@@ -377,10 +377,9 @@ void Draw3D_ArcSegment( const wxPoint& aCenterPos, const wxPoint& aStartPoint, ...@@ -377,10 +377,9 @@ void Draw3D_ArcSegment( const wxPoint& aCenterPos, const wxPoint& aStartPoint,
std::vector <CPolyPt> cornerBuffer; std::vector <CPolyPt> cornerBuffer;
TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle, TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle,
slice, aWidth ); slice, aWidth );
Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits ); Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits );
} }
......
...@@ -389,8 +389,7 @@ void PLOTTER::segmentAsOval( const wxPoint& start, const wxPoint& end, int width ...@@ -389,8 +389,7 @@ void PLOTTER::segmentAsOval( const wxPoint& start, const wxPoint& end, int width
else else
orient = -(int) ( RAD2DEG( atan2( (double)size.y, (double)size.x ) ) * 10.0 ); orient = -(int) ( RAD2DEG( atan2( (double)size.y, (double)size.x ) ) * 10.0 );
size.x = (int) sqrt( ( (double) size.x * size.x ) size.x = KiROUND( hypot( size.x, size.y ) ) + width;
+ ( (double) size.y * size.y ) ) + width;
size.y = width; size.y = width;
FlashPadOval( center, size, orient, tracemode ); FlashPadOval( center, size, orient, tracemode );
......
...@@ -433,11 +433,11 @@ void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize, ...@@ -433,11 +433,11 @@ void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
wxASSERT( outputFile ); wxASSERT( outputFile );
wxSize size( aSize ); wxSize size( aSize );
/* Plot as flashed. */ // Plot as an aperture flash
switch( orient ) switch( int( orient ) )
{ {
case 900: case 900:
case 2700: /* rotation of 90 degrees or 270 swaps dimensions */ case 2700: // rotation of 90 degrees or 270 swaps sizes
EXCHG( size.x, size.y ); EXCHG( size.x, size.y );
// Pass through // Pass through
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <fctsys.h> #include <fctsys.h>
#include <trigo.h> #include <trigo.h>
#include <macros.h> #include <macros.h>
#include <common.h>
#include <convert_basic_shapes_to_polygon.h> #include <convert_basic_shapes_to_polygon.h>
/** /**
...@@ -85,7 +86,6 @@ void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer, ...@@ -85,7 +86,6 @@ void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer,
wxPoint endp = aEnd - aStart; // end point coordinate for the same segment starting at (0,0) wxPoint endp = aEnd - aStart; // end point coordinate for the same segment starting at (0,0)
wxPoint startp = aStart; wxPoint startp = aStart;
wxPoint corner; wxPoint corner;
int seg_len;
CPolyPt polypoint; CPolyPt polypoint;
// normalize the position in order to have endp.x >= 0; // normalize the position in order to have endp.x >= 0;
...@@ -96,7 +96,7 @@ void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer, ...@@ -96,7 +96,7 @@ void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer,
} }
int delta_angle = ArcTangente( endp.y, endp.x ); // delta_angle is in 0.1 degrees 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 ) ); int seg_len = KiROUND( EuclideanNorm( endp ) );
int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree int delta = 3600 / aCircleToSegmentsCount; // rot angle in 0.1 degree
......
...@@ -1075,7 +1075,7 @@ void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2, ...@@ -1075,7 +1075,7 @@ void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
y0 = ClipBox->GetY(); y0 = ClipBox->GetY();
xm = ClipBox->GetRight(); xm = ClipBox->GetRight();
ym = ClipBox->GetBottom(); ym = ClipBox->GetBottom();
r = (int) hypot( x1 - xc, y1 - yc ); r = KiROUND( Distance( x1, y1, xc, yc ) );
if( xc < ( x0 - r ) ) if( xc < ( x0 - r ) )
return; return;
if( yc < ( y0 - r ) ) if( yc < ( y0 - r ) )
......
...@@ -55,6 +55,7 @@ LAYER_MSK g_TabAllCopperLayerMask[NB_COPPER_LAYERS] = { ...@@ -55,6 +55,7 @@ LAYER_MSK g_TabAllCopperLayerMask[NB_COPPER_LAYERS] = {
DISPLAY_OPTIONS DisplayOpt; // Display options for board items 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_RotationAngle;
int g_AnchorColor = BLUE; int g_AnchorColor = BLUE;
......
...@@ -29,7 +29,8 @@ static inline double square( int x ) // helper function to calculate x*x ...@@ -29,7 +29,8 @@ static inline double square( int x ) // helper function to calculate x*x
{ {
return (double) x * x; 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 // test for vertical or horizontal segment
if( aEnd.x == aStart.x ) if( aEnd.x == aStart.x )
...@@ -84,7 +85,7 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist ...@@ -84,7 +85,7 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist
// the distance should be carefully calculated // the distance should be carefully calculated
if( (aStart.x - aRefPoint.x) <= aDist ) 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 ); square( aRefPoint.y - aStart.y );
if( dd <= square( aDist ) ) if( dd <= square( aDist ) )
return true; return true;
...@@ -92,8 +93,8 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist ...@@ -92,8 +93,8 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist
if( (aRefPoint.x - aEnd.x) <= aDist ) if( (aRefPoint.x - aEnd.x) <= aDist )
{ {
double dd = square(aRefPoint.x - aEnd.x) + double dd = square( aRefPoint.x - aEnd.x ) +
square( aRefPoint.y - aEnd.y); square( aRefPoint.y - aEnd.y );
if( dd <= square( aDist ) ) if( dd <= square( aDist ) )
return true; return true;
} }
...@@ -157,9 +158,14 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist ...@@ -157,9 +158,14 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist
} }
int ArcTangente( int dy, int dx ) double ArcTangente( int dy, int dx )
{ {
double fangle;
/* gcc is surprisingly smart in optimizing these conditions in
a tree! */
if( dx == 0 && dy == 0 )
return 0;
if( dy == 0 ) if( dy == 0 )
{ {
...@@ -193,8 +199,7 @@ int ArcTangente( int dy, int dx ) ...@@ -193,8 +199,7 @@ int ArcTangente( int dy, int dx )
return 1800 - 450; return 1800 - 450;
} }
fangle = atan2( (double) dy, (double) dx ) / M_PI * 1800; return atan2( dy, dx ) / M_PI * 1800;
return KiROUND( fangle );
} }
...@@ -202,11 +207,7 @@ void RotatePoint( int* pX, int* pY, double angle ) ...@@ -202,11 +207,7 @@ void RotatePoint( int* pX, int* pY, double angle )
{ {
int tmp; int tmp;
while( angle < 0 ) NORMALIZE_ANGLE_POS( angle );
angle += 3600;
while( angle >= 3600 )
angle -= 3600;
// Cheap and dirty optimizations for 0, 90, 180, and 270 degrees. // Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
if( angle == 0 ) if( angle == 0 )
...@@ -287,11 +288,7 @@ void RotatePoint( double* pX, double* pY, double angle ) ...@@ -287,11 +288,7 @@ void RotatePoint( double* pX, double* pY, double angle )
{ {
double tmp; double tmp;
while( angle < 0 ) NORMALIZE_ANGLE_POS( angle );
angle += 3600;
while( angle >= 3600 )
angle -= 3600;
// Cheap and dirty optimizations for 0, 90, 180, and 270 degrees. // Cheap and dirty optimizations for 0, 90, 180, and 270 degrees.
if( angle == 0 ) if( angle == 0 )
...@@ -327,37 +324,3 @@ void RotatePoint( double* pX, double* pY, double angle ) ...@@ -327,37 +324,3 @@ void RotatePoint( double* pX, double* pY, double angle )
} }
} }
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 );
}
...@@ -757,7 +757,7 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition ) ...@@ -757,7 +757,7 @@ void LIB_ARC::calcEdit( const wxPoint& aPosition )
dy = m_ArcEnd.y - m_ArcStart.y; dy = m_ArcEnd.y - m_ArcStart.y;
cX -= m_ArcStart.x; cX -= m_ArcStart.x;
cY -= m_ArcStart.y; 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 RotatePoint( &dx, &dy, angle ); /* The segment dx, dy is horizontal
* -> Length = dx, dy = 0 */ * -> Length = dx, dy = 0 */
RotatePoint( &cX, &cY, angle ); RotatePoint( &cX, &cY, angle );
...@@ -786,11 +786,9 @@ void LIB_ARC::calcRadiusAngles() ...@@ -786,11 +786,9 @@ void LIB_ARC::calcRadiusAngles()
m_Radius = KiROUND( EuclideanNorm( centerStartVector ) ); m_Radius = KiROUND( EuclideanNorm( centerStartVector ) );
m_t1 = (int) ( atan2( (double) centerStartVector.y, // Angles in eeschema are still integers
(double) centerStartVector.x ) * 1800 / M_PI ); m_t1 = KiROUND( ArcTangente( centerStartVector.y, centerStartVector.x ) );
m_t2 = KiROUND( ArcTangente( centerEndVector.y, centerEndVector.x ) );
m_t2 = (int) ( atan2( (double) centerEndVector.y,
(double) centerEndVector.x ) * 1800 / M_PI );
NORMALIZE_ANGLE_POS( m_t1 ); NORMALIZE_ANGLE_POS( m_t1 );
NORMALIZE_ANGLE_POS( m_t2 ); // angles = 0 .. 3600 NORMALIZE_ANGLE_POS( m_t2 ); // angles = 0 .. 3600
......
...@@ -107,8 +107,7 @@ bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra ...@@ -107,8 +107,7 @@ bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra
wxPoint relpos = aPosRef - aTransform.TransformCoordinate( m_Pos ); wxPoint relpos = aPosRef - aTransform.TransformCoordinate( m_Pos );
int dist = KiROUND( sqrt( ( (double) relpos.x * relpos.x ) + int dist = KiROUND( EuclideanNorm( relpos ) );
( (double) relpos.y * relpos.y ) ) );
if( abs( dist - m_Radius ) <= aThreshold ) if( abs( dist - m_Radius ) <= aThreshold )
return true; return true;
...@@ -348,7 +347,7 @@ void LIB_CIRCLE::calcEdit( const wxPoint& aPosition ) ...@@ -348,7 +347,7 @@ void LIB_CIRCLE::calcEdit( const wxPoint& aPosition )
int dx = m_Pos.x - aPosition.x; int dx = m_Pos.x - aPosition.x;
int dy = m_Pos.y - aPosition.y; int dy = m_Pos.y - aPosition.y;
m_Radius = KiROUND( sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) ) ); m_Radius = KiROUND( hypot( dx, dy ) );
} }
else else
{ {
......
...@@ -159,7 +159,7 @@ void SCH_BASE_FRAME::UpdateStatusBar() ...@@ -159,7 +159,7 @@ void SCH_BASE_FRAME::UpdateStatusBar()
} }
// We already decided the formatter above // 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 ); SetStatusText( line, 3 );
// refresh units display // refresh units display
......
#include <macros.h> #include <macros.h>
#include <transform.h> #include <transform.h>
#include <common.h>
#include <trigo.h>
TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform ) TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform )
...@@ -77,7 +79,7 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const ...@@ -77,7 +79,7 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const
t = x * x1 + y * y1; t = x * x1 + y * y1;
y = x * x2 + y * y2; y = x * x2 + y * y2;
x = t; 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 ); x = cos( *aAngle2 * M_PI / 1800.0 );
y = sin( *aAngle2 * M_PI / 1800.0 ); y = sin( *aAngle2 * M_PI / 1800.0 );
......
...@@ -444,7 +444,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent, ...@@ -444,7 +444,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent,
wxPoint end = mapPt( params[4].GetValue( tool ), wxPoint end = mapPt( params[4].GetValue( tool ),
params[5].GetValue( tool ), m_GerbMetric ); params[5].GetValue( tool ), m_GerbMetric );
wxPoint delta = end - start; 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" // To build the polygon, we must create a horizonta polygon starting to "start"
// and rotate it to have it end point to "end" // and rotate it to have it end point to "end"
...@@ -459,7 +459,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent, ...@@ -459,7 +459,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent,
aBuffer.push_back( currpt ); aBuffer.push_back( currpt );
// Rotate rectangle and move it to the actual start point // Rotate rectangle and move it to the actual start point
int angle = KiROUND( atan2( (double) delta.y, (double) delta.x ) * 1800.0 / M_PI ); int angle = ArcTangente( delta.y, delta.x );
for( unsigned ii = 0; ii < 4; ii++ ) for( unsigned ii = 0; ii < 4; ii++ )
{ {
......
...@@ -360,8 +360,7 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDra ...@@ -360,8 +360,7 @@ void GERBER_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, GR_DRAWMODE aDra
break; break;
case GBR_CIRCLE: case GBR_CIRCLE:
radius = KiROUND(hypot( (double) ( m_End.x - m_Start.x ), radius = KiROUND( GetLineLength( m_Start, m_End ) );
(double) ( m_End.y - m_Start.y ) ));
halfPenWidth = m_Size.x >> 1; halfPenWidth = m_Size.x >> 1;
......
...@@ -332,7 +332,8 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem, ...@@ -332,7 +332,8 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem,
{ {
seg_start = curr_start; seg_start = curr_start;
wxPoint curr_end = start; wxPoint curr_end = start;
RotatePoint( &curr_end, aGbrItem->m_ArcCentre, -(int) (DELTA_ANGLE * ii * 1800 / M_PI) ); RotatePoint( &curr_end, aGbrItem->m_ArcCentre,
-(int) (DELTA_ANGLE * ii * 1800 / M_PI) );
seg_end = curr_end; seg_end = curr_end;
// Reverse Y axis: // Reverse Y axis:
NEGATE( seg_start.y ); NEGATE( seg_start.y );
......
...@@ -802,14 +802,10 @@ void GERBVIEW_FRAME::UpdateStatusBar() ...@@ -802,14 +802,10 @@ void GERBVIEW_FRAME::UpdateStatusBar()
dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x; dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x;
dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y; dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y;
if( dx==0 && dy==0 ) // atan2 in the 0,0 case returns 0
theta = 0.0; theta = RAD2DEG( atan2( -dy, dx ) );
else
theta = atan2( (double) -dy, (double) dx );
theta = theta * 180.0 / M_PI;
ro = sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) ); ro = hypot( dx, dy );
wxString formatter; wxString formatter;
switch( g_UserUnit ) switch( g_UserUnit )
{ {
...@@ -868,7 +864,7 @@ void GERBVIEW_FRAME::UpdateStatusBar() ...@@ -868,7 +864,7 @@ void GERBVIEW_FRAME::UpdateStatusBar()
dYpos = To_User_Unit( g_UserUnit, dy ); dYpos = To_User_Unit( g_UserUnit, dy );
// We already decided the formatter above // 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 ); SetStatusText( line, 3 );
} }
} }
......
...@@ -339,8 +339,8 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem, ...@@ -339,8 +339,8 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem,
* angle is trigonometrical (counter-clockwise), * angle is trigonometrical (counter-clockwise),
* and axis is the X,Y gerber coordinates * and axis is the X,Y gerber coordinates
*/ */
int start_angle = KiROUND(atan2( (double) start.y, (double) start.x ) * 1800 / M_PI); int start_angle = ArcTangente( start.y, start.x );
int end_angle = KiROUND(atan2( (double) end.y, (double) end.x ) * 1800 / M_PI); int end_angle = ArcTangente( end.y, end.x );
// dummyTrack has right geometric parameters, but // dummyTrack has right geometric parameters, but
// fillArcGBRITEM calculates arc parameters for a draw function that expects // fillArcGBRITEM calculates arc parameters for a draw function that expects
......
...@@ -57,8 +57,8 @@ static inline const wxChar* GetChars( const wxString& s ) ...@@ -57,8 +57,8 @@ static inline const wxChar* GetChars( const wxString& s )
#endif #endif
} }
// This really need a function? anyway is used *a lot* of times // This really needs a function? well, it is used *a lot* of times
template<class T> inline void NEGATE( T& x ) { x = -x; } template<class T> inline void NEGATE( T &x ) { x = -x; }
/// # of elements in an array /// # of elements in an array
#define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t #define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
#ifndef TRIGO_H #ifndef TRIGO_H
#define TRIGO_H #define TRIGO_H
#include <math.h>
#include <wx/gdicmn.h> // For wxPoint
/* /*
* Calculate the new point of coord coord pX, pY, * Calculate the new point of coord coord pX, pY,
...@@ -46,7 +47,7 @@ void RotatePoint( int *pX, int *pY, int cx, int cy, double angle ); ...@@ -46,7 +47,7 @@ void RotatePoint( int *pX, int *pY, int cx, int cy, double angle );
* Calculates the new coord point point * Calculates the new coord point point
* for a rotation angle in (1 / 10 degree) * 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 ); RotatePoint( &point->x, &point->y, angle );
} }
...@@ -64,34 +65,69 @@ void RotatePoint( double *pX, double *pY, double cx, double cy, double angle ); ...@@ -64,34 +65,69 @@ void RotatePoint( double *pX, double *pY, double cx, double cy, double angle );
/* Return the arc tangent of 0.1 degrees coord vector dx, dy /* Return the arc tangent of 0.1 degrees coord vector dx, dy
* between -1800 and 1800 * between -1800 and 1800
* Equivalent to atan2 (but faster for calculations if * 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
* in decidegrees instead of radians, so it's handier
*/ */
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 )
{
// this is working with doubles
return hypot( vector.x, vector.y );
}
//! @brief Compute the distance between a line and a reference point //! @brief Compute the distance between a line and a reference point
//! Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html //! Reference: http://mathworld.wolfram.com/Point-LineDistance2-Dimensional.html
//! @param linePointA Point on line //! @param linePointA Point on line
//! @param linePointB Point on line //! @param linePointB Point on line
//! @param referencePoint Reference point //! @param referencePoint Reference point
double DistanceLinePoint( wxPoint linePointA, wxPoint linePointB, wxPoint referencePoint ); inline double DistanceLinePoint( const wxPoint &linePointA,
const wxPoint &linePointB,
//! @brief Euclidean norm of a 2D vector const wxPoint &referencePoint )
//! @param vector Two-dimensional vector {
//! @return Euclidean norm of the vector // Some of the multiple double casts are redundant. However in the previous
double EuclideanNorm( wxPoint vector ); // 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 //! @brief Test, if two points are near each other
//! @param pointA First point //! @param pointA First point
//! @param pointB Second point //! @param pointB Second point
//! @param threshold The maximum distance //! @param threshold The maximum distance
//! @return True or false //! @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 //! @brief Determine the cross product
//! @param vectorA Two-dimensional vector //! @param vectorA Two-dimensional vector
//! @param vectorB 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 * Function TestSegmentHit
...@@ -102,13 +138,21 @@ double CrossProduct( wxPoint vectorA, wxPoint vectorB ); ...@@ -102,13 +138,21 @@ double CrossProduct( wxPoint vectorA, wxPoint vectorB );
* @param aEnd is the second end-point of the line segment * @param aEnd is the second end-point of the line segment
* @param aDist = maximum distance for hit * @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 * Function GetLineLength
* returns the length of a line segment defined by \a aPointA and \a aPointB. * returns the length of a line segment defined by \a aPointA and \a aPointB.
* @return Length of a line. * See also EuclideanNorm and Distance for the single vector or four
* scalar versions
* @return Length of a line (as double)
*/ */
double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB ); inline double GetLineLength( const wxPoint& aPointA, const wxPoint& aPointB )
{
// Implicitly casted to double
return hypot( aPointA.x - aPointB.x,
aPointA.y - aPointB.y );
}
#endif #endif
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include <macros.h> #include <macros.h>
#include <trigo.h> #include <trigo.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <math_for_graphics.h>
#include <class_board.h> #include <class_board.h>
#include <class_track.h> #include <class_track.h>
...@@ -125,7 +125,7 @@ void PlacePad( D_PAD* aPad, int color, int marge, int op_logic ) ...@@ -125,7 +125,7 @@ void PlacePad( D_PAD* aPad, int color, int marge, int op_logic )
{ {
TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy, TraceFilledRectangle( shape_pos.x - dx, shape_pos.y - dy,
shape_pos.x + dx, shape_pos.y + dy, shape_pos.x + dx, shape_pos.y + dy,
(int) aPad->GetOrientation(), aPad->GetOrientation(),
aPad->GetLayerMask(), color, op_logic ); aPad->GetLayerMask(), color, op_logic );
} }
} }
...@@ -561,8 +561,7 @@ void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1, ...@@ -561,8 +561,7 @@ void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
cx = (ux0 + ux1) / 2; cx = (ux0 + ux1) / 2;
cy = (uy0 + uy1) / 2; cy = (uy0 + uy1) / 2;
radius = (int) sqrt( (double) ( cx - ux0 ) * ( cx - ux0 ) radius = KiROUND( Distance( ux0, uy0, cx, cy ) );
+ (double) ( cy - uy0 ) * ( cy - uy0 ) );
// Calculating coordinate limits belonging to the rectangle. // Calculating coordinate limits belonging to the rectangle.
row_max = ( cy + radius ) / RoutingMatrix.m_GridRouting; row_max = ( cy + radius ) / RoutingMatrix.m_GridRouting;
...@@ -689,7 +688,7 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer ...@@ -689,7 +688,7 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer
if( dx ) if( dx )
{ {
angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI ); angle = ArcTangente( dy, dx );
} }
else else
{ {
...@@ -758,7 +757,7 @@ void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer, ...@@ -758,7 +757,7 @@ void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer,
int ii; int ii;
int angle; int angle;
radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) ); radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
x0 = x1 = radius; x0 = x1 = radius;
y0 = y1 = 0; y0 = y1 = 0;
...@@ -803,7 +802,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, ...@@ -803,7 +802,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
int angle, StAngle; int angle, StAngle;
radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) ); radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
x0 = ux1 - ux0; x0 = ux1 - ux0;
y0 = uy1 - uy0; y0 = uy1 - uy0;
...@@ -813,7 +812,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, ...@@ -813,7 +812,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
lg = 1; lg = 1;
nb_segm = ( 2 * radius ) / lg; nb_segm = ( 2 * radius ) / lg;
nb_segm = ( nb_segm * abs( ArcAngle ) ) / 3600; nb_segm = ( nb_segm * std::abs( ArcAngle ) ) / 3600;
if( nb_segm < 5 ) if( nb_segm < 5 )
nb_segm = 5; nb_segm = 5;
...@@ -826,11 +825,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg, ...@@ -826,11 +825,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
angle = ( ArcAngle * ii ) / nb_segm; angle = ( ArcAngle * ii ) / nb_segm;
angle += StAngle; angle += StAngle;
while( angle >= 3600 ) NORMALIZE_ANGLE_POS( angle );
angle -= 3600;
while( angle < 0 )
angle += 3600;
x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) ); x1 = (int) ( radius * cos( DEG2RAD( (double)angle / 10.0 ) ) );
y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) ); y1 = (int) ( radius * sin( DEG2RAD( (double)angle / 10.0 ) ) );
......
...@@ -317,12 +317,12 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag ) ...@@ -317,12 +317,12 @@ void PlaceCells( BOARD* aPcb, int net_code, int flag )
layerMask = GetLayerMask( PtText->GetLayer() ); layerMask = GetLayerMask( PtText->GetLayer() );
TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge, TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge,
uy1 + marge, (int) (PtText->GetOrientation()), uy1 + marge, PtText->GetOrientation(),
layerMask, HOLE, WRITE_CELL ); layerMask, HOLE, WRITE_CELL );
TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge, TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge,
ux1 + via_marge, uy1 + via_marge, ux1 + via_marge, uy1 + via_marge,
(int) (PtText->GetOrientation()), PtText->GetOrientation(),
layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL ); layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL );
} }
break; break;
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
#include <collectors.h> #include <collectors.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <vector2d.h> #include <vector2d.h>
#include <trigo.h>
// Configuration entry names. // Configuration entry names.
static const wxString UserGridSizeXEntry( wxT( "PcbUserGrid_X" ) ); static const wxString UserGridSizeXEntry( wxT( "PcbUserGrid_X" ) );
...@@ -563,14 +563,9 @@ void PCB_BASE_FRAME::UpdateStatusBar() ...@@ -563,14 +563,9 @@ void PCB_BASE_FRAME::UpdateStatusBar()
dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x; dx = screen->GetCrossHairPosition().x - screen->m_O_Curseur.x;
dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y; dy = screen->GetCrossHairPosition().y - screen->m_O_Curseur.y;
if( dx==0 && dy==0 ) theta = ArcTangente( -dy, dx ) / 10;
theta = 0.0;
else
theta = atan2( (double) -dy, (double) dx );
theta = theta * 180.0 / M_PI;
ro = sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) ); ro = hypot( dx, dy );
wxString formatter; wxString formatter;
switch( g_UserUnit ) switch( g_UserUnit )
{ {
...@@ -661,7 +656,7 @@ void PCB_BASE_FRAME::UpdateStatusBar() ...@@ -661,7 +656,7 @@ void PCB_BASE_FRAME::UpdateStatusBar()
#endif #endif
// We already decided the formatter above // 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 ); SetStatusText( line, 3 );
} }
} }
......
...@@ -475,7 +475,7 @@ void CreateThermalReliefPadPolygon( std::vector<CPolyPt>& aCornerBuffer, ...@@ -475,7 +475,7 @@ void CreateThermalReliefPadPolygon( std::vector<CPolyPt>& aCornerBuffer,
double dtmp = sqrt( ( (double) outer_radius * outer_radius ) - double dtmp = sqrt( ( (double) outer_radius * outer_radius ) -
( (double) corner.x * corner.x ) ); ( (double) corner.x * corner.x ) );
corner.y = (int) dtmp; corner.y = (int) dtmp;
RotatePoint( &corner, 90 ); RotatePoint( &corner, 90 ); // 9 degrees is the spoke fillet size
// calculate the ending point of the outter arc // calculate the ending point of the outter arc
corner_end.x = corner.y; corner_end.x = corner.y;
......
...@@ -240,10 +240,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) ...@@ -240,10 +240,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
// Calculate dimension value // Calculate dimension value
measure = KiROUND( hypot( (double) deltax, (double) deltay ) ); measure = KiROUND( hypot( (double) deltax, (double) deltay ) );
if( deltax || deltay ) angle = atan2( deltay, deltax );
angle = atan2( (double) deltay, (double) deltax );
else
angle = 0.0;
// Calculation of parameters X and Y dimensions of the arrows and lines. // Calculation of parameters X and Y dimensions of the arrows and lines.
hx = hy = ii; hx = hy = ii;
...@@ -266,12 +263,12 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) ...@@ -266,12 +263,12 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
if( m_featureLineGO.y == m_crossBarO.y ) if( m_featureLineGO.y == m_crossBarO.y )
hy = 0; hy = 0;
angle_f = angle + (M_PI * 27.5 / 180); angle_f = angle + DEG2RAD( 27.5 );
arrow_up_X = (int) ( arrowz * cos( angle_f ) ); arrow_up_X = wxRound( arrowz * cos( angle_f ) );
arrow_up_Y = (int) ( arrowz * sin( angle_f ) ); arrow_up_Y = wxRound( arrowz * sin( angle_f ) );
angle_f = angle - (M_PI * 27.5 / 180); angle_f = angle - DEG2RAD( 27.5 );
arrow_dw_X = (int) ( arrowz * cos( angle_f ) ); arrow_dw_X = wxRound( arrowz * cos( angle_f ) );
arrow_dw_Y = (int) ( arrowz * sin( angle_f ) ); arrow_dw_Y = wxRound( arrowz * sin( angle_f ) );
} }
m_arrowG1O.x = m_crossBarO.x; m_arrowG1O.x = m_crossBarO.x;
...@@ -312,11 +309,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText ) ...@@ -312,11 +309,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
double newAngle = -(angle * 1800 / M_PI); double newAngle = -(angle * 1800 / M_PI);
if( newAngle < 0 ) NORMALIZE_ANGLE_POS( newAngle );
newAngle += 3600;
if( newAngle >= 3600 )
newAngle -= 3600;
if( newAngle > 900 && newAngle < 2700 ) if( newAngle > 900 && newAngle < 2700 )
newAngle -= 1800; newAngle -= 1800;
......
...@@ -138,16 +138,13 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const ...@@ -138,16 +138,13 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const
const double DRAWSEGMENT::GetArcAngleStart() const const double DRAWSEGMENT::GetArcAngleStart() const
{ {
// due to the Y axis orient atan2 needs - y value // due to the Y axis orient atan2 needs - y value
double angleStart = atan2( (double)(GetArcStart().y - GetCenter().y), double angleStart = ArcTangente( GetArcStart().y - GetCenter().y,
(double)(GetArcStart().x - GetCenter().x) ); GetArcStart().x - GetCenter().x );
// angleStart is in radians, convert it in 1/10 degrees
angleStart = angleStart / M_PI * 1800.0;
// Normalize it to 0 ... 360 deg, to avoid discontinuity for angles near 180 deg // 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. // because 180 deg and -180 are very near angles when ampping betewwen -180 ... 180 deg.
// and this is not easy to handle in calculations // and this is not easy to handle in calculations
if( angleStart < 0 ) NORMALIZE_ANGLE_POS( angleStart );
angleStart += 3600.0;
return angleStart; return angleStart;
} }
...@@ -156,7 +153,7 @@ void DRAWSEGMENT::SetAngle( double aAngle ) ...@@ -156,7 +153,7 @@ void DRAWSEGMENT::SetAngle( double aAngle )
{ {
NORMALIZE_ANGLE_360( aAngle ); NORMALIZE_ANGLE_360( aAngle );
m_Angle = (int) aAngle; m_Angle = aAngle;
} }
...@@ -215,7 +212,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, ...@@ -215,7 +212,7 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
switch( m_Shape ) switch( m_Shape )
{ {
case S_CIRCLE: case S_CIRCLE:
radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
if( mode == LINE ) if( mode == LINE )
{ {
...@@ -235,8 +232,8 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, ...@@ -235,8 +232,8 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
case S_ARC: case S_ARC:
int StAngle, EndAngle; int StAngle, EndAngle;
radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); StAngle = ArcTangente( dy - uy0, dx - ux0 );
EndAngle = StAngle + m_Angle; EndAngle = StAngle + m_Angle;
if( !panel->GetPrintMirrored() ) if( !panel->GetPrintMirrored() )
...@@ -336,7 +333,7 @@ void DRAWSEGMENT::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -336,7 +333,7 @@ void DRAWSEGMENT::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
case S_ARC: case S_ARC:
aList.push_back( MSG_PANEL_ITEM( shape, _( "Arc" ), RED ) ); aList.push_back( MSG_PANEL_ITEM( shape, _( "Arc" ), RED ) );
msg.Printf( wxT( "%.1f" ), (double)m_Angle/10 ); msg.Printf( wxT( "%.1f" ), m_Angle / 10.0 );
aList.push_back( MSG_PANEL_ITEM( _("Angle"), msg, RED ) ); aList.push_back( MSG_PANEL_ITEM( _("Angle"), msg, RED ) );
break; break;
...@@ -434,7 +431,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition ) ...@@ -434,7 +431,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition )
{ {
wxPoint relPos = aPosition - GetCenter(); wxPoint relPos = aPosition - GetCenter();
int radius = GetRadius(); int radius = GetRadius();
int dist = (int) hypot( (double) relPos.x, (double) relPos.y ); int dist = KiROUND( EuclideanNorm( relPos ) );
if( abs( radius - dist ) <= ( m_Width / 2 ) ) if( abs( radius - dist ) <= ( m_Width / 2 ) )
{ {
...@@ -449,8 +446,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition ) ...@@ -449,8 +446,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition )
// and > arc angle if arc angle < 0 (CCW arc) // 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_angle_start = GetArcAngleStart(); // Always 0.0 ... 360 deg, in 0.1 deg
double arc_hittest = atan2( (double) relPos.y, (double) relPos.x ); double arc_hittest = ArcTangente( relPos.y, relPos.x );
arc_hittest = arc_hittest / M_PI * 1800; // angles are in 1/10 deg
// Calculate relative angle between the starting point of the arc, and the test point // Calculate relative angle between the starting point of the arc, and the test point
arc_hittest -= arc_angle_start; arc_hittest -= arc_angle_start;
......
...@@ -33,6 +33,8 @@ ...@@ -33,6 +33,8 @@
#include <class_board_item.h> #include <class_board_item.h>
#include <PolyLine.h> #include <PolyLine.h>
#include <math_for_graphics.h>
#include <trigo.h>
class LINE_READER; class LINE_READER;
...@@ -134,7 +136,7 @@ public: ...@@ -134,7 +136,7 @@ public:
*/ */
int GetRadius() const int GetRadius() const
{ {
double radius = hypot( (double) (m_End.x - m_Start.x), (double) (m_End.y - m_Start.y) ); double radius = GetLineLength( m_Start, m_End );
return KiROUND( radius ); return KiROUND( radius );
} }
...@@ -184,9 +186,7 @@ public: ...@@ -184,9 +186,7 @@ public:
*/ */
double GetLength() const double GetLength() const
{ {
wxPoint delta = GetEnd() - GetStart(); return GetLineLength( GetStart(), GetEnd() );
return hypot( double( delta.x ), double( delta.y ) );
} }
virtual void Move( const wxPoint& aMoveVector ) virtual void Move( const wxPoint& aMoveVector )
......
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <colors_selection.h> #include <colors_selection.h>
#include <richio.h> #include <richio.h>
#include <macros.h> #include <macros.h>
#include <math_for_graphics.h>
#include <wxBasePcbFrame.h> #include <wxBasePcbFrame.h>
#include <pcbcommon.h> #include <pcbcommon.h>
#include <msgpanel.h> #include <msgpanel.h>
...@@ -163,7 +164,7 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, ...@@ -163,7 +164,7 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
break; break;
case S_CIRCLE: case S_CIRCLE:
radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
if( typeaff == LINE ) if( typeaff == LINE )
{ {
...@@ -185,8 +186,8 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode, ...@@ -185,8 +186,8 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
break; break;
case S_ARC: case S_ARC:
radius = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) ); radius = KiROUND( Distance( ux0, uy0, dx, dy ) );
StAngle = (int) ArcTangente( dy - uy0, dx - ux0 ); StAngle = ArcTangente( dy - uy0, dx - ux0 );
EndAngle = StAngle + m_Angle; EndAngle = StAngle + m_Angle;
if( StAngle > EndAngle ) if( StAngle > EndAngle )
......
...@@ -495,7 +495,7 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -495,7 +495,7 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Stat" ), msg, MAGENTA ) ); aList.push_back( MSG_PANEL_ITEM( _( "Stat" ), msg, MAGENTA ) );
msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 ); msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 );
aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), msg, BROWN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), msg, BROWN ) );
// Controls on right side of the dialog // Controls on right side of the dialog
......
...@@ -555,10 +555,10 @@ void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList ) ...@@ -555,10 +555,10 @@ void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
if( module_orient ) if( module_orient )
Line.Printf( wxT( "%3.1f(+%3.1f)" ), Line.Printf( wxT( "%3.1f(+%3.1f)" ),
(double) ( m_Orient - module_orient ) / 10, ( m_Orient - module_orient ) / 10.0,
(double) module_orient / 10 ); module_orient / 10.0 );
else else
Line.Printf( wxT( "%3.1f" ), (double) m_Orient / 10 ); Line.Printf( wxT( "%3.1f" ), m_Orient / 10.0 );
aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), Line, LIGHTBLUE ) ); aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), Line, LIGHTBLUE ) );
...@@ -586,7 +586,6 @@ bool D_PAD::IsOnLayer( LAYER_NUM aLayer ) const ...@@ -586,7 +586,6 @@ bool D_PAD::IsOnLayer( LAYER_NUM aLayer ) const
bool D_PAD::HitTest( const wxPoint& aPosition ) bool D_PAD::HitTest( const wxPoint& aPosition )
{ {
int dx, dy; int dx, dy;
double dist;
wxPoint shape_pos = ReturnShapePos(); wxPoint shape_pos = ReturnShapePos();
...@@ -604,9 +603,7 @@ bool D_PAD::HitTest( const wxPoint& aPosition ) ...@@ -604,9 +603,7 @@ bool D_PAD::HitTest( const wxPoint& aPosition )
switch( m_PadShape & 0x7F ) switch( m_PadShape & 0x7F )
{ {
case PAD_CIRCLE: case PAD_CIRCLE:
dist = hypot( delta.x, delta.y ); if( KiROUND( EuclideanNorm( delta ) ) <= dx )
if( KiROUND( dist ) <= dx )
return true; return true;
break; break;
......
...@@ -527,7 +527,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) ...@@ -527,7 +527,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
// area of the pad // area of the pad
RotatePoint( &tpos, shape_pos, angle ); RotatePoint( &tpos, shape_pos, angle );
/* Draw text with an angle between -90 deg and + 90 deg */ // Draw text with an angle between -90 deg and + 90 deg
int t_angle = angle; int t_angle = angle;
NORMALIZE_ANGLE_90( t_angle ); NORMALIZE_ANGLE_90( t_angle );
...@@ -595,7 +595,8 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo ) ...@@ -595,7 +595,8 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
* aSegStart and aSegEnd are the ending points of the equivalent segment of the shape * aSegStart and aSegEnd are the ending points of the equivalent segment of the shape
* aRotation is the asked rotation of the segment (usually m_Orient) * aRotation is the asked rotation of the segment (usually m_Orient)
*/ */
int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int aRotation) const int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd,
int aRotation) const
{ {
int width; int width;
...@@ -628,7 +629,8 @@ int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int a ...@@ -628,7 +629,8 @@ int D_PAD::BuildSegmentFromOvalShape(wxPoint& aSegStart, wxPoint& aSegEnd, int a
} }
void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotation ) const void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue,
int aRotation ) const
{ {
if( (GetShape() != PAD_RECT) && (GetShape() != PAD_TRAPEZOID) ) if( (GetShape() != PAD_RECT) && (GetShape() != PAD_TRAPEZOID) )
return; return;
...@@ -696,7 +698,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat ...@@ -696,7 +698,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat
if( delta.y ) // lower and upper segment is horizontal if( delta.y ) // lower and upper segment is horizontal
{ {
// Calculate angle of left (or right) segment with vertical axis // Calculate angle of left (or right) segment with vertical axis
angle = atan2( double( m_DeltaSize.y ), double( m_Size.y ) ); angle = atan2( m_DeltaSize.y, m_Size.y );
// left and right sides are moved by aInflateValue.x in their perpendicular direction // left and right sides are moved by aInflateValue.x in their perpendicular direction
// We must calculate the corresponding displacement on the horizontal axis // We must calculate the corresponding displacement on the horizontal axis
......
...@@ -136,7 +136,7 @@ void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -136,7 +136,7 @@ void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
else else
aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), _( "Yes" ), DARKGREEN ) );
msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 ); msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 );
aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, DARKGREEN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, DARKGREEN ) );
msg = ::CoordinateToString( m_Thickness ); msg = ::CoordinateToString( m_Thickness );
......
...@@ -385,7 +385,7 @@ void TEXTE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList ) ...@@ -385,7 +385,7 @@ void TEXTE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Mirror" ), msg, DARKGREEN ) );
msg.Printf( wxT( "%.1f" ), (float) m_Orient / 10 ); msg.Printf( wxT( "%.1f" ), m_Orient / 10.0 );
aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), msg, DARKGREEN ) ); aList.push_back( MSG_PANEL_ITEM( _( "Orient" ), msg, DARKGREEN ) );
msg = ::CoordinateToString( m_Thickness ); msg = ::CoordinateToString( m_Thickness );
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <gr_basic.h> #include <gr_basic.h>
#include <common.h> #include <common.h>
#include <trigo.h> #include <trigo.h>
#include <macros.h>
#include <class_drawpanel.h> #include <class_drawpanel.h>
#include <class_pcb_screen.h> #include <class_pcb_screen.h>
#include <drawtxt.h> #include <drawtxt.h>
...@@ -295,7 +296,7 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) ...@@ -295,7 +296,7 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
{ {
double dist = hypot( (double)dx, (double) dy ); double dist = hypot( (double)dx, (double) dy );
if( min_dist >= (int) dist ) if( min_dist >= KiROUND( dist ) )
result |= STARTPOINT; result |= STARTPOINT;
} }
...@@ -311,7 +312,7 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist ) ...@@ -311,7 +312,7 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
{ {
double dist = hypot( (double) dx, (double) dy ); double dist = hypot( (double) dx, (double) dy );
if( min_dist >= (int) dist ) if( min_dist >= KiROUND( dist ) )
result |= ENDPOINT; result |= ENDPOINT;
} }
...@@ -618,8 +619,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, ...@@ -618,8 +619,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
if( m_Shape == S_CIRCLE ) if( m_Shape == S_CIRCLE )
{ {
radius = (int) hypot( (double) ( m_End.x - m_Start.x ), radius = KiROUND( GetLineLength( m_Start, m_End ) );
(double) ( m_End.y - m_Start.y ) );
if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH ) if( aDC->LogicalToDeviceXRel( l_trace ) <= MIN_DRAW_WIDTH )
{ {
...@@ -691,7 +691,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, ...@@ -691,7 +691,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
#define THRESHOLD 10 #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 ) if( len < THRESHOLD * m_Width )
return; return;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <class_board_item.h> #include <class_board_item.h>
#include <class_board_connected_item.h> #include <class_board_connected_item.h>
#include <PolyLine.h> #include <PolyLine.h>
#include <trigo.h>
class TRACK; class TRACK;
...@@ -155,10 +156,7 @@ public: ...@@ -155,10 +156,7 @@ public:
*/ */
double GetLength() const double GetLength() const
{ {
double dx = m_Start.x - m_End.x; return GetLineLength( m_Start, m_End );
double dy = m_Start.y - m_End.y;
return hypot( dx, dy );
} }
/* Display on screen: */ /* Display on screen: */
......
...@@ -348,7 +348,7 @@ int CONNECTIONS::SearchConnectedTracks( const TRACK * aTrack ) ...@@ -348,7 +348,7 @@ int CONNECTIONS::SearchConnectedTracks( const TRACK * aTrack )
// We have a good candidate: calculate the actual distance // We have a good candidate: calculate the actual distance
// between ends, which should be <= dist max. // between ends, which should be <= dist max.
wxPoint delta = tracks_candidates[ii]->GetPoint() - position; 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 ) if( dist > dist_max )
continue; continue;
......
...@@ -122,7 +122,7 @@ void DialogEditModuleText::initDlg( ) ...@@ -122,7 +122,7 @@ void DialogEditModuleText::initDlg( )
msg.Printf( format, msg.Printf( format,
GetChars( m_module->GetReference() ), GetChars( m_module->GetReference() ),
GetChars( m_module->GetValue() ), GetChars( m_module->GetValue() ),
(float) m_module->GetOrientation() / 10 ); m_module->GetOrientation() / 10.0 );
} }
else else
{ {
......
...@@ -110,12 +110,13 @@ void PCB_EDIT_FRAME::OnOrientFootprints( wxCommandEvent& event ) ...@@ -110,12 +110,13 @@ void PCB_EDIT_FRAME::OnOrientFootprints( wxCommandEvent& event )
} }
bool PCB_EDIT_FRAME::ReOrientModules( const wxString& ModuleMask, int Orient, bool include_fixe ) bool PCB_EDIT_FRAME::ReOrientModules( const wxString& ModuleMask, int Orient,
bool include_fixe )
{ {
wxString line; wxString line;
bool modified = false; 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.0 );
if( !IsOK( this, line ) ) if( !IsOK( this, line ) )
return false; return false;
......
...@@ -280,7 +280,7 @@ void DIALOG_PAD_PROPERTIES::initValues() ...@@ -280,7 +280,7 @@ void DIALOG_PAD_PROPERTIES::initValues()
m_staticModuleSideValue->SetLabel( _( "Back side (footprint is mirrored)" ) ); m_staticModuleSideValue->SetLabel( _( "Back side (footprint is mirrored)" ) );
} }
msg.Printf( wxT( "%.1f" ), (double) module->GetOrientation() / 10 ); msg.Printf( wxT( "%.1f" ), module->GetOrientation() / 10.0 );
m_staticModuleRotValue->SetLabel( msg ); m_staticModuleRotValue->SetLabel( msg );
} }
......
...@@ -329,12 +329,12 @@ static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC, ...@@ -329,12 +329,12 @@ static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
delta = Dimension->m_featureLineDO - Dimension->m_featureLineGO; delta = Dimension->m_featureLineDO - Dimension->m_featureLineGO;
/* Calculating the direction of travel perpendicular to the selected axis. */ /* Calculating the direction of travel perpendicular to the selected axis. */
angle = atan2( (double)delta.y, (double)delta.x ) + (M_PI / 2); angle = atan2( delta.y, delta.x ) + (M_PI / 2);
delta = pos - Dimension->m_featureLineDO; delta = pos - Dimension->m_featureLineDO;
depl = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) ); depl = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
dx = (int) ( depl * cos( angle ) ); dx = KiROUND( depl * cos( angle ) );
dy = (int) ( depl * sin( angle ) ); dy = KiROUND( depl * sin( angle ) );
Dimension->m_crossBarO.x = Dimension->m_featureLineGO.x + dx; Dimension->m_crossBarO.x = Dimension->m_featureLineGO.x + dx;
Dimension->m_crossBarO.y = Dimension->m_featureLineGO.y + dy; Dimension->m_crossBarO.y = Dimension->m_featureLineGO.y + dy;
Dimension->m_crossBarF.x = Dimension->m_featureLineDO.x + dx; Dimension->m_crossBarF.x = Dimension->m_featureLineDO.x + dx;
......
...@@ -359,7 +359,7 @@ void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LAYER_MSK ...@@ -359,7 +359,7 @@ void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LAYER_MSK
if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist ) 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 ) if( dist <= maxdist )
{ {
...@@ -377,7 +377,7 @@ void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LAYER_MSK ...@@ -377,7 +377,7 @@ void Collect_TrackSegmentsToDrag( BOARD* aPcb, const wxPoint& aRefPos, LAYER_MSK
if( std::abs( delta.x ) <= maxdist && std::abs( delta.y ) <= maxdist ) 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 ) if( dist <= maxdist )
flag |= ENDPOINT; flag |= ENDPOINT;
......
...@@ -362,7 +362,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) ...@@ -362,7 +362,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads )
if( track->Type() == PCB_VIA_T ) if( track->Type() == PCB_VIA_T )
{ {
// Test distance between two vias, i.e. two circles, trivial case // 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, m_currentMarker = fillMarker( aRefSeg, track,
DRCE_VIA_NEAR_VIA, m_currentMarker ); DRCE_VIA_NEAR_VIA, m_currentMarker );
...@@ -527,7 +527,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads ) ...@@ -527,7 +527,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads )
segEndPoint = track->GetEnd(); segEndPoint = track->GetEnd();
delta = segEndPoint - segStartPoint; delta = segEndPoint - segStartPoint;
/* Compute the segment orientation (angle) en 0,1 degre */ // Compute the segment orientation (angle) en 0,1 degre
int angle = ArcTangente( delta.y, delta.x ); int angle = ArcTangente( delta.y, delta.x );
// Compute the segment lenght: delta.x = lenght after rotation // Compute the segment lenght: delta.x = lenght after rotation
...@@ -580,7 +580,7 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad ) ...@@ -580,7 +580,7 @@ bool DRC::checkClearancePadToPad( D_PAD* aRefPad, D_PAD* aPad )
// relativePadPos is the aPad shape position relative to the aRefPad shape position // relativePadPos is the aPad shape position relative to the aRefPad shape position
wxPoint relativePadPos = aPad->ReturnShapePos() - aRefPad->ReturnShapePos(); wxPoint relativePadPos = aPad->ReturnShapePos() - aRefPad->ReturnShapePos();
dist = (int) hypot( relativePadPos.x, relativePadPos.y ); dist = KiROUND( EuclideanNorm( relativePadPos ) );
// Quick test: Clearance is OK if the bounding circles are further away than "dist_min" // Quick test: Clearance is OK if the bounding circles are further away than "dist_min"
if( (dist - aRefPad->GetBoundingRadius() - aPad->GetBoundingRadius()) >= dist_min ) if( (dist - aRefPad->GetBoundingRadius() - aPad->GetBoundingRadius()) >= dist_min )
...@@ -1017,7 +1017,7 @@ bool DRC::checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength ) ...@@ -1017,7 +1017,7 @@ bool DRC::checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength )
if( aCentre.x > aLength ) // aCentre is after the ending point if( aCentre.x > aLength ) // aCentre is after the ending point
aCentre.x -= aLength; // move aCentre to the starting point of the segment 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 // distance between aCentre and the starting point or the ending point is < aRadius
return false; return false;
} }
......
...@@ -77,10 +77,8 @@ MARKER_PCB* DRC::fillMarker( TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, M ...@@ -77,10 +77,8 @@ MARKER_PCB* DRC::fillMarker( TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, M
// distance from end of aTrack. // distance from end of aTrack.
position = track->GetStart(); position = track->GetStart();
double dToEnd = hypot( endPos.x - aTrack->GetEnd().x, double dToEnd = GetLineLength( endPos, aTrack->GetEnd() );
endPos.y - aTrack->GetEnd().y ); double dToStart = GetLineLength( position, aTrack->GetEnd() );
double dToStart = hypot( position.x - aTrack->GetEnd().x,
position.y - aTrack->GetEnd().y );
if( dToEnd < dToStart ) if( dToEnd < dToStart )
position = endPos; position = endPos;
......
...@@ -314,7 +314,6 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge, ...@@ -314,7 +314,6 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge,
STROKE_T type_edge ) STROKE_T type_edge )
{ {
MODULE* module = GetBoard()->m_Modules; MODULE* module = GetBoard()->m_Modules;
int angle = 0;
if( module == NULL ) if( module == NULL )
return NULL; return NULL;
...@@ -331,7 +330,7 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge, ...@@ -331,7 +330,7 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge,
// Update characteristics of the segment or arc. // Update characteristics of the segment or arc.
aEdge->SetFlags( IS_NEW ); aEdge->SetFlags( IS_NEW );
aEdge->SetAngle( angle ); aEdge->SetAngle( 0 );
aEdge->SetShape( type_edge ); aEdge->SetShape( type_edge );
if( aEdge->GetShape() == S_ARC ) if( aEdge->GetShape() == S_ARC )
......
...@@ -1058,9 +1058,8 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module ) ...@@ -1058,9 +1058,8 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module )
case S_CIRCLE: case S_CIRCLE:
{ {
int radius = (int) hypot( int radius = KiROUND( GetLineLength( PtEdge->m_End0,
(double) ( PtEdge->m_End0.x - PtEdge->m_Start0.x ), PtEdge->m_Start0 ) );
(double) ( PtEdge->m_End0.y - PtEdge->m_Start0.y ) );
fprintf( aFile, "CIRCLE %g %g %g\n", fprintf( aFile, "CIRCLE %g %g %g\n",
PtEdge->m_Start0.x / SCALE_FACTOR, PtEdge->m_Start0.x / SCALE_FACTOR,
Yaxis_sign * PtEdge->m_Start0.y / SCALE_FACTOR, Yaxis_sign * PtEdge->m_Start0.y / SCALE_FACTOR,
......
...@@ -388,6 +388,7 @@ static void export_vrml_line( LAYER_NUM layer, double startx, double starty, //{ ...@@ -388,6 +388,7 @@ static void export_vrml_line( LAYER_NUM layer, double startx, double starty, //{
alpha = angle + PI2; alpha = angle + PI2;
fan.add( endx + r * cos( alpha ), endy + r * sin( alpha ) ); fan.add( endx + r * cos( alpha ), endy + r * sin( alpha ) );
// The 'start' side cap // The 'start' side cap
for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions ) for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions )
fan.add( startx + r * cos( alpha ), starty + r * sin( alpha ) ); fan.add( startx + r * cos( alpha ), starty + r * sin( alpha ) );
...@@ -538,7 +539,7 @@ static void export_vrml_arc( LAYER_NUM layer, double centerx, double centery, ...@@ -538,7 +539,7 @@ static void export_vrml_arc( LAYER_NUM layer, double centerx, double centery,
double divisions = arc_angle*M_PI/180.0 / count; 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); + ( width / 2);
double inner_radius = outer_radius - width; double inner_radius = outer_radius - width;
...@@ -568,7 +569,7 @@ static void export_vrml_varc( TRIANGLEBAG& triangles, ...@@ -568,7 +569,7 @@ static void export_vrml_varc( TRIANGLEBAG& triangles,
loop.z_bottom = layer_z[bottom_layer]; loop.z_bottom = layer_z[bottom_layer];
double start_angle = atan2( arc_starty - centery, arc_startx - centerx ); 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 ); int count = KiROUND( arc_angle / 360.0 * SEGM_COUNT_PER_360 );
...@@ -617,7 +618,7 @@ static void export_vrml_drawsegment( DRAWSEGMENT* drawseg ) //{{{ ...@@ -617,7 +618,7 @@ static void export_vrml_drawsegment( DRAWSEGMENT* drawseg ) //{{{
case S_CIRCLE: case S_CIRCLE:
export_vrml_hole( layer_triangles[layer], export_vrml_hole( layer_triangles[layer],
FIRST_COPPER_LAYER, LAST_COPPER_LAYER, x, y, FIRST_COPPER_LAYER, LAST_COPPER_LAYER, x, y,
hypot( xf - x, yf - y ) / 2 ); Distance( xf, yf, x, y ) / 2 );
break; break;
default: default:
...@@ -905,7 +906,8 @@ static void export_vrml_pad( BOARD* pcb, D_PAD* aPad ) //{{{ ...@@ -905,7 +906,8 @@ static void export_vrml_pad( BOARD* pcb, D_PAD* aPad ) //{{{
// Oblong hole (slot) // Oblong hole (slot)
export_vrml_slot( layer_triangles[EDGE_N], export_vrml_slot( layer_triangles[EDGE_N],
FIRST_COPPER_LAYER, LAST_COPPER_LAYER, 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,
aPad->GetOrientation() );
} }
else else
{ {
...@@ -1109,10 +1111,10 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, ...@@ -1109,10 +1111,10 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
// Do some quaternion munching // Do some quaternion munching
double q1[4], q2[4], rot[4]; double q1[4], q2[4], rot[4];
build_quat( 1, 0, 0, rotx / 180.0 * M_PI, q1 ); build_quat( 1, 0, 0, DEG2RAD( rotx ), q1 );
build_quat( 0, 1, 0, roty / 180.0 * M_PI, q2 ); build_quat( 0, 1, 0, DEG2RAD( roty ), q2 );
compose_quat( q1, q2, q1 ); 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 ); compose_quat( q1, q2, q1 );
// Note here aModule->GetOrientation() is in 0.1 degrees, // Note here aModule->GetOrientation() is in 0.1 degrees,
...@@ -1140,7 +1142,7 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule, ...@@ -1140,7 +1142,7 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
else // In normal mode, Y axis is reversed in Pcbnew. else // In normal mode, Y axis is reversed in Pcbnew.
NEGATE(offsety); NEGATE(offsety);
RotatePoint(&offsetx, &offsety, aModule->GetOrientation()); RotatePoint( &offsetx, &offsety, aModule->GetOrientation() );
fprintf( aOutputFile, " translation %g %g %g\n", fprintf( aOutputFile, " translation %g %g %g\n",
(offsetx + aModule->GetPosition().x) * boardIU2WRML, (offsetx + aModule->GetPosition().x) * boardIU2WRML,
......
...@@ -485,7 +485,7 @@ int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName, ...@@ -485,7 +485,7 @@ int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName,
sprintf( text, " %9.4f %9.4f %8.1f ", sprintf( text, " %9.4f %9.4f %8.1f ",
module_pos.x * conv_unit, module_pos.x * conv_unit,
-module_pos.y * conv_unit, -module_pos.y * conv_unit,
double(list[ii].m_Module->GetOrientation()) / 10 ); list[ii].m_Module->GetOrientation() / 10.0 );
LAYER_NUM layer = list[ii].m_Module->GetLayer(); LAYER_NUM layer = list[ii].m_Module->GetLayer();
...@@ -640,7 +640,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool ...@@ -640,7 +640,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool
module_pos.y * conv_unit ); module_pos.y * conv_unit );
fputs( line, rptfile ); fputs( line, rptfile );
sprintf( line, "orientation %.2f\n", (double) Module->GetOrientation() / 10 ); sprintf( line, "orientation %.2f\n", Module->GetOrientation() / 10.0 );
if( Module->GetLayer() == LAYER_N_FRONT ) if( Module->GetLayer() == LAYER_N_FRONT )
strcat( line, "layer component\n" ); strcat( line, "layer component\n" );
...@@ -675,7 +675,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool ...@@ -675,7 +675,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool
fputs( line, rptfile ); fputs( line, rptfile );
sprintf( line, "orientation %.2f\n", sprintf( line, "orientation %.2f\n",
double(pad->GetOrientation() - Module->GetOrientation()) / 10 ); (pad->GetOrientation() - Module->GetOrientation()) / 10.0 );
fputs( line, rptfile ); fputs( line, rptfile );
static const char* shape_name[6] = { "???", "Circ", "Rect", "Oval", "Trap", "Spec" }; static const char* shape_name[6] = { "???", "Circ", "Rect", "Oval", "Trap", "Spec" };
...@@ -751,7 +751,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile, double aCon ...@@ -751,7 +751,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile, double aCon
switch( PtDrawSegment->GetShape() ) switch( PtDrawSegment->GetShape() )
{ {
case S_CIRCLE: case S_CIRCLE:
radius = hypot( dx - ux0, dy - uy0 ); radius = Distance( ux0, uy0, dx, dy );
fprintf( rptfile, "$CIRCLE \n" ); fprintf( rptfile, "$CIRCLE \n" );
fprintf( rptfile, "centre %.6lf %.6lf\n", ux0, uy0 ); fprintf( rptfile, "centre %.6lf %.6lf\n", ux0, uy0 );
fprintf( rptfile, "radius %.6lf\n", radius ); fprintf( rptfile, "radius %.6lf\n", radius );
...@@ -764,7 +764,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile, double aCon ...@@ -764,7 +764,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile, double aCon
int endx = PtDrawSegment->GetEnd().x; int endx = PtDrawSegment->GetEnd().x;
int endy = PtDrawSegment->GetEnd().y; int endy = PtDrawSegment->GetEnd().y;
radius = hypot( dx - ux0, dy - uy0 ); radius = Distance( ux0, uy0, dx, dy );
RotatePoint( &endx, RotatePoint( &endx,
&endy, &endy,
PtDrawSegment->GetStart().x, PtDrawSegment->GetStart().x,
......
...@@ -564,7 +564,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR, ...@@ -564,7 +564,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR,
wxPoint padPos( (x1 + x2) / 2, (y1 + y2) / 2 ); 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 ) ); width ) );
padPos += module->GetPosition(); padPos += module->GetPosition();
......
...@@ -251,11 +251,8 @@ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize, ...@@ -251,11 +251,8 @@ bool Magnetize( PCB_EDIT_FRAME* frame, int aCurrentTool, wxSize aGridSize,
// a new track and that new track is parallel to the track the // 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 // mouse is on. Find the nearest end point of the track under mouse
// to the mouse and return that. // to the mouse and return that.
double distStart = hypot( double( curpos->x - track->GetStart().x ), double distStart = GetLineLength( *curpos, track->GetStart() );
double( curpos->y - track->GetStart().y )); double distEnd = GetLineLength( *curpos, track->GetEnd() );
double distEnd = hypot( double( curpos->x - track->GetEnd().x ),
double( curpos->y - track->GetEnd().y ));
// if track not via, or if its a via dragging but not with its adjacent track // if track not via, or if its a via dragging but not with its adjacent track
if( currTrack->Type() != PCB_VIA_T if( currTrack->Type() != PCB_VIA_T
......
...@@ -104,8 +104,8 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, ...@@ -104,8 +104,8 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
wxPoint poly[5]; wxPoint poly[5];
wxPoint pt = Mself.m_End - Mself.m_Start; wxPoint pt = Mself.m_End - Mself.m_Start;
int angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI ); double angle = -ArcTangente( pt.y, pt.x );
int len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) ); int len = KiROUND( EuclideanNorm( pt ) );
// calculate corners // calculate corners
pt.x = 0; pt.y = len / 4; pt.x = 0; pt.y = len / 4;
...@@ -125,8 +125,8 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, ...@@ -125,8 +125,8 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
Mself.m_End = aPanel->GetScreen()->GetCrossHairPosition(); Mself.m_End = aPanel->GetScreen()->GetCrossHairPosition();
pt = Mself.m_End - Mself.m_Start; pt = Mself.m_End - Mself.m_Start;
angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI ); angle = -ArcTangente( pt.y, pt.x );
len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) ); len = KiROUND( EuclideanNorm( pt ) );
// calculate new corners // calculate new corners
pt.x = 0; pt.y = len / 4; pt.x = 0; pt.y = len / 4;
...@@ -195,7 +195,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC ) ...@@ -195,7 +195,7 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
Mself.m_End = GetScreen()->GetCrossHairPosition(); Mself.m_End = GetScreen()->GetCrossHairPosition();
wxPoint pt = Mself.m_End - Mself.m_Start; 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; Mself.lng = min_len;
// Enter the desired length. // Enter the desired length.
...@@ -398,8 +398,8 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer, ...@@ -398,8 +398,8 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
#define ADJUST_SIZE 0.988 #define ADJUST_SIZE 0.988
wxPoint pt = aEndPoint - aStartPoint; wxPoint pt = aEndPoint - aStartPoint;
int angle = -KiROUND( atan2( (double) pt.y, (double) pt.x ) * 1800.0 / M_PI ); double angle = -ArcTangente( pt.y, pt.x );
int min_len = KiROUND( sqrt( (double) pt.x * pt.x + (double) pt.y * pt.y ) ); int min_len = KiROUND( EuclideanNorm( pt ) );
int segm_len = 0; // length of segments int segm_len = 0; // length of segments
int full_len; // full len of shape (sum of lenght of all segments + arcs) int full_len; // full len of shape (sum of lenght of all segments + arcs)
......
...@@ -97,8 +97,7 @@ void PCB_ARC::Parse( XNODE* aNode, ...@@ -97,8 +97,7 @@ void PCB_ARC::Parse( XNODE* aNode,
int alpha2 = ArcTangente( endY - m_positionY, endX - m_positionX ); int alpha2 = ArcTangente( endY - m_positionY, endX - m_positionX );
m_angle = alpha1 - alpha2; m_angle = alpha1 - alpha2;
if( m_angle < 0 ) NORMALIZE_ANGLE_POS( m_angle );
m_angle = 3600 + m_angle;
} }
else if( aNode->GetName() == wxT( "arc" ) ) else if( aNode->GetName() == wxT( "arc" ) )
{ {
......
...@@ -388,15 +388,13 @@ void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge ) ...@@ -388,15 +388,13 @@ void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge )
break; break;
case S_CIRCLE: case S_CIRCLE:
radius = (int) hypot( (double) ( end.x - pos.x ), radius = KiROUND( GetLineLength( end, pos ) );
(double) ( end.y - pos.y ) );
m_plotter->ThickCircle( pos, radius * 2, thickness, GetMode() ); m_plotter->ThickCircle( pos, radius * 2, thickness, GetMode() );
break; break;
case S_ARC: case S_ARC:
{ {
radius = (int) hypot( (double) ( end.x - pos.x ), radius = KiROUND( GetLineLength( end, pos ) );
(double) ( end.y - pos.y ) );
double startAngle = ArcTangente( end.y - pos.y, end.x - pos.x ); double startAngle = ArcTangente( end.y - pos.y, end.x - pos.x );
...@@ -607,14 +605,12 @@ void BRDITEMS_PLOTTER::PlotDrawSegment( DRAWSEGMENT* aSeg ) ...@@ -607,14 +605,12 @@ void BRDITEMS_PLOTTER::PlotDrawSegment( DRAWSEGMENT* aSeg )
switch( aSeg->GetShape() ) switch( aSeg->GetShape() )
{ {
case S_CIRCLE: case S_CIRCLE:
radius = (int) hypot( (double) ( end.x - start.x ), radius = KiROUND( GetLineLength( end, start ) );
(double) ( end.y - start.y ) );
m_plotter->ThickCircle( start, radius * 2, thickness, GetMode() ); m_plotter->ThickCircle( start, radius * 2, thickness, GetMode() );
break; break;
case S_ARC: case S_ARC:
radius = (int) hypot( (double) ( end.x - start.x ), radius = KiROUND( GetLineLength( end, start ) );
(double) ( end.y - start.y ) );
StAngle = ArcTangente( end.y - start.y, end.x - start.x ); StAngle = ArcTangente( end.y - start.y, end.x - start.x );
EndAngle = StAngle + aSeg->GetAngle(); EndAngle = StAngle + aSeg->GetAngle();
m_plotter->ThickArc( start, -EndAngle, -StAngle, radius, thickness, GetMode() ); m_plotter->ThickArc( start, -EndAngle, -StAngle, radius, thickness, GetMode() );
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "pcbnew_footprint_wizards.h" #include "pcbnew_footprint_wizards.h"
#include <python_scripting.h> #include <python_scripting.h>
#include <stdio.h> #include <stdio.h>
#include <macros.h>
PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD( PyObject* aWizard ) PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD( PyObject* aWizard )
......
...@@ -769,8 +769,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule ) ...@@ -769,8 +769,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule )
// lexer/beautifier, and the spec is not clear that this is // lexer/beautifier, and the spec is not clear that this is
// required. Fixed point floats are all that should be needed. // required. Fixed point floats are all that should be needed.
double radius = hypot( double(graphic->GetStart().x - graphic->GetEnd().x), double radius = GetLineLength( graphic->GetStart(), graphic->GetEnd() );
double(graphic->GetStart().y - graphic->GetEnd().y) );
// better if evenly divisible into 360 // better if evenly divisible into 360
const int DEGREE_INTERVAL = 18; // 18 means 20 line segments const int DEGREE_INTERVAL = 18; // 18 means 20 line segments
...@@ -779,8 +778,8 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule ) ...@@ -779,8 +778,8 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule )
radians < 2 * M_PI; radians < 2 * M_PI;
radians += DEGREE_INTERVAL * M_PI / 180.0 ) radians += DEGREE_INTERVAL * M_PI / 180.0 )
{ {
wxPoint point( int( radius * cos( radians ) ), wxPoint point( KiROUND( radius * cos( radians ) ),
int( radius * sin( radians ) ) ); KiROUND( radius * sin( radians ) ) );
point += graphic->m_Start0; // an offset point += graphic->m_Start0; // an offset
......
...@@ -65,8 +65,8 @@ ...@@ -65,8 +65,8 @@
extern void BuildUnconnectedThermalStubsPolygonList( std::vector<CPolyPt>& aCornerBuffer, extern void BuildUnconnectedThermalStubsPolygonList( std::vector<CPolyPt>& aCornerBuffer,
BOARD* aPcb, ZONE_CONTAINER* aZone, BOARD* aPcb, ZONE_CONTAINER* aZone,
double aArcCorrection, double aArcCorrection,
int aRoundPadThermalRotation); int aRoundPadThermalRotation);
extern void Test_For_Copper_Island_And_Remove( BOARD* aPcb, extern void Test_For_Copper_Island_And_Remove( BOARD* aPcb,
ZONE_CONTAINER* aZone_container ); ZONE_CONTAINER* aZone_container );
......
...@@ -1047,8 +1047,8 @@ void CPolyLine::AppendArc( int xi, int yi, int xf, int yf, int xc, int yc, int n ...@@ -1047,8 +1047,8 @@ void CPolyLine::AppendArc( int xi, int yi, int xf, int yf, int xc, int yc, int n
// generate arc // generate arc
for( int ic = 0; ic < num; ic++ ) for( int ic = 0; ic < num; ic++ )
{ {
int x = KiROUND( xc + radius * cos( theta ) ); int x = xc + KiROUND( radius * cos( theta ) );
int y = KiROUND( yc + radius * sin( theta ) ); int y = yc + KiROUND( radius * sin( theta ) );
AppendCorner( x, y ); AppendCorner( x, y );
theta += th_d; theta += th_d;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment