diff options
author | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-02-08 22:27:24 -0500 |
---|---|---|
committer | Hamilton Kibbe <hamilton.kibbe@gmail.com> | 2015-02-08 22:27:24 -0500 |
commit | aea1f38597824085739aeed1fa6f33e264e23a4b (patch) | |
tree | e5b33f4f41fe0c045ae346cacc45ec49a50b03e2 /gerber | |
parent | a4c8a4cbcf8d60307b73d9a450c752ea376eeeb0 (diff) | |
download | gerbonara-aea1f38597824085739aeed1fa6f33e264e23a4b.tar.gz gerbonara-aea1f38597824085739aeed1fa6f33e264e23a4b.tar.bz2 gerbonara-aea1f38597824085739aeed1fa6f33e264e23a4b.zip |
Fix write_gerber_value bug
Diffstat (limited to 'gerber')
-rw-r--r-- | gerber/tests/test_utils.py | 3 | ||||
-rw-r--r-- | gerber/utils.py | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/gerber/tests/test_utils.py b/gerber/tests/test_utils.py index 1c3f1e5..fe9b2e6 100644 --- a/gerber/tests/test_utils.py +++ b/gerber/tests/test_utils.py @@ -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 diff --git a/gerber/utils.py b/gerber/utils.py index 86119ba..23575b3 100644 --- a/gerber/utils.py +++ b/gerber/utils.py @@ -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': |