From 42650a7a1933ce056b9f850a24b606d24799d764 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Tue, 3 Mar 2020 09:01:19 +0800 Subject: [PATCH] refactor --- src/function_grapher.scad | 92 ++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 41 deletions(-) diff --git a/src/function_grapher.scad b/src/function_grapher.scad index 7bd793fd..252336dd 100644 --- a/src/function_grapher.scad +++ b/src/function_grapher.scad @@ -162,52 +162,52 @@ module function_grapher(points, thickness, style = "FACES", slicing = "SLASH") { test_function_grapher_faces(pts, face_idxs); } - module tri_to_lines(tri1, tri2) { - polyline3d(concat(tri1, [tri1[0]]), thickness); + module tri_to_slash_lines(tri1, tri2) { + polyline3d(concat(tri1, [tri1[0]]), thickness); + if(tri2[0][0] == points[0][0][0]) { + polyline3d([tri2[0], tri2[2]], thickness); + } - if(slicing == "SLASH") { - if(tri2[0][0] == points[0][0][0]) { - polyline3d([tri2[0], tri2[2]], thickness); - } - - if(tri2[1][1] == points[rows - 1][0][1]) { - polyline3d([tri2[1], tri2[2]], thickness); - } - } - else { - if(tri2[1][0] == points[0][columns - 1][0]) { - polyline3d([tri2[1], tri2[2]], thickness); - } - - if(tri2[2][1] == points[rows - 1][columns - 1][1]) { - polyline3d([tri2[0], tri2[2]], thickness); - } - } + if(tri2[1][1] == points[rows - 1][0][1]) { + polyline3d([tri2[1], tri2[2]], thickness); + } } - module tri_to_hull_lines(tri1, tri2) { + module tri_to_backslash_lines(tri1, tri2) { + polyline3d(concat(tri1, [tri1[0]]), thickness); + if(tri2[1][0] == points[0][columns - 1][0]) { + polyline3d([tri2[1], tri2[2]], thickness); + } + + if(tri2[2][1] == points[rows - 1][columns - 1][1]) { + polyline3d([tri2[0], tri2[2]], thickness); + } + } + + module tri_to_slash_hull_lines(tri1, tri2) { hull_polyline3d(concat(tri1, [tri1[0]]), thickness); - if(slicing == "SLASH") { - if(tri2[0][0] == points[0][0][0]) { - hull_polyline3d([tri2[0], tri2[2]], thickness); - } + if(tri2[0][0] == points[0][0][0]) { + hull_polyline3d([tri2[0], tri2[2]], thickness); + } - if(tri2[1][1] == points[rows - 1][0][1]) { - hull_polyline3d([tri2[1], tri2[2]], thickness); - } - } - else { - if(tri2[1][0] == points[0][columns - 1][0]) { - hull_polyline3d([tri2[1], tri2[2]], thickness); - } + if(tri2[1][1] == points[rows - 1][0][1]) { + hull_polyline3d([tri2[1], tri2[2]], thickness); + } + } + + module tri_to_backslash_hull_lines(tri1, tri2) { + hull_polyline3d(concat(tri1, [tri1[0]]), thickness); + + if(tri2[1][0] == points[0][columns - 1][0]) { + hull_polyline3d([tri2[1], tri2[2]], thickness); + } + + if(tri2[2][1] == points[rows - 1][columns - 1][1]) { + hull_polyline3d([tri2[0], tri2[2]], thickness); + } + } - if(tri2[2][1] == points[rows - 1][columns - 1][1]) { - hull_polyline3d([tri2[0], tri2[2]], thickness); - } - } - } - module hull_pts(tri) { half_thickness = thickness / 2; hull() { @@ -224,11 +224,21 @@ module function_grapher(points, thickness, style = "FACES", slicing = "SLASH") { module tri_to_graph(tri1, tri2) { if(style == "LINES") { - tri_to_lines(tri1, tri2); + if(slicing == "SLASH") { + tri_to_slash_lines(tri1, tri2); + } + else { + tri_to_backslash_lines(tri1, tri2); + } } else if(style == "HULL_FACES") { // Warning: May be very slow!! tri_to_hull_faces(tri1, tri2); } else if(style == "HULL_LINES") { // Warning: very very slow!! - tri_to_hull_lines(tri1, tri2); + if(slicing == "SLASH") { + tri_to_slash_hull_lines(tri1, tri2); + } + else { + tri_to_backslash_hull_lines(tri1, tri2); + } } }