From 541cdf66a59f2724ae5ed1794a038a51032dbb47 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Thu, 25 May 2017 09:45:43 +0800 Subject: [PATCH] refactored --- src/__private__/__shape_pie.scad | 20 ++++++++++++++++++++ src/shape_pie.scad | 21 ++------------------- 2 files changed, 22 insertions(+), 19 deletions(-) create mode 100644 src/__private__/__shape_pie.scad diff --git a/src/__private__/__shape_pie.scad b/src/__private__/__shape_pie.scad new file mode 100644 index 00000000..8d09cf8d --- /dev/null +++ b/src/__private__/__shape_pie.scad @@ -0,0 +1,20 @@ +function __shape_pie(radius, angle) = + let( + frags = __frags(radius), + a_step = 360 / frags, + leng = radius * cos(a_step / 2), + angles = __is_vector(angle) ? angle : [0:angle], + m = floor(angles[0] / a_step) + 1, + n = floor(angles[1] / a_step), + edge_r_begin = leng / cos((m - 0.5) * a_step - angles[0]), + edge_r_end = leng / cos((n + 0.5) * a_step - angles[1]), + shape_pts = concat( + [[0, 0], __ra_to_xy(edge_r_begin, angles[0])], + m > n ? [] : [ + for(i = [m:n]) + let(a = a_step * i) + __ra_to_xy(radius, a) + ], + angles[1] == a_step * n ? [] : [__ra_to_xy(edge_r_end, angles[1])] + ) + ) shape_pts; \ No newline at end of file diff --git a/src/shape_pie.scad b/src/shape_pie.scad index fa393837..44f69992 100644 --- a/src/shape_pie.scad +++ b/src/shape_pie.scad @@ -15,24 +15,7 @@ include <__private__/__frags.scad>; include <__private__/__is_vector.scad>; include <__private__/__ra_to_xy.scad>; +include <__private__/__shape_pie.scad>; function shape_pie(radius, angle) = - let( - frags = __frags(radius), - a_step = 360 / frags, - leng = radius * cos(a_step / 2), - angles = __is_vector(angle) ? angle : [0:angle], - m = floor(angles[0] / a_step) + 1, - n = floor(angles[1] / a_step), - edge_r_begin = leng / cos((m - 0.5) * a_step - angles[0]), - edge_r_end = leng / cos((n + 0.5) * a_step - angles[1]), - shape_pts = concat( - [[0, 0], __ra_to_xy(edge_r_begin, angles[0])], - m > n ? [] : [ - for(i = [m:n]) - let(a = a_step * i) - __ra_to_xy(radius, a) - ], - angles[1] == a_step * n ? [] : [__ra_to_xy(edge_r_end, angles[1])] - ) - ) shape_pts; \ No newline at end of file + __shape_pie(radius, angle); \ No newline at end of file