Fix write_gerber_value bug
This commit is contained in:
parent
a4c8a4cbcf
commit
aea1f38597
2 changed files with 8 additions and 0 deletions
|
|
@ -37,6 +37,9 @@ def test_zero_suppression():
|
|||
assert_equal(value, parse_gerber_value(string, fmt, zero_suppression))
|
||||
assert_equal(string, write_gerber_value(value, fmt, zero_suppression))
|
||||
|
||||
assert_equal(write_gerber_value(0.000000001, fmt, 'leading'), '0')
|
||||
assert_equal(write_gerber_value(0.000000001, fmt, 'trailing'), '0')
|
||||
|
||||
|
||||
def test_format():
|
||||
""" Test gerber value parser and writer handle format correctly
|
||||
|
|
|
|||
|
|
@ -138,6 +138,11 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
|
|||
fmtstring = '%%0%d.0%df' % (MAX_DIGITS + 1, decimal_digits)
|
||||
digits = [val for val in fmtstring % value if val != '.']
|
||||
|
||||
# If all the digits are 0, return '0'.
|
||||
digit_sum = reduce(lambda x,y:x+int(y), digits, 0)
|
||||
if digit_sum == 0:
|
||||
return '0'
|
||||
|
||||
# Suppression...
|
||||
if zero_suppression == 'trailing':
|
||||
while digits and digits[-1] == '0':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue