summaryrefslogtreecommitdiff
path: root/gerber/utils.py
diff options
context:
space:
mode:
authorPaulo Henrique Silva <ph.silva@gmail.com>2015-04-07 18:22:02 -0300
committerPaulo Henrique Silva <ph.silva@gmail.com>2015-04-07 18:22:02 -0300
commitb93804ed9a3400099afceacfe5a809ae8bded2a4 (patch)
tree572889ae424748dbb8e0d015aa42b76ca6b20c69 /gerber/utils.py
parentb9b20a9644ca7b87493ca5786e2a25ecab132b75 (diff)
downloadgerbonara-b93804ed9a3400099afceacfe5a809ae8bded2a4.tar.gz
gerbonara-b93804ed9a3400099afceacfe5a809ae8bded2a4.tar.bz2
gerbonara-b93804ed9a3400099afceacfe5a809ae8bded2a4.zip
Add unspecified FS D leading zeros format
FS D leading zero format (probably form Direct) is an unspecified coordinate format where all numbers are specified with both leading and trailing zeros.
Diffstat (limited to 'gerber/utils.py')
-rw-r--r--gerber/utils.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/gerber/utils.py b/gerber/utils.py
index 1c43550..df26516 100644
--- a/gerber/utils.py
+++ b/gerber/utils.py
@@ -54,7 +54,7 @@ def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
(number of integer-part digits, number of decimal-part digits)
zero_suppression : string
- Zero-suppression mode. May be 'leading' or 'trailing'
+ Zero-suppression mode. May be 'leading', 'trailing' or 'none'
Returns
-------
@@ -82,11 +82,14 @@ def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
if negative:
value = value.lstrip('-')
+ missing_digits = MAX_DIGITS - len(value)
- digits = list('0' * MAX_DIGITS)
- offset = 0 if zero_suppression == 'trailing' else (MAX_DIGITS - len(value))
- for i, digit in enumerate(value):
- digits[i + offset] = digit
+ if zero_suppression == 'trailing':
+ digits = list(value + ('0' * missing_digits))
+ elif zero_suppression == 'leading':
+ digits = list(('0' * missing_digits) + value)
+ else:
+ digits = list(value)
result = float(''.join(digits[:integer_digits] + ['.'] + digits[integer_digits:]))
return -result if negative else result
@@ -114,7 +117,7 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
(number of integer-part digits, number of decimal-part digits)
zero_suppression : string
- Zero-suppression mode. May be 'leading' or 'trailing'
+ Zero-suppression mode. May be 'leading', 'trailing' or 'none'
Returns
-------
@@ -150,7 +153,7 @@ def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
if zero_suppression == 'trailing':
while digits and digits[-1] == '0':
digits.pop()
- else:
+ elif zero_suppression == 'leading':
while digits and digits[0] == '0':
digits.pop(0)