summaryrefslogtreecommitdiff
path: root/gerber/utils.py
diff options
context:
space:
mode:
authorHamilton Kibbe <hamilton.kibbe@gmail.com>2014-10-19 22:23:00 -0400
committerHamilton Kibbe <hamilton.kibbe@gmail.com>2014-10-19 22:23:00 -0400
commit18e3b87625ddb739faeddffcaed48e12db6c7e8b (patch)
tree8b27aa49e431d67e4940d053c2fd640854bd945a /gerber/utils.py
parent6d2db67e6d0973ce26ce3a6700ca44295f73fea7 (diff)
downloadgerbonara-18e3b87625ddb739faeddffcaed48e12db6c7e8b.tar.gz
gerbonara-18e3b87625ddb739faeddffcaed48e12db6c7e8b.tar.bz2
gerbonara-18e3b87625ddb739faeddffcaed48e12db6c7e8b.zip
Test update
Diffstat (limited to 'gerber/utils.py')
-rw-r--r--gerber/utils.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/gerber/utils.py b/gerber/utils.py
index fce6369..31ff196 100644
--- a/gerber/utils.py
+++ b/gerber/utils.py
@@ -44,6 +44,10 @@ def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
The specified value as a floating-point number.
"""
+ # Handle excellon edge case with explicit decimal. "That was easy!"
+ if '.' in value:
+ return float(value)
+
# Format precision
integer_digits, decimal_digits = format
MAX_DIGITS = integer_digits + decimal_digits
@@ -55,23 +59,20 @@ def parse_gerber_value(value, format=(2, 5), zero_suppression='trailing'):
raise ValueError('Parser only supports precision up to 6:7 format')
# Remove extraneous information
- value = value.strip()
- value = value.strip(' +')
+ #value = value.strip()
+ value = value.lstrip('+')
negative = '-' in value
if negative:
- value = value.strip(' -')
+ value = value.lstrip('-')
- # Handle excellon edge case with explicit decimal. "That was easy!"
- if '.' in value:
- return float(value)
- digits = [digit for digit in '0' * MAX_DIGITS]
+ 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
result = float(''.join(digits[:integer_digits] + ['.'] + digits[integer_digits:]))
- return -1.0 * result if negative else result
+ return -result if negative else result
def write_gerber_value(value, format=(2, 5), zero_suppression='trailing'):