Commit 45749e8b authored by Lars Kruse's avatar Lars Kruse

fix issue with scientific number formats in GCode

The "decimal" module can cause the output of values like "0E-12"
with the "%s" formatting string.

Test case:
   import decimal; print decimal.Decimal("0.0000001")
=> 1E-7

This fix uses a "%.?f" (? = number of digits) format string based
the number of significant digits as given via "minimum step width"
in GCode settings.
parent 46abd367
...@@ -61,7 +61,8 @@ def _get_num_converter(step_width): ...@@ -61,7 +61,8 @@ def _get_num_converter(step_width):
""" """
digits = _get_num_of_significant_digits(step_width) digits = _get_num_of_significant_digits(step_width)
format_string = "%%.%df" % digits format_string = "%%.%df" % digits
return lambda number: decimal.Decimal(format_string % number) conv_func = lambda number: decimal.Decimal(format_string % number)
return conv_func, format_string
class GCodeGenerator(object): class GCodeGenerator(object):
...@@ -99,8 +100,8 @@ class GCodeGenerator(object): ...@@ -99,8 +100,8 @@ class GCodeGenerator(object):
step_width = minimum_steps[i] step_width = minimum_steps[i]
else: else:
step_width = minimum_steps[-1] step_width = minimum_steps[-1]
conv = _get_num_converter(step_width) conv, format_string = _get_num_converter(step_width)
self._axes_formatter.append((conv(step_width), conv)) self._axes_formatter.append((conv(step_width), conv, format_string))
self._finished = False self._finished = False
if comment: if comment:
self.add_comment(comment) self.add_comment(comment)
...@@ -302,7 +303,7 @@ class GCodeGenerator(object): ...@@ -302,7 +303,7 @@ class GCodeGenerator(object):
continue continue
if not self.last_position or \ if not self.last_position or \
(new_pos[index] != self.last_position[index]): (new_pos[index] != self.last_position[index]):
pos_string.append("%s%s" % (axis_spec, new_pos[index])) pos_string.append(axis_spec + self._axes_formatter[index][2] % new_pos[index])
self.last_position[index] = new_pos[index] self.last_position[index] = new_pos[index]
if rapid == self.last_rapid: if rapid == self.last_rapid:
prefix = "" prefix = ""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment