Avoid divide-by-zero.
This commit is contained in:
parent
415aaabc29
commit
45ca0a5ab8
|
@ -63,6 +63,9 @@ IMAGE_SIZE::IMAGE_SIZE()
|
|||
|
||||
void IMAGE_SIZE::SetOutputSizeFromInitialImageSize()
|
||||
{
|
||||
// Safety-check to guarantee no divide-by-zero
|
||||
m_originalDPI = std::max( 1, m_originalDPI );
|
||||
|
||||
// Set the m_outputSize value from the m_originalSizePixels and the selected unit
|
||||
if( m_unit == EDA_UNITS::MILLIMETRES )
|
||||
{
|
||||
|
@ -97,6 +100,9 @@ int IMAGE_SIZE::GetOutputDPI()
|
|||
outputDPI = KiROUND( m_outputSize );
|
||||
}
|
||||
|
||||
// Zero is not a DPI, and may cause divide-by-zero errors...
|
||||
outputDPI = std::max( 1, outputDPI );
|
||||
|
||||
return outputDPI;
|
||||
}
|
||||
|
||||
|
|
|
@ -556,6 +556,11 @@ void AM_PRIMITIVE::ConvertShapeToPolygon( const GERBER_DRAW_ITEM* aParent,
|
|||
// params = center.x (unused here), center.y (unused here), outside diam, inside diam, crosshair thickness
|
||||
int outerRadius = scaletoIU( params[2].GetValue( tool ), m_GerbMetric ) / 2;
|
||||
int innerRadius = scaletoIU( params[3].GetValue( tool ), m_GerbMetric ) / 2;
|
||||
|
||||
// Safety checks to guarantee no divide-by-zero
|
||||
outerRadius = std::max( 1, outerRadius );
|
||||
innerRadius = std::max( 1, innerRadius );
|
||||
|
||||
int halfthickness = scaletoIU( params[4].GetValue( tool ), m_GerbMetric ) / 2;
|
||||
double angle_start = RAD2DECIDEG( asin( (double) halfthickness / innerRadius ) );
|
||||
|
||||
|
|
|
@ -42,6 +42,9 @@ int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree )
|
|||
// calculate the number of segments to approximate a circle by segments
|
||||
// given the max distance between the middle of a segment and the circle
|
||||
|
||||
// avoid divide-by-zero
|
||||
aRadius = std::max( 1, aRadius );
|
||||
|
||||
// error relative to the radius value:
|
||||
double rel_error = (double)aErrorMax / aRadius;
|
||||
// minimal arc increment in degrees:
|
||||
|
@ -67,8 +70,7 @@ double GetCircletoPolyCorrectionFactor( int aSegCountforCircle )
|
|||
* therefore, to move the middle of the segment to the circle (distance = radius)
|
||||
* the correctionFactor is 1 /cos( PI/aSegCountforCircle )
|
||||
*/
|
||||
if( aSegCountforCircle < MIN_SEGCOUNT_FOR_CIRCLE )
|
||||
aSegCountforCircle = MIN_SEGCOUNT_FOR_CIRCLE;
|
||||
aSegCountforCircle = std::max( MIN_SEGCOUNT_FOR_CIRCLE, aSegCountforCircle );
|
||||
|
||||
return 1.0 / cos( M_PI / aSegCountforCircle );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue