summaryrefslogtreecommitdiff
path: root/gerber/utils.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2014-11-10 12:24:09 -0200
committerPaulo Henrique Silva <ph.silva@gmail.com>2014-11-10 12:24:09 -0200
commitab69ee0172353e64fbe5099a974341e88feaf24b (patch)
tree13dacd4fc7fceb664d86dae1457d4511ff928181 /gerber/utils.py
parentf5abd5b0bdc0b9f524456dc9216bd0f3732e82a0 (diff)
downloadgerbonara-ab69ee0172353e64fbe5099a974341e88feaf24b.tar.gz
gerbonara-ab69ee0172353e64fbe5099a974341e88feaf24b.tar.bz2
gerbonara-ab69ee0172353e64fbe5099a974341e88feaf24b.zip
Bunch of small fixes to improve Gerber read/write.
Diffstat (limited to 'gerber/utils.py')
-rw-r--r--gerber/utils.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/gerber/utils.py b/gerber/utils.py
index 7749e22..56b675f 100644
--- a/gerber/utils.py
+++ b/gerber/utils.py
@@ -125,9 +125,9 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
if MAX_DIGITS > 13 or integer_digits > 6 or decimal_digits > 7:
raise ValueError('Parser only supports precision up to 6:7 format')
- # Edge case...
+ # Edge case... (per Gerber spec we should return 0 in all cases, see page 77)
if value == 0:
- return '00'
+ return '0'
# negative sign affects padding, so deal with it at the end...
negative = value < 0.0
@@ -173,10 +173,14 @@ def decimal_string(value, precision=6, padding=False):
integer, decimal = floatstr.split('.')
elif ',' in floatstr:
integer, decimal = floatstr.split(',')
+ else:
+ integer, decimal = floatstr, "0"
+
if len(decimal) > precision:
decimal = decimal[:precision]
elif padding:
decimal = decimal + (precision - len(decimal)) * '0'
+
if integer or decimal:
return ''.join([integer, '.', decimal])
else: