1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-29 11:58:39 +01:00

refactor: clean code

This commit is contained in:
Justin Lin 2022-04-16 17:18:02 +08:00
parent 64515eec03
commit ada3588fb4

View File

@ -1,22 +1,6 @@
use <../__comm__/__fast_fibonacci.scad>;
use <../ptf/ptf_rotate.scad>;
use <../shape_circle.scad>;
function _fast_fibonacci_sub(nth) =
let(
_f = _fast_fibonacci_2_elems(floor(nth / 2)),
a = _f[0],
b = _f[1],
c = a * (b * 2 - a),
d = a ^ 2 + b ^ 2
)
nth % 2 == 0 ? [c, d] : [d, c + d];
function _fast_fibonacci_2_elems(nth) =
nth == 0 ? [0, 1] : _fast_fibonacci_sub(nth);
function _fast_fibonacci(nth) =
_fast_fibonacci_2_elems(nth)[0];
function _remove_same_pts(pts1, pts2) =
concat(
@ -28,29 +12,29 @@ function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) =
let(
f1 = __fast_fibonacci(from),
f2 = __fast_fibonacci(from + 1),
fn = floor(f1 * 6.28312 / point_distance),
fn = floor(f1 * PI * 2 / point_distance),
$fn = fn + 4 - (fn % 4),
circle_pts = shape_circle(radius = f1, n = $fn / 4 + 1),
len_pts = len(circle_pts),
a_step = 360 / $fn * rt_dir,
range_i = [0:len_pts - 1],
arc_points_angles = (rt_dir == 1 ? [
for(i = range_i)
[circle_pts[i], a_step * i]
] : [
for(i = range_i) let(idx = len_pts - i - 1)
[circle_pts[idx], a_step * i]
]),
offset = f2 - f1
arc_points_angles = (
rt_dir == 1 ?
[for(i = range_i) [circle_pts[i], a_step * i]] :
[for(i = range_i) let(idx = len_pts - i - 1) [circle_pts[idx], a_step * i]]
),
d_f2f1 = f2 - f1,
off_p = rt_dir == 1 ? [0, -d_f2f1, 0] : [-d_f2f1, 0, 0],
za = 90 * rt_dir,
ra = [0, 0, za]
) _remove_same_pts(
arc_points_angles,
[
for(pt_a = _golden_spiral(from + 1, to, point_distance, rt_dir))
[
ptf_rotate(pt_a[0], [0, 0, 90 * rt_dir]) +
(rt_dir == 1 ? [0, -offset, 0] : [-offset, 0, 0]),
pt_a[1] + 90 * rt_dir
]
[
ptf_rotate(pt_a[0], ra) + off_p,
pt_a[1] + za
]
]
);