From 1428dc83076f565b6396d8350711afbc75c33c1a Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 8 May 2022 15:48:00 +0800 Subject: [PATCH] refactor --- src/turtle/_impl/_footprints2.scad | 9 --------- src/turtle/_impl/_footprints3.scad | 9 --------- src/turtle/footprints2.scad | 12 +++++++++--- src/turtle/footprints3.scad | 11 ++++++++--- 4 files changed, 17 insertions(+), 24 deletions(-) delete mode 100644 src/turtle/_impl/_footprints2.scad delete mode 100644 src/turtle/_impl/_footprints3.scad diff --git a/src/turtle/_impl/_footprints2.scad b/src/turtle/_impl/_footprints2.scad deleted file mode 100644 index eacdbdc1..00000000 --- a/src/turtle/_impl/_footprints2.scad +++ /dev/null @@ -1,9 +0,0 @@ -use <../turtle2d.scad>; - -function _footprints2(cmds, t, leng, i = 0) = - i == leng ? [] : - let( - nxt = turtle2d(cmds[i][0], t, cmds[i][1]), - pts = _footprints2(cmds, nxt, leng, i + 1) - ) - cmds[i][0] != "forward" ? pts : [turtle2d("pt", nxt), each pts]; \ No newline at end of file diff --git a/src/turtle/_impl/_footprints3.scad b/src/turtle/_impl/_footprints3.scad deleted file mode 100644 index e95e4cd5..00000000 --- a/src/turtle/_impl/_footprints3.scad +++ /dev/null @@ -1,9 +0,0 @@ -use <../turtle3d.scad>; - -function _footprints3(cmds, t, leng, i = 0) = - i == leng ? [] : - let( - nxt = turtle3d(cmds[i][0], t, cmds[i][1]), - pts = _footprints3(cmds, nxt, leng, i + 1) - ) - cmds[i][0] != "forward" ? pts : [turtle3d("pt", nxt), each pts]; diff --git a/src/turtle/footprints2.scad b/src/turtle/footprints2.scad index baa5e46f..101d5c28 100644 --- a/src/turtle/footprints2.scad +++ b/src/turtle/footprints2.scad @@ -1,3 +1,4 @@ + /** * footprints2.scad * @@ -8,9 +9,14 @@ * **/ -use <_impl/_footprints2.scad>; use ; function footprints2(cmds, start = [0, 0]) = - let(t = turtle2d("create", start.x, start.y, 0)) - [turtle2d("pt", t), each _footprints2(cmds, t, len(cmds))]; \ No newline at end of file + let(leng = len(cmds)) + [start, each [ + for(i = 0, t = turtle2d(cmds[i][0], turtle2d("create", start.x, start.y, 0), cmds[i][1]); + i < leng; + i = i + 1, + t = turtle2d(cmds[i][0], t, cmds[i][1])) + if(cmds[i][0] == "forward") turtle2d("pt", t) + ]]; \ No newline at end of file diff --git a/src/turtle/footprints3.scad b/src/turtle/footprints3.scad index fe91921b..32a358e5 100644 --- a/src/turtle/footprints3.scad +++ b/src/turtle/footprints3.scad @@ -8,9 +8,14 @@ * **/ -use <_impl/_footprints3.scad>; use ; function footprints3(cmds, start = [0, 0, 0]) = - let(t = turtle3d("create", start, [[1, 0, 0], [0, 1, 0], [0, 0, 1]])) - [turtle3d("pt", t), each _footprints3(cmds, t, len(cmds))]; \ No newline at end of file + let(leng = len(cmds)) + [start, each [ + for(i = 0, t = turtle3d(cmds[i][0], turtle3d("create", start, [[1, 0, 0], [0, 1, 0], [0, 0, 1]]), cmds[i][1]); + i < leng; + i = i + 1, + t = turtle3d(cmds[i][0], t, cmds[i][1])) + if(cmds[i][0] == "forward") turtle3d("pt", t) + ]];