← Back to team overview

kicad-developers team mailing list archive

Re: Guidelines for KiROUND-ing

 

On 04/29/2013 07:08 PM, Lorenzo Marcantonio wrote:
Looking around for angles I noticed a thing... especially when computing
distance (like using hypot or a whole sqrt expression), sometimes the
result is KiROUND-ed while often a simple (int) truncation is done.

Simple example (from the plotting routines, where rounding *would* matter
for gerbers):

     start.x = centre.x + (int) ( radius * cos( -alpha ) );
     start.y = centre.y + (int) ( radius * sin( -alpha ) );

IMHO these should be KiROUNDed, instead of casted. The same appears
often when computing, for example, a circle radius; since we have good
geometric functions we could go from (this is from the autorouter):

     radius = (int) sqrt( (double) ( cx - ux0 ) * ( cx - ux0 )
                        + (double) ( cy - uy0 ) * ( cy - uy0 ) );

to

     radius = KiROUND( Distance( ux0, uy0, cx, cy ) );

which I hope everyone agree is better (if only for the expression itself).

Are there situations where some geometrical variable should *not* be rounded
and instead just cast to int?
Hi Lorenzo,

My 0.001 cent - It's much simpler: just don't use floating point.

Tom


Follow ups

References