Commit cb49ca5a authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

More int casts to rounding conversions

parent b2a76062
......@@ -39,9 +39,9 @@
// Thickness of copper
// TODO: define the actual copper thickness by user
#define COPPER_THICKNESS (int)(0.035 * IU_PER_MM) // for 35 u
#define TECH_LAYER_THICKNESS (int)(0.04 * IU_PER_MM)
#define EPOXY_THICKNESS (int)(1.6 * IU_PER_MM) // for 1.6 mm
#define COPPER_THICKNESS KiROUND( 0.035 * IU_PER_MM ) // for 35 µm
#define TECH_LAYER_THICKNESS KiROUND( 0.04 * IU_PER_MM )
#define EPOXY_THICKNESS KiROUND( 1.6 * IU_PER_MM ) // for 1.6 mm
/* INFO3D_VISU in an helper class to store parameters like scaling factors,
......
......@@ -123,7 +123,7 @@ public: INFO3D_VISU();
*/
int GetLayerZcoordBIU( int aLayerId )
{
return (int) (m_LayerZcoord[aLayerId] / m_BiuTo3Dunits );
return KiROUND( m_LayerZcoord[aLayerId] / m_BiuTo3Dunits );
}
/**
......@@ -137,7 +137,7 @@ public: INFO3D_VISU();
int GetCopperThicknessBIU() const
{
return m_DrawFlags[FL_USE_COPPER_THICKNESS] ?
(int) (m_CopperThickness / m_BiuTo3Dunits )
KiROUND( m_CopperThickness / m_BiuTo3Dunits )
: 0;
}
......@@ -147,7 +147,7 @@ public: INFO3D_VISU();
*/
int GetEpoxyThicknessBIU() const
{
return (int) (m_EpoxyThickness / m_BiuTo3Dunits );
return KiROUND( m_EpoxyThickness / m_BiuTo3Dunits );
}
/**
......@@ -160,7 +160,7 @@ public: INFO3D_VISU();
int GetNonCopperLayerThicknessBIU() const
{
return m_DrawFlags[FL_USE_COPPER_THICKNESS] ?
(int) (m_NonCopperLayerThickness / m_BiuTo3Dunits )
KiROUND( m_NonCopperLayerThickness / m_BiuTo3Dunits )
: 0;
}
......
......@@ -389,7 +389,7 @@ void PLOTTER::segmentAsOval( const wxPoint& start, const wxPoint& end, int width
else
orient = -ArcTangente( size.y, size.x );
size.x = KiROUND( hypot( size.x, size.y ) ) + width;
size.x = KiROUND( EuclideanNorm( size ) ) + width;
size.y = width;
FlashPadOval( center, size, orient, tracemode );
......
......@@ -43,7 +43,7 @@
#include <transform.h>
// Helper function
static inline wxPoint twoPointVector( wxPoint startPoint, wxPoint endPoint )
static inline wxPoint twoPointVector( const wxPoint &startPoint, const wxPoint &endPoint )
{
return endPoint - startPoint;
}
......@@ -195,7 +195,7 @@ bool LIB_ARC::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTran
NEGATE( relativePosition.y ); // reverse Y axis
int distance = KiROUND( EuclideanNorm( twoPointVector( m_Pos, relativePosition ) ) );
int distance = KiROUND( GetLineLength( m_Pos, relativePosition ) );
if( abs( distance - m_Radius ) > aThreshold )
return false;
......
......@@ -105,9 +105,7 @@ bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra
if( aThreshold < 0 )
aThreshold = GetPenSize() / 2;
wxPoint relpos = aPosRef - aTransform.TransformCoordinate( m_Pos );
int dist = KiROUND( EuclideanNorm( relpos ) );
int dist = KiROUND( GetLineLength( aPosRef, aTransform.TransformCoordinate( m_Pos ) ) );
if( abs( dist - m_Radius ) <= aThreshold )
return true;
......@@ -345,9 +343,7 @@ void LIB_CIRCLE::calcEdit( const wxPoint& aPosition )
if( m_Flags == IS_NEW )
SetEraseLastDrawItem();
int dx = m_Pos.x - aPosition.x;
int dy = m_Pos.y - aPosition.y;
m_Radius = KiROUND( hypot( dx, dy ) );
m_Radius = KiROUND( GetLineLength( m_Pos, aPosition ) );
}
else
{
......
......@@ -233,6 +233,8 @@ void GBR_TO_PCB_EXPORTER::export_non_copper_item( GERBER_DRAW_ITEM* aGbrItem, LA
#define SEG_SHAPE 0
#define ARC_SHAPE 2
int shape = SEG_SHAPE;
// please note: the old PCB format only has integer support for angles
int angle = 0;
wxPoint seg_start, seg_end;
......
......@@ -28,7 +28,7 @@ void GERBVIEW_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition )
{
if( DrawStruct && DrawStruct->GetFlags() )
{
msg.Printf( wxT( "GERBVIEW_FRAME::OnLeftClick err: Struct %d, m_Flags = %X" ),
msg.Printf( wxT( "GERBVIEW_FRAME::OnLeftClick err: Struct %u, m_Flags = %X" ),
(unsigned) DrawStruct->Type(),
(unsigned) DrawStruct->GetFlags() );
wxFAIL_MSG( msg );
......
......@@ -81,6 +81,12 @@ inline double EuclideanNorm( const wxPoint &vector )
return hypot( vector.x, vector.y );
}
inline double EuclideanNorm( const wxSize &vector )
{
// this is working with doubles, too
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
......
......@@ -942,8 +942,8 @@ double PCB_EDIT_FRAME::Compute_Ratsnest_PlaceModule( wxDC* DC )
// the penalty is max for 45 degrees ratsnests,
// and 0 for horizontal or vertical ratsnests.
// For Horizontal and Vertical ratsnests, dy = 0;
icout = hypot( (double) dx, (double) dy * 2.0 );
cout += icout; /* Total cost = sum of costs of each connection. */
icout = hypot( dx, dy * 2.0 );
cout += icout; // Total cost = sum of costs of each connection
}
return cout;
......
......@@ -431,7 +431,7 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer
switch( m_PadShape )
{
case PAD_CIRCLE:
dx = (int) ( dx * aCorrectionFactor );
dx = KiROUND( dx * aCorrectionFactor );
TransformCircleToPolygon( aCornerBuffer, PadShapePos, dx,
aCircleToSegmentsCount );
break;
......@@ -444,13 +444,13 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer
wxPoint shape_offset;
if( dy > dx ) // Oval pad X/Y ratio for choosing translation axis
{
dy = (int) ( dy * aCorrectionFactor );
dy = KiROUND( dy * aCorrectionFactor );
shape_offset.y = dy - dx;
width = dx * 2;
}
else //if( dy <= dx )
{
dx = (int) ( dx * aCorrectionFactor );
dx = KiROUND( dx * aCorrectionFactor );
shape_offset.x = dy - dx;
width = dy * 2;
}
......@@ -474,8 +474,8 @@ void D_PAD:: TransformShapeWithClearanceToPolygon( CPOLYGONS_LIST& aCornerBuffer
angle = m_Orient;
// Corner rounding radius
int rounding_radius = (int) ( aClearanceValue * aCorrectionFactor );
int angle_pg; // Polygon increment angle
int rounding_radius = KiROUND( aClearanceValue * aCorrectionFactor );
double angle_pg; // Polygon increment angle
for( int i = 0; i < aCircleToSegmentsCount / 4 + 1; i++ )
{
......@@ -716,7 +716,7 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
std::vector <wxPoint> corners_buffer;
// Radius of outer arcs of the shape corrected for arc approximation by lines
int outer_radius = (int) ( (dx + aThermalGap) * aCorrectionFactor );
int outer_radius = KiROUND( (dx + aThermalGap) * aCorrectionFactor );
// Crosspoint of thermal spoke sides, the first point of polygon buffer
corners_buffer.push_back( wxPoint( copper_thickness.x / 2, copper_thickness.y / 2 ) );
......@@ -725,7 +725,7 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
// and first seg of arc approx
corner.x = copper_thickness.x / 2;
int y = outer_radius - (aThermalGap / 4);
corner.y = (int) sqrt( ( ( (double) y * y ) - (double) corner.x * corner.x ) );
corner.y = KiROUND( sqrt( ( (double) y * y - (double) corner.x * corner.x ) ) );
if( aThermalRot != 0 )
corners_buffer.push_back( corner );
......@@ -733,9 +733,8 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
// calculate the starting point of the outter arc
corner.x = copper_thickness.x / 2;
double dtmp = sqrt( ( (double) outer_radius * outer_radius ) -
( (double) corner.x * corner.x ) );
corner.y = (int) dtmp;
corner.y = KiROUND( sqrt( ( (double) outer_radius * outer_radius ) -
( (double) corner.x * corner.x ) ) );
RotatePoint( &corner, 90 ); // 9 degrees is the spoke fillet size
// calculate the ending point of the outter arc
......@@ -818,8 +817,8 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
if( copper_thickness.x > deltasize )
{
corner.x = copper_thickness.x / 2;
corner.y = (int) sqrt( ( (double) outer_radius * outer_radius ) -
( (double) ( corner.x - delta ) * ( corner.x - deltasize ) ) );
corner.y = KiROUND( sqrt( ( (double) outer_radius * outer_radius ) -
( (double) ( corner.x - delta ) * ( corner.x - deltasize ) ) ) );
corner.x -= deltasize;
/* creates an intermediate point, to have a > 90 deg angle
......@@ -843,13 +842,13 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
last_corner.y = copper_thickness.y / 2;
int px = outer_radius - (aThermalGap / 4);
last_corner.x =
(int) sqrt( ( ( (double) px * px ) - (double) last_corner.y * last_corner.y ) );
KiROUND( sqrt( ( ( (double) px * px ) - (double) last_corner.y * last_corner.y ) ) );
// Arc stop point calculation, the intersecting point of cutout arc and thermal spoke edge
corner_end.y = copper_thickness.y / 2;
corner_end.x =
(int) sqrt( ( (double) outer_radius *
outer_radius ) - ( (double) corner_end.y * corner_end.y ) );
KiROUND( sqrt( ( (double) outer_radius *
outer_radius ) - ( (double) corner_end.y * corner_end.y ) ) );
RotatePoint( &corner_end, -90 ); // 9 degrees of thermal fillet
// calculate intermediate arc points till limit is reached
......@@ -948,7 +947,7 @@ void CreateThermalReliefPadPolygon( CPOLYGONS_LIST& aCornerBuffer,
corners_buffer.push_back( wxPoint( -(aThermalGap / 4 + copper_thickness.x / 2), -dy ) );
int angle = aPad.GetOrientation();
int rounding_radius = (int) ( aThermalGap * aCorrectionFactor ); // Corner rounding radius
int rounding_radius = KiROUND( aThermalGap * aCorrectionFactor ); // Corner rounding radius
int angle_pg; // Polygon increment angle
for( int i = 0; i < aCircleToSegmentsCount / 4 + 1; i++ )
......
......@@ -238,7 +238,7 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
deltay = m_featureLineDO.y - m_featureLineGO.y;
// Calculate dimension value
measure = KiROUND( hypot( (double) deltax, (double) deltay ) );
measure = KiROUND( hypot( deltax, deltay ) );
angle = atan2( deltay, deltax );
......@@ -248,8 +248,8 @@ void DIMENSION::AdjustDimensionDetails( bool aDoNotChangeText )
// Taking into account the slope of the side lines.
if( measure )
{
hx = (abs) ( (int) ( ( (double) deltay * hx ) / measure ) );
hy = (abs) ( (int) ( ( (double) deltax * hy ) / measure ) );
hx = abs( KiROUND( ( (double) deltay * hx ) / measure ) );
hy = abs( KiROUND( ( (double) deltax * hy ) / measure ) );
if( m_featureLineGO.x > m_crossBarO.x )
hx = -hx;
......
......@@ -103,14 +103,13 @@ int D_PAD::boundingRadius() const
break;
case PAD_RECT:
radius = 1 + (int) ( sqrt( (double) m_Size.y * m_Size.y
+ (double) m_Size.x * m_Size.x ) / 2 );
radius = 1 + KiROUND( EuclideanNorm( m_Size ) / 2 );
break;
case PAD_TRAPEZOID:
x = m_Size.x + std::abs( m_DeltaSize.y ); // Remember: m_DeltaSize.y is the m_Size.x change
y = m_Size.y + std::abs( m_DeltaSize.x ); // Remember: m_DeltaSize.x is the m_Size.y change
radius = 1 + (int) ( sqrt( (double) y * y + (double) x * x ) / 2 );
radius = 1 + KiROUND( hypot( x, y ) / 2 );
break;
default:
......
......@@ -284,33 +284,22 @@ STATUS_FLAGS TRACK::IsPointOnEnds( const wxPoint& point, int min_dist )
if( min_dist < 0 )
min_dist = m_Width / 2;
int dx = m_Start.x - point.x;
int dy = m_Start.y - point.y;
if( min_dist == 0 )
{
if( (dx == 0) && (dy == 0 ) )
if( m_Start == point )
result |= STARTPOINT;
if( m_End == point )
result |= ENDPOINT;
}
else
{
double dist = hypot( (double)dx, (double) dy );
double dist = GetLineLength( m_Start, point );
if( min_dist >= KiROUND( dist ) )
result |= STARTPOINT;
}
dx = m_End.x - point.x;
dy = m_End.y - point.y;
if( min_dist == 0 )
{
if( (dx == 0) && (dy == 0 ) )
result |= ENDPOINT;
}
else
{
double dist = hypot( (double) dx, (double) dy );
dist = GetLineLength( m_End, point );
if( min_dist >= KiROUND( dist ) )
result |= ENDPOINT;
......@@ -1152,7 +1141,7 @@ void TRACK::GetMsgPanelInfoBase( std::vector< MSG_PANEL_ITEM >& aList )
// Display drill value
int drill_value = GetDrillValue();
msg = ::CoordinateToString( (unsigned) drill_value );
msg = ::CoordinateToString( drill_value );
wxString title = _( "Drill" );
title += wxT( " " );
......
......@@ -540,13 +540,14 @@ bool ZONE_CONTAINER::HitTestForEdge( const wxPoint& refPos )
end_segm = tmp; // end_segm is the beginning of the current outline
}
/* test the dist between segment and ref point */
int dist = (int) GetPointToLineSegmentDistance( refPos.x,
refPos.y,
m_Poly->m_CornersList[item_pos].x,
m_Poly->m_CornersList[item_pos].y,
m_Poly->m_CornersList[end_segm].x,
m_Poly->m_CornersList[end_segm].y );
// test the dist between segment and ref point
int dist = KiROUND( GetPointToLineSegmentDistance(
refPos.x,
refPos.y,
m_Poly->m_CornersList[item_pos].x,
m_Poly->m_CornersList[item_pos].y,
m_Poly->m_CornersList[end_segm].x,
m_Poly->m_CornersList[end_segm].y ) );
if( dist < min_dist )
{
......
......@@ -98,7 +98,7 @@ void DIALOG_MODULE_BOARD_EDITOR::InitBoardProperties()
(m_CurrentModule->GetLayer() == LAYER_N_BACK) ? 1 : 0 );
bool select = false;
switch( (int) m_CurrentModule->GetOrientation() )
switch( int( m_CurrentModule->GetOrientation() ) )
{
case 0:
m_OrientCtrl->SetSelection( 0 );
......
......@@ -21,8 +21,8 @@
#include <dialog_print_using_printer_base.h>
#define PEN_WIDTH_MAX_VALUE ( (int)(5 * IU_PER_MM) )
#define PEN_WIDTH_MIN_VALUE ( (int)(0.005 * IU_PER_MM) )
#define PEN_WIDTH_MAX_VALUE ( KiROUND( 5 * IU_PER_MM ) )
#define PEN_WIDTH_MIN_VALUE ( KiROUND( 0.005 * IU_PER_MM ) )
extern int g_DrawDefaultLineThickness;
......
......@@ -1028,7 +1028,7 @@ static inline int USCALE( unsigned arg, unsigned num, unsigned den )
{
int ii;
ii = (int) ( ( (double) arg * num ) / den );
ii = KiROUND( ( (double) arg * num ) / den );
return ii;
}
......
......@@ -652,7 +652,7 @@ static void PushTrack( EDA_DRAW_PANEL* panel )
}
//Helpre function: Draws Via circle and Via Clearence circle.
//Helper function: Draws Via circle and Via Clearance circle.
inline void DrawViaCirclesWhenEditingNewTrack( EDA_RECT* aPanelClipBox,
wxDC* aDC, const wxPoint& aPos,
int aViaRadius,
......
......@@ -406,7 +406,7 @@ static void export_vrml_circle( LAYER_NUM layer, double startx, double starty, /
double hole, radius;
FLAT_RING ring;
radius = hypot( startx - endx, starty - endy ) + ( width / 2);
radius = Distance( startx, starty, endx, endy ) + ( width / 2);
hole = radius - width;
for( double alpha = 0; alpha < M_PI * 2; alpha += INC_ANGLE )
......
......@@ -109,15 +109,15 @@ bool EXCELLON_WRITER::GenDrillMapFile( const wxString& aFullFileName,
wxSize pageSizeIU = pageA4.GetSizeIU();
// Reserve a margin around the page.
int margin = (int) (20 * IU_PER_MM );
int margin = KiROUND( 20 * IU_PER_MM );
// Calculate a scaling factor to print the board on the sheet
double Xscale = (double) ( pageSizeIU.x - ( 2 * margin ) ) / bbbox.GetWidth();
double Xscale = double( pageSizeIU.x - ( 2 * margin ) ) / bbbox.GetWidth();
// We should print the list of drill sizes, so reserve room for it
// 60% height for board 40% height for list
int ypagesize_for_board = (int) (pageSizeIU.y * 0.6);
double Yscale = (double) ( ypagesize_for_board - margin ) / bbbox.GetHeight();
int ypagesize_for_board = KiROUND( pageSizeIU.y * 0.6 );
double Yscale = double( ypagesize_for_board - margin ) / bbbox.GetHeight();
scale = std::min( Xscale, Yscale );
......@@ -126,8 +126,9 @@ bool EXCELLON_WRITER::GenDrillMapFile( const wxString& aFullFileName,
// So the scale is clipped at 3.0;
scale = std::min( scale, 3.0 );
offset.x = (int) ( (double) bbbox.Centre().x - ( pageSizeIU.x / 2.0 ) / scale );
offset.y = (int) ( (double) bbbox.Centre().y -
offset.x = KiROUND( double( bbbox.Centre().x ) -
( pageSizeIU.x / 2.0 ) / scale );
offset.y = KiROUND( double( bbbox.Centre().y ) -
( ypagesize_for_board / 2.0 ) / scale );
if( aFormat == PLOT_FORMAT_PDF )
......@@ -200,7 +201,7 @@ bool EXCELLON_WRITER::GenDrillMapFile( const wxString& aFullFileName,
int intervalle = 0;
char line[1024];
wxString msg;
int textmarginaftersymbol = (int) (2 * IU_PER_MM);
int textmarginaftersymbol = KiROUND( 2 * IU_PER_MM );
// Set Drill Symbols width
plotter->SetDefaultLineWidth( 0.2 * IU_PER_MM / scale );
......@@ -213,18 +214,18 @@ bool EXCELLON_WRITER::GenDrillMapFile( const wxString& aFullFileName,
int charSize = 3 * IU_PER_MM; // text size in IUs
double charScale = 1.0 / scale; // real scale will be 1/scale,
// because the global plot scale is scale
TextWidth = (int) ( (charSize * charScale) / 10 ); // Set text width (thickness)
intervalle = (int) ( charSize * charScale ) + TextWidth;
TextWidth = KiROUND( (charSize * charScale) / 10.0 ); // Set text width (thickness)
intervalle = KiROUND( charSize * charScale ) + TextWidth;
// Trace information.
plotX = (int) ( (double) bbbox.GetX() + textmarginaftersymbol * charScale );
plotX = KiROUND( bbbox.GetX() + textmarginaftersymbol * charScale );
plotY = bbbox.GetBottom() + intervalle;
// Plot title "Info"
wxString Text = wxT( "Drill Map:" );
plotter->Text( wxPoint( plotX, plotY ), UNSPECIFIED_COLOR, Text, 0,
wxSize( (int) ( charSize * charScale ),
(int) ( charSize * charScale ) ),
wxSize( KiROUND( charSize * charScale ),
KiROUND( charSize * charScale ) ),
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
TextWidth, false, false );
......@@ -237,10 +238,10 @@ bool EXCELLON_WRITER::GenDrillMapFile( const wxString& aFullFileName,
plotY += intervalle;
plot_diam = (int) m_toolListBuffer[ii].m_Diameter;
x = (int) ( (double) plotX - textmarginaftersymbol * charScale
- (double) plot_diam / 2.0 );
y = (int) ( (double) plotY + (double) charSize * charScale );
plot_diam = KiROUND( m_toolListBuffer[ii].m_Diameter );
x = KiROUND( plotX - textmarginaftersymbol * charScale
- plot_diam / 2.0 );
y = KiROUND( plotY + charSize * charScale );
plotter->Marker( wxPoint( x, y ), plot_diam, ii );
// List the diameter of each drill in mm and inches.
......@@ -268,13 +269,12 @@ bool EXCELLON_WRITER::GenDrillMapFile( const wxString& aFullFileName,
msg += FROM_UTF8( line );
plotter->Text( wxPoint( plotX, y ), UNSPECIFIED_COLOR,
msg,
0, wxSize( (int) ( charSize * charScale ),
(int) ( charSize * charScale ) ),
0, wxSize( KiROUND( charSize * charScale ),
KiROUND( charSize * charScale ) ),
GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_VJUSTIFY_CENTER,
TextWidth, false, false );
intervalle = (int) ( charSize * charScale ) + TextWidth;
intervalle = (int) ( intervalle * 1.2 );
intervalle = KiROUND( (( charSize * charScale ) + TextWidth) * 1.2);
if( intervalle < (plot_diam + (1 * IU_PER_MM / scale) + TextWidth) )
intervalle = plot_diam + (1 * IU_PER_MM / scale) + TextWidth;
......
......@@ -229,7 +229,7 @@ void PCB_BASE_FRAME::GlobalChange_PadSettings( D_PAD* aPad,
// Search and copy the name of library reference.
MODULE* Module_Ref = module;
int pad_orient = aPad->GetOrientation() - Module_Ref->GetOrientation();
double pad_orient = aPad->GetOrientation() - Module_Ref->GetOrientation();
// Prepare an undo list:
if( aSaveForUndo )
......
......@@ -408,7 +408,7 @@ MODULE* GPCB_FPL_CACHE::parseMODULE( LINE_READER* aLineReader ) throw( IO_ERROR,
int tsize = ( parseInt( parameters[paramCnt-3] ) * TEXT_DEFAULT_SIZE ) / 100;
int thickness = module->Reference().GetSize().x / 6;
tsize = std::max( (int)(5 * IU_PER_MILS), tsize ); // Ensure a minimal size = 5 mils
tsize = std::max( KiROUND(5 * IU_PER_MILS), tsize ); // Ensure a minimal size = 5 mils
module->Reference().SetSize( wxSize( tsize, tsize ) );
module->Reference().SetThickness( thickness );
module->Value().SetOrientation( module->Reference().GetOrientation() );
......
......@@ -64,7 +64,7 @@ class BOARD;
#define PLOT_MAX_SCALE 100.0
// Small drill marks (small pad holes) diameter value
#define SMALL_DRILL (int)( 0.35 * IU_PER_MM )
#define SMALL_DRILL KiROUND( 0.35 * IU_PER_MM )
// A helper class to plot board items
......
......@@ -250,8 +250,8 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
scalex, scaley );
wxSize PlotAreaSizeInUserUnits;
PlotAreaSizeInUserUnits.x = (int) (PlotAreaSizeInPixels.x/scalex);
PlotAreaSizeInUserUnits.y = (int) (PlotAreaSizeInPixels.y/scaley);
PlotAreaSizeInUserUnits.x = KiROUND( PlotAreaSizeInPixels.x / scalex );
PlotAreaSizeInUserUnits.y = KiROUND( PlotAreaSizeInPixels.y / scaley );
wxLogTrace( tracePrinting, wxT( "Scaled plot area in user units: x=%d, y=%d" ),
PlotAreaSizeInUserUnits.x, PlotAreaSizeInUserUnits.y );
......@@ -309,7 +309,7 @@ void BOARD_PRINTOUT_CONTROLLER::DrawPage()
* (this is the upper left corner) but the Y axis is reversed, therefore the plotting area
* is the y coordinate values from - PlotAreaSize.y to 0 */
int y_dc_offset = PlotAreaSizeInPixels.y;
y_dc_offset = (int) ( ( double ) y_dc_offset * userscale );
y_dc_offset = KiROUND( y_dc_offset * userscale );
dc->SetDeviceOrigin( 0, y_dc_offset );
wxLogTrace( tracePrinting, wxT( "Device origin: x=%d, y=%d" ),
......
......@@ -439,7 +439,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IO_ERROR )
if( place->side == T_front )
{
// convert from degrees to tenths of degrees used in KiCad.
int orientation = (int) (place->rotation * 10.0);
int orientation = KiROUND( place->rotation * 10.0 );
if( module->GetLayer() != LAYER_N_FRONT )
{
......@@ -451,7 +451,7 @@ void SPECCTRA_DB::FromSESSION( BOARD* aBoard ) throw( IO_ERROR )
}
else if( place->side == T_back )
{
int orientation = (int) ((place->rotation + 180.0) * 10.0);
int orientation = KiROUND( (place->rotation + 180.0) * 10.0 );
if( module->GetLayer() != LAYER_N_BACK )
{
......
......@@ -203,7 +203,7 @@ void BuildUnconnectedThermalStubsPolygonList( CPOLYGONS_LIST& aCornerBuffer,
copperThickness = 0;
// Leave a small extra size to the copper area inside to pad
copperThickness += (int)(IU_PER_MM * 0.04);
copperThickness += KiROUND( IU_PER_MM * 0.04 );
startpoint.x = std::min( pad->GetSize().x, copperThickness );
startpoint.y = std::min( pad->GetSize().y, copperThickness );
......@@ -216,7 +216,7 @@ void BuildUnconnectedThermalStubsPolygonList( CPOLYGONS_LIST& aCornerBuffer,
int fAngle = pad->GetOrientation();
if( pad->GetShape() == PAD_CIRCLE )
{
endpoint.x = (int) ( endpoint.x * aArcCorrection );
endpoint.x = KiROUND( endpoint.x * aArcCorrection );
endpoint.y = endpoint.x;
fAngle = aRoundPadThermalRotation;
}
......
......@@ -111,7 +111,8 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
ClipperLib::Polygon& polygon = normalized_polygons[ii];
cornerslist.clear();
for( unsigned jj = 0; jj < polygon.size(); jj++ )
cornerslist.push_back( KI_POLY_POINT( (int)polygon[jj].X, (int)polygon[jj].Y ) );
cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ),
KiROUND( polygon[jj].Y ) ) );
mainpoly.set( cornerslist.begin(), cornerslist.end() );
all_contours.push_back( mainpoly );
}
......@@ -137,7 +138,8 @@ int CPolyLine::NormalizeAreaOutlines( std::vector<CPolyLine*>* aNewPolygonList )
ClipperLib::Polygon& polygon = normalized_polygons[ii];
cornerslist.clear();
for( unsigned jj = 0; jj < polygon.size(); jj++ )
cornerslist.push_back( KI_POLY_POINT( (int)polygon[jj].X, (int)polygon[jj].Y ) );
cornerslist.push_back( KI_POLY_POINT( KiROUND( polygon[jj].X ),
KiROUND( polygon[jj].Y ) ) );
bpl::set_points( poly_tmp, cornerslist.begin(), cornerslist.end() );
polysholes.push_back( poly_tmp );
}
......@@ -367,27 +369,27 @@ CPolyLine* CPolyLine::Chamfer( unsigned int aDistance )
yb = m_CornersList[index + 1].y - y1;
}
unsigned int lena = (unsigned int) sqrt( (double) (xa * xa + ya * ya) );
unsigned int lenb = (unsigned int) sqrt( (double) (xb * xb + yb * yb) );
unsigned int lena = KiROUND( hypot( xa, ya ) );
unsigned int lenb = KiROUND( hypot( xb, yb ) );
unsigned int distance = aDistance;
// Chamfer one half of an edge at most
if( 0.5 * lena < distance )
distance = (unsigned int) (0.5 * (double) lena);
distance = int( 0.5 * lena );
if( 0.5 * lenb < distance )
distance = (unsigned int) (0.5 * (double) lenb);
distance = int( 0.5 * lenb );
nx = (int) ( (double) (distance * xa) / sqrt( (double) (xa * xa + ya * ya) ) );
ny = (int) ( (double) (distance * ya) / sqrt( (double) (xa * xa + ya * ya) ) );
nx = KiROUND( (distance * xa) / hypot( xa, ya ) );
ny = KiROUND( (distance * ya) / hypot( xa, ya ) );
if( index == startIndex )
newPoly->Start( GetLayer(), x1 + nx, y1 + ny, GetHatchStyle() );
else
newPoly->AppendCorner( x1 + nx, y1 + ny );
nx = (int) ( (double) (distance * xb) / sqrt( (double) (xb * xb + yb * yb) ) );
ny = (int) ( (double) (distance * yb) / sqrt( (double) (xb * xb + yb * yb) ) );
nx = KiROUND( (distance * xb) / hypot( xb, yb ) );
ny = KiROUND( (distance * yb) / hypot( xb, yb ) );
newPoly->AppendCorner( x1 + nx, y1 + ny );
}
......@@ -447,8 +449,8 @@ CPolyLine* CPolyLine::Fillet( unsigned int aRadius, unsigned int aSegments )
yb = m_CornersList[index + 1].y - y1;
}
double lena = sqrt( (double) (xa * xa + ya * ya) );
double lenb = sqrt( (double) (xb * xb + yb * yb) );
double lena = hypot( xa, ya );
double lenb = hypot( xb, yb );
double cosine = ( xa * xb + ya * yb ) / ( lena * lenb );
double radius = aRadius;
......@@ -500,19 +502,19 @@ CPolyLine* CPolyLine::Fillet( unsigned int aRadius, unsigned int aSegments )
if( xa * yb - ya * xb <= 0 )
deltaAngle *= -1;
nx = xc + xs + 0.5;
ny = yc + ys + 0.5;
nx = xc + xs;
ny = yc + ys;
if( index == startIndex )
newPoly->Start( GetLayer(), (int) nx, (int) ny, GetHatchStyle() );
newPoly->Start( GetLayer(), KiROUND( nx ), KiROUND( ny ), GetHatchStyle() );
else
newPoly->AppendCorner( (int) nx, (int) ny );
newPoly->AppendCorner( KiROUND( nx ), KiROUND( ny ) );
for( unsigned int j = 0; j < segments; j++ )
{
nx = xc + cos( startAngle + (j + 1) * deltaAngle ) * radius + 0.5;
ny = yc - sin( startAngle + (j + 1) * deltaAngle ) * radius + 0.5;
newPoly->AppendCorner( (int) nx, (int) ny );
nx = xc + cos( startAngle + (j + 1) * deltaAngle ) * radius;
ny = yc - sin( startAngle + (j + 1) * deltaAngle ) * radius;
newPoly->AppendCorner( KiROUND( nx ), KiROUND( ny ) );
}
}
......@@ -791,7 +793,7 @@ void CPolyLine::Hatch()
else
spacing = m_hatchPitch * 2;
// set the "lenght" of hatch lines (the lenght on horizontal axis)
// set the "length" of hatch lines (the lenght on horizontal axis)
double hatch_line_len = m_hatchPitch;
// To have a better look, give a slope depending on the layer
......@@ -802,13 +804,13 @@ void CPolyLine::Hatch()
if( slope_flag == 1 )
{
max_a = (int) (max_y - slope * min_x);
min_a = (int) (min_y - slope * max_x);
max_a = KiROUND( max_y - slope * min_x );
min_a = KiROUND( min_y - slope * max_x );
}
else
{
max_a = (int) (max_y - slope * max_x);
min_a = (int) (min_y - slope * min_x);
max_a = KiROUND( max_y - slope * max_x );
min_a = KiROUND( min_y - slope * min_x );
}
min_a = (min_a / spacing) * spacing;
......@@ -864,13 +866,13 @@ void CPolyLine::Hatch()
if( ok )
{
wxPoint point( (int) x, (int) y );
wxPoint point( KiROUND( x ), KiROUND( y ) );
pointbuffer.push_back( point );
}
if( ok == 2 )
{
wxPoint point( (int) x2, (int) y2 );
wxPoint point( KiROUND( x2 ), KiROUND( y2 ) );
pointbuffer.push_back( point );
}
......@@ -1036,7 +1038,7 @@ void CPolyLine::SetEndContour( int ic, bool end_contour )
void CPolyLine::AppendArc( int xi, int yi, int xf, int yf, int xc, int yc, int num )
{
// get radius
double radius = hypot( (double) (xi - xc), (double) (yi - yc) );
double radius = ::Distance( xi, yi, xf, yf );
// get angles of start and finish
double th_i = atan2( (double) (yi - yc), (double) (xi - xc) );
......
......@@ -5,7 +5,7 @@
#include <cmath>
#include <float.h>
#include <limits.h>
#include <common.h>
#include <fctsys.h>
#include <PolyLine.h>
......@@ -13,12 +13,6 @@
static bool InRange( double x, double xi, double xf );
double Distance( double x1, double y1, double x2, double y2 )
{
return hypot( x1 - x2, y1 - y2 );
}
/* Function FindSegmentIntersections
* find intersections between line segment (xi,yi) to (xf,yf)
* and line segment (xi2,yi2) to (xf2,yf2)
......@@ -203,10 +197,10 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
if( InRange( y1, y1i, y1f ) && InRange( x1, x2i, x2f ) && InRange( y1, y2i, y2f ) )
{
if( x )
*x = (int) x1;
*x = KiROUND( x1 );
if( y )
*y = (int) y1;
*y = KiROUND( y1 );
if( d )
*d = 0.0;
......@@ -231,10 +225,10 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
if( InRange( x1, x1i, x1f ) && InRange( x1, x2i, x2f ) && InRange( y1, y2i, y2f ) )
{
if( x )
*x = (int) x1;
*x = KiROUND( x1 );
if( y )
*y = (int) y1;
*y = KiROUND( y1 );
if( d )
*d = 0.0;
......@@ -259,10 +253,10 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
if( InRange( x1, x1i, x1f ) && InRange( y1, y1i, y1f ) && InRange( y1, y2i, y2f ) )
{
if( x )
*x = (int) x1;
*x = KiROUND( x1 );
if( y )
*y = (int) y1;
*y = KiROUND( y1 );
if( d )
*d = 0.0;
......@@ -287,10 +281,10 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
if( InRange( x1, x1i, x1f ) && InRange( y1, y1i, y1f ) )
{
if( x )
*x = (int) x1;
*x = KiROUND( x1 );
if( y )
*y = (int) y1;
*y = KiROUND( y1 );
if( d )
*d = 0.0;
......@@ -318,10 +312,10 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
if( InRange( x1, x1i, x1f ) && InRange( y1, y1i, y1f ) )
{
if( x )
*x = (int) x1;
*x = KiROUND( x1 );
if( y )
*y = (int) y1;
*y = KiROUND( y1 );
if( d )
*d = 0.0;
......@@ -365,10 +359,10 @@ bool TestForIntersectionOfStraightLineSegments( int x1i, int y1i, int x1f, int y
}
if( x )
*x = (int) xx;
*x = KiROUND( xx );
if( y )
*y = (int) yy;
*y = KiROUND( yy );
if( d )
*d = dist;
......@@ -405,7 +399,7 @@ int GetClearanceBetweenSegments( int x1i, int y1i, int x1f, int y1f, int w1,
double dist;
TestForIntersectionOfStraightLineSegments( x1i, y1i, x1f, y1f,
x2i, y2i, x2f, y2f, &xx, &yy, &dist );
int d = (int) dist - ( (w1 + w2) / 2 );
int d = KiROUND( dist - (w1 + w2) / 2 );
if( d < 0 )
d = 0;
......
......@@ -60,8 +60,12 @@ double GetPointToLineSegmentDistance( int x, int y, int xi, int yi, int xf, int
* if b > DBL_MAX/10, assume vertical line at x = a
* returns closest point on line in xpp, ypp
*/
double GetPointToLineDistance( double a, double b, int x, int y, double * xp=NULL, double * yp=NULL );
double GetPointToLineDistance( double a, double b, int x, int y,
double * xp=NULL, double * yp=NULL );
double Distance( double x1, double y1, double x2, double y2 );
inline double Distance( double x1, double y1, double x2, double y2 )
{
return hypot( x1 - x2, y1 - y2 );
}
#endif
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