David Boddie avatar David Boddie committed 3b43b09

Ensured that coordinates never exceed the maximum stitch length when
truncated to integers.

Comments (0)

Files changed (1)

 
 if __name__ == "__main__":
 
-    if not 2 <= len(sys.argv) <= 3:
-        sys.stderr.write("Usage: %s <SVG file> <JEF file>\n" % sys.argv[0])
+    if not 2 <= len(sys.argv) <= 4:
+        sys.stderr.write("Usage: %s [maximum stitch length (JEF units)] <SVG file> <JEF file>\n" % sys.argv[0])
         sys.exit(1)
     
-    svg_file = sys.argv[1]
-    jef_file = sys.argv[2]
+    elif len(sys.argv) == 4:
+        max_stitch_length = min(127.0, max(1.0, float(sys.argv[1])))
+        svg_file = sys.argv[2]
+        jef_file = sys.argv[3]
+    
+    else:
+        max_stitch_length = 127.0
+        svg_file = sys.argv[1]
+        jef_file = sys.argv[2]
     
     app = QCoreApplication(sys.argv)
     
         while i < len(coordinates):
         
             command, x, y = coordinates[i]
-            x += dx
-            y += dy
+            x = int(x + dx)
+            y = int(y + dy)
             
             # If one or both dimensions are greater than the maximum stitch
             # length then split the line into pieces.
             d = max(abs(x - cx), abs(y - cy))
-            n = (d / 127.0)
+            n = (d / max_stitch_length)
             
             if n > 1:
             
-                xs = float(x - cx)/n
-                ys = float(y - cy)/n
+                xs = max(-max_stitch_length, min(float(x - cx)/n, max_stitch_length))
+                ys = max(-max_stitch_length, min(float(y - cy)/n, max_stitch_length))
                 
                 # Insert moves/stitches at intermediate positions.
                 j = 1
                 cx, cy = px, py
             
             # Update the original coordinate.
-            coordinates[i] = (command, int(x), int(y))
+            coordinates[i] = (command, x, y)
             cx, cy = x, y
             i += 1
     
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.