From aea1f38597824085739aeed1fa6f33e264e23a4b Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sun, 8 Feb 2015 22:27:24 -0500 Subject: Fix write_gerber_value bug --- gerber/tests/test_utils.py | 3 +++ gerber/utils.py | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'gerber') 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': -- cgit