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 )
aVertices[ii].y *= m_MatScale.y;
aVertices[ii].z *= m_MatScale.z;
/* adjust rotation */
// adjust rotation
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 )
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 )
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) */
#define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB)
......
......@@ -553,9 +553,8 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment )
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() ) );
Draw3D_ZaxisCylinder( segment->GetStart(), radius,
thickness, segment->GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
......@@ -587,9 +586,8 @@ void EDA_3D_CANVAS::Draw3D_DrawSegment( DRAWSEGMENT* segment )
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() ) );
Draw3D_ZaxisCylinder( segment->GetStart(), radius,
thickness, segment->GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
......@@ -806,9 +804,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas )
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 ) );
Draw3D_ZaxisCylinder( m_Start, radius,
thickness, GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
......@@ -848,9 +844,7 @@ void EDGE_MODULE::Draw3D( EDA_3D_CANVAS* glcanvas )
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 ) );
Draw3D_ZaxisCylinder( m_Start, radius,
thickness, GetWidth(),
zpos, g_Parm_3D_Visu.m_BiuTo3Dunits );
......
......@@ -377,10 +377,9 @@ void Draw3D_ArcSegment( const wxPoint& aCenterPos, const wxPoint& aStartPoint,
std::vector <CPolyPt> cornerBuffer;
TransformArcToPolygon( cornerBuffer, aCenterPos, aStartPoint, aArcAngle,
slice, aWidth );
slice, aWidth );
Draw3D_SolidHorizontalPolyPolygons( cornerBuffer, aZpos, aThickness, aBiuTo3DUnits );
}
......
......@@ -389,8 +389,7 @@ void PLOTTER::segmentAsOval( const wxPoint& start, const wxPoint& end, int width
else
orient = -(int) ( RAD2DEG( atan2( (double)size.y, (double)size.x ) ) * 10.0 );
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 );
......
......@@ -433,11 +433,11 @@ void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
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 swaps sizes
EXCHG( size.x, size.y );
// Pass through
......
......@@ -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 @@ void TransformRoundedEndsSegmentToPolygon( std::vector <CPolyPt>& aCornerBuffer,
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;
......@@ -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
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
......
......@@ -1075,7 +1075,7 @@ void GRArc1( EDA_RECT* ClipBox, wxDC* DC, int x1, int y1, int x2, int y2,
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 ) )
......
......@@ -55,6 +55,7 @@ LAYER_MSK g_TabAllCopperLayerMask[NB_COPPER_LAYERS] = {
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;
......
......@@ -29,7 +29,8 @@ static inline double square( int x ) // helper function to calculate 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
if( aEnd.x == aStart.x )
......@@ -84,7 +85,7 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist
// 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 @@ bool TestSegmentHit( wxPoint aRefPoint, wxPoint aStart, wxPoint aEnd, int aDist
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,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 )
{
......@@ -193,8 +199,7 @@ int ArcTangente( int dy, int dx )
return 1800 - 450;
}
fangle = atan2( (double) dy, (double) dx ) / M_PI * 1800;
return KiROUND( fangle );
return atan2( dy, dx ) / M_PI * 1800;
}
......@@ -202,11 +207,7 @@ void RotatePoint( int* pX, int* pY, double angle )
{
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 )
......@@ -287,11 +288,7 @@ void RotatePoint( double* pX, double* pY, double angle )
{
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 )
......@@ -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 )
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 @@ void LIB_ARC::calcRadiusAngles()
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
......
......@@ -107,8 +107,7 @@ bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra
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 @@ void LIB_CIRCLE::calcEdit( const wxPoint& aPosition )
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
{
......
......@@ -159,7 +159,7 @@ void SCH_BASE_FRAME::UpdateStatusBar()
}
// 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
......
#include <macros.h>
#include <transform.h>
#include <common.h>
#include <trigo.h>
TRANSFORM& TRANSFORM::operator=( const TRANSFORM& aTransform )
......@@ -77,7 +79,7 @@ bool TRANSFORM::MapAngles( int* aAngle1, int* aAngle2 ) const
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 );
......
......@@ -444,7 +444,7 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent,
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 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( GERBER_DRAW_ITEM* aParent,
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 );
int angle = ArcTangente( delta.y, delta.x );
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
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;
......
......@@ -332,7 +332,8 @@ void GBR_TO_PCB_EXPORTER::export_segarc_copper_item( GERBER_DRAW_ITEM* aGbrItem,
{
seg_start = curr_start;
wxPoint curr_end = start;
RotatePoint( &curr_end, aGbrItem->m_ArcCentre, -(int) (DELTA_ANGLE * ii * 1800 / M_PI) );
RotatePoint( &curr_end, aGbrItem->m_ArcCentre,
-(int) (DELTA_ANGLE * ii * 1800 / M_PI) );
seg_end = curr_end;
// Reverse Y axis:
NEGATE( seg_start.y );
......
......@@ -802,14 +802,10 @@ void GERBVIEW_FRAME::UpdateStatusBar()
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;
// atan2 in the 0,0 case returns 0
theta = RAD2DEG( atan2( -dy, dx ) );
ro = sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
ro = hypot( dx, dy );
wxString formatter;
switch( g_UserUnit )
{
......@@ -868,7 +864,7 @@ void GERBVIEW_FRAME::UpdateStatusBar()
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 );
}
}
......
......@@ -339,8 +339,8 @@ static void fillArcPOLY( GERBER_DRAW_ITEM* aGbrItem,
* 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);
int start_angle = ArcTangente( start.y, start.x );
int end_angle = ArcTangente( end.y, end.x );
// dummyTrack has right geometric parameters, but
// fillArcGBRITEM calculates arc parameters for a draw function that expects
......
......@@ -57,8 +57,8 @@ static inline const wxChar* GetChars( const wxString& s )
#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
......
......@@ -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 @@ void RotatePoint( int *pX, int *pY, int cx, int cy, double angle );
* 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,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
* 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
* 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
//! 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 )
{
// Some of 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 +138,21 @@ double CrossProduct( wxPoint vectorA, wxPoint vectorB );
* @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.
* 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
......@@ -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>
......@@ -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,
shape_pos.x + dx, shape_pos.y + dy,
(int) aPad->GetOrientation(),
aPad->GetOrientation(),
aPad->GetLayerMask(), color, op_logic );
}
}
......@@ -561,8 +561,7 @@ void TraceFilledRectangle( int ux0, int uy0, int ux1, int uy1,
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;
......@@ -689,7 +688,7 @@ void DrawSegmentQcq( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer
if( dx )
{
angle = (int) ( atan2( (double) dy, (double) dx ) * 1800 / M_PI );
angle = ArcTangente( dy, dx );
}
else
{
......@@ -758,7 +757,7 @@ void TraceCircle( int ux0, int uy0, int ux1, int uy1, int lg, LAYER_NUM layer,
int ii;
int angle;
radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) );
radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
x0 = x1 = radius;
y0 = y1 = 0;
......@@ -803,7 +802,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
int angle, StAngle;
radius = (int) hypot( (double) (ux1 - ux0), (double) (uy1 - uy0) );
radius = KiROUND( Distance( ux0, uy0, ux1, uy1 ) );
x0 = ux1 - ux0;
y0 = uy1 - uy0;
......@@ -813,7 +812,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
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,11 +825,7 @@ void TraceArc( int ux0, int uy0, int ux1, int uy1, int ArcAngle, int lg,
angle = ( ArcAngle * ii ) / nb_segm;
angle += StAngle;
while( angle >= 3600 )
angle -= 3600;
while( angle < 0 )
angle += 3600;
NORMALIZE_ANGLE_POS( angle );
x1 = (int) ( radius * cos( 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 )
layerMask = GetLayerMask( PtText->GetLayer() );
TraceFilledRectangle( ux0 - marge, uy0 - marge, ux1 + marge,
uy1 + marge, (int) (PtText->GetOrientation()),
uy1 + marge, PtText->GetOrientation(),
layerMask, HOLE, WRITE_CELL );
TraceFilledRectangle( ux0 - via_marge, uy0 - via_marge,
ux1 + via_marge, uy1 + via_marge,
(int) (PtText->GetOrientation()),
PtText->GetOrientation(),
layerMask, VIA_IMPOSSIBLE, WRITE_OR_CELL );
}
break;
......
......@@ -46,7 +46,7 @@
#include <collectors.h>
#include <class_drawpanel.h>
#include <vector2d.h>
#include <trigo.h>
// Configuration entry names.
static const wxString UserGridSizeXEntry( wxT( "PcbUserGrid_X" ) );
......@@ -563,14 +563,9 @@ void PCB_BASE_FRAME::UpdateStatusBar()
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;
theta = ArcTangente( -dy, dx ) / 10;
ro = sqrt( ( (double) dx * dx ) + ( (double) dy * dy ) );
ro = hypot( dx, dy );
wxString formatter;
switch( g_UserUnit )
{
......@@ -661,7 +656,7 @@ void PCB_BASE_FRAME::UpdateStatusBar()
#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 );
}
}
......
......@@ -475,7 +475,7 @@ void CreateThermalReliefPadPolygon( std::vector<CPolyPt>& aCornerBuffer,
double dtmp = sqrt( ( (double) outer_radius * outer_radius ) -
( (double) corner.x * corner.x ) );
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
corner_end.x = corner.y;
......
......@@ -240,10 +240,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
// Calculate dimension value
measure = KiROUND( hypot( (double) deltax, (double) deltay ) );
if( deltax || deltay )
angle = atan2( (double) deltay, (double) deltax );
else
angle = 0.0;
angle = atan2( deltay, deltax );
// Calculation of parameters X and Y dimensions of the arrows and lines.
hx = hy = ii;
......@@ -266,12 +263,12 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
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;
......@@ -312,11 +309,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
double newAngle = -(angle * 1800 / M_PI);
if( newAngle < 0 )
newAngle += 3600;
if( newAngle >= 3600 )
newAngle -= 3600;
NORMALIZE_ANGLE_POS( newAngle );
if( newAngle > 900 && newAngle < 2700 )
newAngle -= 1800;
......
......@@ -138,16 +138,13 @@ const wxPoint DRAWSEGMENT::GetArcEnd() const
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 +153,7 @@ void DRAWSEGMENT::SetAngle( double 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,
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 )
{
......@@ -235,8 +232,8 @@ void DRAWSEGMENT::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
case S_ARC:
int StAngle, EndAngle;
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( !panel->GetPrintMirrored() )
......@@ -336,7 +333,7 @@ void DRAWSEGMENT::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
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.0 );
aList.push_back( MSG_PANEL_ITEM( _("Angle"), msg, RED ) );
break;
......@@ -434,7 +431,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition )
{
wxPoint relPos = aPosition - GetCenter();
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 ) )
{
......@@ -449,8 +446,7 @@ bool DRAWSEGMENT::HitTest( const wxPoint& aPosition )
// 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;
......
......@@ -33,6 +33,8 @@
#include <class_board_item.h>
#include <PolyLine.h>
#include <math_for_graphics.h>
#include <trigo.h>
class LINE_READER;
......@@ -134,7 +136,7 @@ public:
*/
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 );
}
......@@ -184,9 +186,7 @@ public:
*/
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 )
......
......@@ -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 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
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 @@ void EDGE_MODULE::Draw( EDA_DRAW_PANEL* panel, wxDC* DC, GR_DRAWMODE draw_mode,
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 )
......
......@@ -495,7 +495,7 @@ void MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
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 ) );
// Controls on right side of the dialog
......
......@@ -555,10 +555,10 @@ void D_PAD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM>& aList )
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.0,
module_orient / 10.0 );
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 ) );
......@@ -586,7 +586,6 @@ bool D_PAD::IsOnLayer( LAYER_NUM aLayer ) const
bool D_PAD::HitTest( const wxPoint& aPosition )
{
int dx, dy;
double dist;
wxPoint shape_pos = ReturnShapePos();
......@@ -604,9 +603,7 @@ bool D_PAD::HitTest( const wxPoint& aPosition )
switch( m_PadShape & 0x7F )
{
case PAD_CIRCLE:
dist = hypot( delta.x, delta.y );
if( KiROUND( dist ) <= dx )
if( KiROUND( EuclideanNorm( delta ) ) <= dx )
return true;
break;
......
......@@ -527,7 +527,7 @@ void D_PAD::DrawShape( EDA_RECT* aClipBox, wxDC* aDC, PAD_DRAWINFO& aDrawInfo )
// area of the pad
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;
NORMALIZE_ANGLE_90( t_angle );
......@@ -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
* 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;
......@@ -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) )
return;
......@@ -696,7 +698,7 @@ void D_PAD::BuildPadPolygon( wxPoint aCoord[4], wxSize aInflateValue, int aRotat
if( delta.y ) // lower and upper segment is horizontal
{
// 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
// We must calculate the corresponding displacement on the horizontal axis
......
......@@ -136,7 +136,7 @@ void TEXTE_PCB::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
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.0 );
aList.push_back( MSG_PANEL_ITEM( _( "Orientation" ), msg, DARKGREEN ) );
msg = ::CoordinateToString( m_Thickness );
......
......@@ -385,7 +385,7 @@ void TEXTE_MODULE::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
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 ) );
msg = ::CoordinateToString( m_Thickness );
......
......@@ -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 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
{
double dist = hypot( (double)dx, (double) dy );
if( min_dist >= (int) dist )
if( min_dist >= KiROUND( dist ) )
result |= STARTPOINT;
}
......@@ -311,7 +312,7 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
{
double dist = hypot( (double) dx, (double) dy );
if( min_dist >= (int) dist )
if( min_dist >= KiROUND( dist ) )
result |= ENDPOINT;
}
......@@ -618,8 +619,7 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
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 @@ void TRACK::Draw( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode,
#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;
......
......@@ -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 @@ public:
*/
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: */
......
......@@ -348,7 +348,7 @@ int CONNECTIONS::SearchConnectedTracks( const TRACK * aTrack )
// 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;
......
......@@ -122,7 +122,7 @@ void DialogEditModuleText::initDlg( )
msg.Printf( format,
GetChars( m_module->GetReference() ),
GetChars( m_module->GetValue() ),
(float) m_module->GetOrientation() / 10 );
m_module->GetOrientation() / 10.0 );
}
else
{
......
......@@ -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;
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 ) )
return false;
......
......@@ -280,7 +280,7 @@ void DIALOG_PAD_PROPERTIES::initValues()
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 );
}
......
......@@ -329,12 +329,12 @@ static void BuildDimension( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
delta = Dimension->m_featureLineDO - Dimension->m_featureLineGO;
/* 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;
depl = ( delta.x * cos( angle ) ) + ( delta.y * sin( angle ) );
dx = (int) ( depl * cos( angle ) );
dy = (int) ( depl * sin( angle ) );
dx = KiROUND( depl * cos( angle ) );
dy = KiROUND( depl * sin( angle ) );
Dimension->m_crossBarO.x = Dimension->m_featureLineGO.x + dx;
Dimension->m_crossBarO.y = Dimension->m_featureLineGO.y + dy;
Dimension->m_crossBarF.x = Dimension->m_featureLineDO.x + dx;
......
......@@ -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 )
{
int dist = (int) hypot( (double) delta.x, (double) delta.y );
int dist = KiROUND( EuclideanNorm( delta ) );
if( dist <= maxdist )
{
......@@ -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 )
{
int dist = (int) hypot( (double) delta.x, (double) delta.y );
int dist = KiROUND( EuclideanNorm( delta ) );
if( dist <= maxdist )
flag |= ENDPOINT;
......
......@@ -362,7 +362,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads )
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 );
......@@ -527,7 +527,7 @@ bool DRC::doTrackDrc( TRACK* aRefSeg, TRACK* aStart, bool testPads )
segEndPoint = track->GetEnd();
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 );
// Compute the segment lenght: delta.x = lenght after rotation
......@@ -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
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"
if( (dist - aRefPad->GetBoundingRadius() - aPad->GetBoundingRadius()) >= dist_min )
......@@ -1017,7 +1017,7 @@ bool DRC::checkMarginToCircle( wxPoint aCentre, int aRadius, int aLength )
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;
}
......
......@@ -77,10 +77,8 @@ MARKER_PCB* DRC::fillMarker( TRACK* aTrack, BOARD_ITEM* aItem, int aErrorCode, M
// 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;
......
......@@ -314,7 +314,6 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge,
STROKE_T type_edge )
{
MODULE* module = GetBoard()->m_Modules;
int angle = 0;
if( module == NULL )
return NULL;
......@@ -331,7 +330,7 @@ EDGE_MODULE* FOOTPRINT_EDIT_FRAME::Begin_Edge_Module( EDGE_MODULE* aEdge,
// 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 )
......
......@@ -1058,9 +1058,8 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module )
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,
......
......@@ -388,6 +388,7 @@ static void export_vrml_line( LAYER_NUM layer, double startx, double starty, //{
alpha = angle + PI2;
fan.add( endx + r * cos( alpha ), endy + r * sin( alpha ) );
// The 'start' side cap
for( alpha = angle + PI2; alpha < angle + 3 * PI2; alpha += PI2 / divisions )
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,
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);
double inner_radius = outer_radius - width;
......@@ -568,7 +569,7 @@ static void export_vrml_varc( TRIANGLEBAG& triangles,
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 +618,7 @@ static void export_vrml_drawsegment( DRAWSEGMENT* drawseg ) //{{{
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 +906,8 @@ static void export_vrml_pad( BOARD* pcb, D_PAD* aPad ) //{{{
// 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,
aPad->GetOrientation() );
}
else
{
......@@ -1109,10 +1111,10 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
// 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,
......@@ -1140,7 +1142,7 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
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,
......
......@@ -485,7 +485,7 @@ int PCB_EDIT_FRAME::DoGenFootprintsPositionFile( const wxString& aFullFileName,
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.0 );
LAYER_NUM layer = list[ii].m_Module->GetLayer();
......@@ -640,7 +640,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool
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.0 );
if( Module->GetLayer() == LAYER_N_FRONT )
strcat( line, "layer component\n" );
......@@ -675,7 +675,7 @@ bool PCB_EDIT_FRAME::DoGenFootprintsReport( const wxString& aFullFilename, bool
fputs( line, rptfile );
sprintf( line, "orientation %.2f\n",
double(pad->GetOrientation() - Module->GetOrientation()) / 10 );
(pad->GetOrientation() - Module->GetOrientation()) / 10.0 );
fputs( line, rptfile );
static const char* shape_name[6] = { "???", "Circ", "Rect", "Oval", "Trap", "Spec" };
......@@ -751,7 +751,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile, double aCon
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 );
fprintf( rptfile, "radius %.6lf\n", radius );
......@@ -764,7 +764,7 @@ void WriteDrawSegmentPcb( DRAWSEGMENT* PtDrawSegment, FILE* rptfile, double aCon
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,
......
......@@ -564,7 +564,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR,
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 ) );
padPos += module->GetPosition();
......
......@@ -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
// 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
......
......@@ -104,8 +104,8 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
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 @@ static void ShowBoundingBoxMicroWaveInductor( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
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 @@ MODULE* PCB_EDIT_FRAME::Genere_Self( wxDC* DC )
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 @@ int BuildCornersList_S_Shape( std::vector <wxPoint>& aBuffer,
#define ADJUST_SIZE 0.988
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)
......
......@@ -97,8 +97,7 @@ void PCB_ARC::Parse( XNODE* aNode,
int 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" ) )
{
......
......@@ -388,15 +388,13 @@ void BRDITEMS_PLOTTER::Plot_1_EdgeModule( EDGE_MODULE* aEdge )
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 );
......@@ -607,14 +605,12 @@ void BRDITEMS_PLOTTER::PlotDrawSegment( DRAWSEGMENT* aSeg )
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() );
......
......@@ -30,6 +30,7 @@
#include "pcbnew_footprint_wizards.h"
#include <python_scripting.h>
#include <stdio.h>
#include <macros.h>
PYTHON_FOOTPRINT_WIZARD::PYTHON_FOOTPRINT_WIZARD( PyObject* aWizard )
......
......@@ -769,8 +769,7 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule )
// 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
......@@ -779,8 +778,8 @@ IMAGE* SPECCTRA_DB::makeIMAGE( BOARD* aBoard, MODULE* aModule )
radians < 2 * M_PI;
radians += DEGREE_INTERVAL * M_PI / 180.0 )
{
wxPoint point( int( radius * cos( radians ) ),
int( radius * sin( radians ) ) );
wxPoint point( KiROUND( radius * cos( radians ) ),
KiROUND( radius * sin( radians ) ) );
point += graphic->m_Start0; // an offset
......
......@@ -65,8 +65,8 @@
extern void BuildUnconnectedThermalStubsPolygonList( std::vector<CPolyPt>& aCornerBuffer,
BOARD* aPcb, ZONE_CONTAINER* aZone,
double aArcCorrection,
int aRoundPadThermalRotation);
double aArcCorrection,
int aRoundPadThermalRotation);
extern void Test_For_Copper_Island_And_Remove( BOARD* aPcb,
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
// 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;
}
......
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