← Back to team overview

kicad-developers team mailing list archive

Re: Guidelines for KiROUND-ing

 

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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. [...] Are there situations where some
> geometrical variable should *not* be rounded and instead just cast
> to int? The standard defines 'truncation' as the behaviour
> (http://en.cppreference.com/w/cpp/language/implicit_cast), so it 
> could be useful to have a 'rounding toward zero' behaviour; however
> I'd use an explicit call to trunc if that was an important and
> wanted behaviour (just like I often see and esplicit cast to double
> when an int is passed as a double argument... I presume that's for
> highlighting the conversion).

It might be in DRC situations - if you want 12mil clearance and
calculate a distance of 11.6mil, the rounding will tell you you're
fine, the truncation will show you are too close. I agree with you
though in that there should be an explicit call to a truncation
function (or macro or whatever) for code readability's sake.

Hope you get what I mean,
Heiko

- -- 
Mein PGP-Key zur Verifizierung: http://pgp.mit.edu

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlF+s7oACgkQ/Vb5NagElAX+gACgm2DjqVB847wvNyDS1xjBNeBV
BUsAni6keC9BVES378K1jlmLhuwpDwfh
=KCbB
-----END PGP SIGNATURE-----


Follow ups

References