Mailing list archives : pcb-rnd

ID:88
From:ge...@igor2.repo.hu
Date:Fri, 23 Sep 2016 11:26:44 +0200 (CEST)
Subject:[pcb-rnd] pcb-printf, %mH, human-readable scaling
Hi all,
 
we had a discussion recently on human readable coordinate prints. I got to 
the point where this is needed again, for the lihata board format this 
time. I commited an implementation today. It's not in use yet, but it's 
already testable:
 
1. svn up
2. make
3. cd tests/pcb-printf
4. make
5. ./prcli "%.08mH" "0.254mm"
 
The heuristics is pertty simple:
 
- it converts the value to mm first; if it's out of the "convenient range" 
of 0.001 .. 1000 mm, it changes to um or m (metric value)
 
- it then converts the value to mil; if it's bigger than 1000 mil, it 
converts to inch (imperial value)
 
- it counts how many non-zero decimal digits the value the metric and the 
imperial value has and picks the one that has less (i.e. the more round)
 
- if they look the same, it prefers metric - it is because the internal 
base unit (nanometer) can be converted to metric forth and back without 
loss (in theory)
 
Please test it and find corner cases where it is not doing what you expect 
it to do.
 
Examples:
 
0.254mm -> 10.0 mil
0.251mm -> 0.251 mm
1.12mil -> 1.12 mil
1.3in -> 1.3 in
0.3in -> 300 mil
1.2m -> 1.2 m
0.1m -> 100 mm
0.0005mm -> 0.5 um
0.01mil -> 0.01 mil
0.001mil -> 0.025 um (um and mil roundness match, metric preference)
 
Unintetnional/buggy:
 
1.123mil -> 0.028524 mm - it is because the inherited code uses doubles 
carelessly and there are rounding errors making the actual value 1.1229999 
on the input conversion which is then not rounder in mil than in mm and 
the mm preference triggers
 
0.43m -> 429.99999 mm - a similar rounding error; to check that it goes 
wrong on the input, print it in the internal units using "%mI"
 
I think these would be addressed only when we get rid of floats in a later 
development cycle.
 
Regards,
 
Igor2
 
 
 
 

Reply subtree:
88 [pcb-rnd] pcb-printf, %mH, human-readable scaling from ge...@igor2.repo.hu