From a49b27ecb1f76ecd7ca0265a0364d0da356d4625 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sun, 26 Jan 2020 20:28:44 +0800 Subject: [PATCH] use scad --- src/pixel/_impl/_px_cylinder_impl.scad | 50 ++++++++++++++++++++++++++ src/pixel/px_cylinder.scad | 49 ++----------------------- test/pixel/test_px_cylinder.scad | 4 +-- 3 files changed, 54 insertions(+), 49 deletions(-) create mode 100644 src/pixel/_impl/_px_cylinder_impl.scad diff --git a/src/pixel/_impl/_px_cylinder_impl.scad b/src/pixel/_impl/_px_cylinder_impl.scad new file mode 100644 index 00000000..a7639bd4 --- /dev/null +++ b/src/pixel/_impl/_px_cylinder_impl.scad @@ -0,0 +1,50 @@ + +function _px_cylinder_px_circle(radius, filled, thickness) = + let(range = [-radius: radius - 1]) + filled ? [ + for(y = range) + for(x = range) + let(v = [x, y]) + if(norm(v) < radius) v + ] : + let(ishell = radius * radius - 2 * thickness * radius) + [ + for(y = range) + for(x = range) + let( + v = [x, y], + leng = norm(v) + ) + if(leng < radius && (leng * leng) > ishell) v + ]; + +function _px_cylinder_diff_r(r, h, filled, thickness) = + let( + r1 = r[0], + r2 = r[1] + ) + r1 == r2 ? _px_cylinder_same_r(r1, h, filled, thickness) : + let(dr = (r2 - r1) / (h - 1)) + [ + for(i = 0; i < h; i = i + 1) + let(r = round(r1 + dr * i)) + each [ + for(pt = _px_cylinder_px_circle(r, filled, thickness)) + [pt[0], pt[1], i] + ] + ]; + +function _px_cylinder_same_r(r, h, filled, thickness) = + let(c = _px_cylinder_px_circle(r, filled, thickness)) + [ + for(i = 0; i < h; i = i + 1) + each [ + for(pt = c) + [pt[0], pt[1], i] + ] + ]; + +function _px_cylinder_impl(r, h, filled, thickness) = + is_num(r) ? + _px_cylinder_same_r(r, h, filled, thickness) : + _px_cylinder_diff_r(r, h, filled, thickness); \ No newline at end of file diff --git a/src/pixel/px_cylinder.scad b/src/pixel/px_cylinder.scad index 7f7309fd..37335a88 100644 --- a/src/pixel/px_cylinder.scad +++ b/src/pixel/px_cylinder.scad @@ -8,52 +8,7 @@ * **/ -function _px_cylinder_px_circle(radius, filled, thickness) = - let(range = [-radius: radius - 1]) - filled ? [ - for(y = range) - for(x = range) - let(v = [x, y]) - if(norm(v) < radius) v - ] : - let(ishell = radius * radius - 2 * thickness * radius) - [ - for(y = range) - for(x = range) - let( - v = [x, y], - leng = norm(v) - ) - if(leng < radius && (leng * leng) > ishell) v - ]; - -function _px_cylinder_diff_r(r, h, filled, thickness) = - let( - r1 = r[0], - r2 = r[1] - ) - r1 == r2 ? _px_cylinder_same_r(r1, h, filled, thickness) : - let(dr = (r2 - r1) / (h - 1)) - [ - for(i = 0; i < h; i = i + 1) - let(r = round(r1 + dr * i)) - each [ - for(pt = _px_cylinder_px_circle(r, filled, thickness)) - [pt[0], pt[1], i] - ] - ]; - -function _px_cylinder_same_r(r, h, filled, thickness) = - let(c = _px_cylinder_px_circle(r, filled, thickness)) - [ - for(i = 0; i < h; i = i + 1) - each [ - for(pt = c) - [pt[0], pt[1], i] - ] - ]; +use ; function px_cylinder(r, h, filled = false, thickness = 1) = - is_num(r) ? - _px_cylinder_same_r(r, h, filled, thickness) : - _px_cylinder_diff_r(r, h, filled, thickness); \ No newline at end of file + _px_cylinder_impl(r, h, filled, thickness); \ No newline at end of file diff --git a/test/pixel/test_px_cylinder.scad b/test/pixel/test_px_cylinder.scad index 8e0b00b1..1fc514eb 100644 --- a/test/pixel/test_px_cylinder.scad +++ b/test/pixel/test_px_cylinder.scad @@ -1,5 +1,5 @@ -include ; -include ; +use ; +use ; module test_px_cylinder() { echo("==== test_px_cylinder ====");