Improvements to loop removing

This commit is contained in:
alonso.torres 2021-04-23 11:29:07 +02:00 committed by Andrés Moya
parent 2184286a78
commit 1a7b098282
8 changed files with 96 additions and 73 deletions

View file

@ -65,22 +65,20 @@
(defn format-path [content]
(let [content (ups/close-subpaths content)]
(loop [result ""
last-move nil
(with-out-str
(loop [last-move nil
current (first content)
content (rest content)]
(if (some? current)
(when (some? current)
(let [point (upc/command->point current)
current-move? (= :move-to (:command current))
result (str result (command->string current))
result (if (and (not current-move?) (= last-move point))
(str result "Z")
result)
last-move (if current-move? point last-move)]
(recur result
last-move
(print (command->string current))
(when (and (not current-move?) (= last-move point))
(print "Z"))
(recur last-move
(first content)
(rest content)))
result))))
(rest content)))))))

View file

@ -103,9 +103,7 @@
(defn close-subpaths
"Searches a path for posible supaths that can create closed loops and merge them"
[content]
(let [subpaths (get-subpaths content)
closed-subpaths
(loop [result []
current (first subpaths)