Replace round_nearest with KiROUND
This commit is contained in:
parent
226c96ae89
commit
ffa30d75a3
|
@ -99,9 +99,4 @@ int rescale( int aNumerator, int aValue, int aDenominator );
|
||||||
template <>
|
template <>
|
||||||
int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator );
|
int64_t rescale( int64_t aNumerator, int64_t aValue, int64_t aDenominator );
|
||||||
|
|
||||||
static inline int round_nearest( double v )
|
|
||||||
{
|
|
||||||
return int( v < 0 ? v - 0.5 : v + 0.5 );
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // UTIL_H
|
#endif // UTIL_H
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include <eda_rect.h>
|
#include <eda_rect.h>
|
||||||
#include <geometry/geometry_utils.h>
|
#include <geometry/geometry_utils.h>
|
||||||
#include <math/util.h> // for round_nearest
|
#include <math/util.h> // for KiROUND
|
||||||
|
|
||||||
// To approximate a circle by segments, a minimal seg count is mandatory
|
// To approximate a circle by segments, a minimal seg count is mandatory
|
||||||
#define MIN_SEGCOUNT_FOR_CIRCLE 6
|
#define MIN_SEGCOUNT_FOR_CIRCLE 6
|
||||||
|
@ -51,7 +51,7 @@ int GetArcToSegmentCount( int aRadius, int aErrorMax, double aArcAngleDegree )
|
||||||
// (360.0 degrees). For very small radius values, this is mandatory.
|
// (360.0 degrees). For very small radius values, this is mandatory.
|
||||||
arc_increment = std::min( 360.0/MIN_SEGCOUNT_FOR_CIRCLE, arc_increment );
|
arc_increment = std::min( 360.0/MIN_SEGCOUNT_FOR_CIRCLE, arc_increment );
|
||||||
|
|
||||||
int segCount = round_nearest( fabs( aArcAngleDegree ) / arc_increment );
|
int segCount = KiROUND( fabs( aArcAngleDegree ) / arc_increment );
|
||||||
|
|
||||||
// Ensure at least one segment is used (can happen for small arcs)
|
// Ensure at least one segment is used (can happen for small arcs)
|
||||||
return std::max( segCount, 1 );
|
return std::max( segCount, 1 );
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
#include <geometry/shape_line_chain.h>
|
#include <geometry/shape_line_chain.h>
|
||||||
#include <geometry/shape_poly_set.h>
|
#include <geometry/shape_poly_set.h>
|
||||||
#include <math/box2.h> // for BOX2I
|
#include <math/box2.h> // for BOX2I
|
||||||
#include <math/util.h> // for round_nearest, rescale
|
#include <math/util.h> // for KiROUND, rescale
|
||||||
#include <math/vector2d.h> // for VECTOR2I, VECTOR2D, VECTOR2
|
#include <math/vector2d.h> // for VECTOR2I, VECTOR2D, VECTOR2
|
||||||
#include <md5_hash.h>
|
#include <md5_hash.h>
|
||||||
|
|
||||||
|
@ -1723,13 +1723,13 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
|
||||||
if( 0.5 * lenb < distance )
|
if( 0.5 * lenb < distance )
|
||||||
distance = 0.5 * lenb;
|
distance = 0.5 * lenb;
|
||||||
|
|
||||||
int nx1 = round_nearest( distance * xa / lena );
|
int nx1 = KiROUND( distance * xa / lena );
|
||||||
int ny1 = round_nearest( distance * ya / lena );
|
int ny1 = KiROUND( distance * ya / lena );
|
||||||
|
|
||||||
newContour.Append( x1 + nx1, y1 + ny1 );
|
newContour.Append( x1 + nx1, y1 + ny1 );
|
||||||
|
|
||||||
int nx2 = round_nearest( distance * xb / lenb );
|
int nx2 = KiROUND( distance * xb / lenb );
|
||||||
int ny2 = round_nearest( distance * yb / lenb );
|
int ny2 = KiROUND( distance * yb / lenb );
|
||||||
|
|
||||||
newContour.Append( x1 + nx2, y1 + ny2 );
|
newContour.Append( x1 + nx2, y1 + ny2 );
|
||||||
}
|
}
|
||||||
|
@ -1789,11 +1789,11 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
|
||||||
double nx = xc + xs;
|
double nx = xc + xs;
|
||||||
double ny = yc + ys;
|
double ny = yc + ys;
|
||||||
|
|
||||||
newContour.Append( round_nearest( nx ), round_nearest( ny ) );
|
newContour.Append( KiROUND( nx ), KiROUND( ny ) );
|
||||||
|
|
||||||
// Store the previous added corner to make a sanity check
|
// Store the previous added corner to make a sanity check
|
||||||
int prevX = round_nearest( nx );
|
int prevX = KiROUND( nx );
|
||||||
int prevY = round_nearest( ny );
|
int prevY = KiROUND( ny );
|
||||||
|
|
||||||
for( int j = 0; j < segments; j++ )
|
for( int j = 0; j < segments; j++ )
|
||||||
{
|
{
|
||||||
|
@ -1801,11 +1801,11 @@ SHAPE_POLY_SET::POLYGON SHAPE_POLY_SET::chamferFilletPolygon( CORNER_MODE aMode,
|
||||||
ny = yc - sin( startAngle + ( j + 1 ) * deltaAngle ) * radius;
|
ny = yc - sin( startAngle + ( j + 1 ) * deltaAngle ) * radius;
|
||||||
|
|
||||||
// Sanity check: the rounding can produce repeated corners; do not add them.
|
// Sanity check: the rounding can produce repeated corners; do not add them.
|
||||||
if( round_nearest( nx ) != prevX || round_nearest( ny ) != prevY )
|
if( KiROUND( nx ) != prevX || KiROUND( ny ) != prevY )
|
||||||
{
|
{
|
||||||
newContour.Append( round_nearest( nx ), round_nearest( ny ) );
|
newContour.Append( KiROUND( nx ), KiROUND( ny ) );
|
||||||
prevX = round_nearest( nx );
|
prevX = KiROUND( nx );
|
||||||
prevY = round_nearest( ny );
|
prevY = KiROUND( ny );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue