From 327c15865b52c5fc91f04d00c53a442afb53b409 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 2 May 2022 16:39:35 +0800 Subject: [PATCH] refactor --- src/voxel/_impl/_vx_cylinder_impl.scad | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/voxel/_impl/_vx_cylinder_impl.scad b/src/voxel/_impl/_vx_cylinder_impl.scad index 80e38167..22e0993d 100644 --- a/src/voxel/_impl/_vx_cylinder_impl.scad +++ b/src/voxel/_impl/_vx_cylinder_impl.scad @@ -1,18 +1,18 @@ function _vx_cylinder_vx_circle(radius, filled, thickness) = - let(range = [-radius: radius - 1]) + let(range = [-radius: radius - 1], powr = radius ^ 2) filled ? [ for(y = range, x = range) let(v = [x, y]) - if(norm(v) < radius) v + if(v * v < powr) v ] : - let(ishell = radius ^ 2 - 2 * thickness * radius) + let(ishell = powr - 2 * thickness * radius) [ for(y = range, x = range) let( v = [x, y], - leng = norm(v) + pow_leng = v * v ) - if(leng < radius && (leng ^ 2) > ishell) v + if(pow_leng < powr && pow_leng > ishell) v ]; function _vx_cylinder_diff_r(r, h, filled, thickness) = @@ -25,19 +25,15 @@ function _vx_cylinder_diff_r(r, h, filled, thickness) = [ for(i = 0; i < h; i = i + 1) let(r = round(r1 + dr * i)) - each [ for(pt = _vx_cylinder_vx_circle(r, filled, thickness)) [each pt, i] - ] ]; function _vx_cylinder_same_r(r, h, filled, thickness) = let(c = _vx_cylinder_vx_circle(r, filled, thickness)) [ for(i = 0; i < h; i = i + 1) - each [ for(pt = c) [each pt, i] - ] ]; function _vx_cylinder_impl(r, h, filled, thickness) =