From ce0bbc5b6e99af43978479571edcc19b28952d96 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 27 Jan 2020 16:09:05 +0800 Subject: [PATCH] refactor deps --- src/_impl/_shape_glued2circles_impl.scad | 66 ++++++++++++++++++++++++ src/shape_glued2circles.scad | 62 +--------------------- test/test_shape_glued2circles.scad | 3 -- 3 files changed, 68 insertions(+), 63 deletions(-) create mode 100644 src/_impl/_shape_glued2circles_impl.scad diff --git a/src/_impl/_shape_glued2circles_impl.scad b/src/_impl/_shape_glued2circles_impl.scad new file mode 100644 index 00000000..d6fcbf99 --- /dev/null +++ b/src/_impl/_shape_glued2circles_impl.scad @@ -0,0 +1,66 @@ +use ; +use ; +use ; + +function _glued2circles_pie_curve(radius, centre_dist, tangent_angle) = + let( + begin_ang = 90 + tangent_angle, + shape_pts = shape_pie(radius, [-begin_ang, begin_ang]), + leng = len(shape_pts) + ) + [ + for(i = 1; i < leng; i = i + 1) + shape_pts[i] + [centre_dist / 2, 0] + ]; + +function _glued2circles_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) = + let( + ctrl_p = rotate_p([radius * tan(tangent_angle), -radius], tangent_angle), + ctrl_p2 = [-ctrl_p[0], ctrl_p[1]] + [centre_dist / 2, 0], + ctrl_p3 = [-ctrl_p2[0], ctrl_p2[1]], + ctrl_p4 = [-ctrl_p1[0], ctrl_p1[1]] + ) + bezier_curve( + t_step, + [ + ctrl_p1, + ctrl_p2, + ctrl_p3, + ctrl_p4 + ] + ); + +function _glued2circles_lower_half_curve(curve_pts, leng) = + [ + for(i = 0; i < leng; i = i + 1) + let(p = curve_pts[leng - 1 - i]) + if(p[0] >= 0) p + ]; + +function _glued2circles_half_glued_circle(radius, centre_dist, tangent_angle, t_step) = + let( + pie_curve_pts = _glued2circles_pie_curve(radius, centre_dist, tangent_angle), + curve_pts = _glued2circles_bezier(radius, centre_dist, tangent_angle, t_step, pie_curve_pts[0]), + lower_curve_pts = _glued2circles_lower_half_curve(curve_pts, len(curve_pts)), + leng_half_curve_pts = len(lower_curve_pts), + upper_curve_pts = [ + for(i = 0; i < leng_half_curve_pts; i = i + 1) + let(pt = lower_curve_pts[leng_half_curve_pts - 1 - i]) + [pt[0], -pt[1]] + ] + ) concat( + lower_curve_pts, + pie_curve_pts, + upper_curve_pts + ); + +function _shape_glued2circles_impl(radius, centre_dist, tangent_angle, t_step) = + let( + half_glued_circles = _glued2circles_half_glued_circle(radius, centre_dist, tangent_angle, t_step), + leng_half_glued_circles = len(half_glued_circles), + left_half_glued_circles = [ + for(i = 0; i < leng_half_glued_circles; i = i + 1) + let(pt = half_glued_circles[leng_half_glued_circles - 1 - i]) + [-pt[0], pt[1]] + ] + ) concat(half_glued_circles, left_half_glued_circles); \ No newline at end of file diff --git a/src/shape_glued2circles.scad b/src/shape_glued2circles.scad index 28446aa0..214a8bf3 100644 --- a/src/shape_glued2circles.scad +++ b/src/shape_glued2circles.scad @@ -9,65 +9,7 @@ * **/ -function _glued2circles_pie_curve(radius, centre_dist, tangent_angle) = - let( - begin_ang = 90 + tangent_angle, - shape_pts = shape_pie(radius, [-begin_ang, begin_ang]), - leng = len(shape_pts) - ) - [ - for(i = 1; i < leng; i = i + 1) - shape_pts[i] + [centre_dist / 2, 0] - ]; - -function _glued2circles_bezier(radius, centre_dist, tangent_angle, t_step, ctrl_p1) = - let( - ctrl_p = rotate_p([radius * tan(tangent_angle), -radius], tangent_angle), - ctrl_p2 = [-ctrl_p[0], ctrl_p[1]] + [centre_dist / 2, 0], - ctrl_p3 = [-ctrl_p2[0], ctrl_p2[1]], - ctrl_p4 = [-ctrl_p1[0], ctrl_p1[1]] - ) - bezier_curve( - t_step, - [ - ctrl_p1, - ctrl_p2, - ctrl_p3, - ctrl_p4 - ] - ); - -function _glued2circles_lower_half_curve(curve_pts, leng) = - [ - for(i = 0; i < leng; i = i + 1) - let(p = curve_pts[leng - 1 - i]) - if(p[0] >= 0) p - ]; - -function _glued2circles_half_glued_circle(radius, centre_dist, tangent_angle, t_step) = - let( - pie_curve_pts = _glued2circles_pie_curve(radius, centre_dist, tangent_angle), - curve_pts = _glued2circles_bezier(radius, centre_dist, tangent_angle, t_step, pie_curve_pts[0]), - lower_curve_pts = _glued2circles_lower_half_curve(curve_pts, len(curve_pts)), - leng_half_curve_pts = len(lower_curve_pts), - upper_curve_pts = [ - for(i = 0; i < leng_half_curve_pts; i = i + 1) - let(pt = lower_curve_pts[leng_half_curve_pts - 1 - i]) - [pt[0], -pt[1]] - ] - ) concat( - lower_curve_pts, - pie_curve_pts, - upper_curve_pts - ); +use <_impl/_shape_glued2circles_impl.scad>; function shape_glued2circles(radius, centre_dist, tangent_angle = 30, t_step = 0.1) = - let( - half_glued_circles = _glued2circles_half_glued_circle(radius, centre_dist, tangent_angle, t_step), - leng_half_glued_circles = len(half_glued_circles), - left_half_glued_circles = [ - for(i = 0; i < leng_half_glued_circles; i = i + 1) - let(pt = half_glued_circles[leng_half_glued_circles - 1 - i]) - [-pt[0], pt[1]] - ] - ) concat(half_glued_circles, left_half_glued_circles); \ No newline at end of file + _shape_glued2circles_impl(radius, centre_dist, tangent_angle, t_step); \ No newline at end of file diff --git a/test/test_shape_glued2circles.scad b/test/test_shape_glued2circles.scad index 6707695d..27551f70 100644 --- a/test/test_shape_glued2circles.scad +++ b/test/test_shape_glued2circles.scad @@ -1,7 +1,4 @@ include ; -include ; -include ; -include ; include ; module test_shape_glued2circles() {