mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-05 06:17:32 +02:00
refactor: clean code
This commit is contained in:
@@ -2,22 +2,6 @@ use <../__comm__/__fast_fibonacci.scad>;
|
|||||||
use <../ptf/ptf_rotate.scad>;
|
use <../ptf/ptf_rotate.scad>;
|
||||||
use <../shape_circle.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) =
|
function _remove_same_pts(pts1, pts2) =
|
||||||
concat(
|
concat(
|
||||||
pts1,
|
pts1,
|
||||||
@@ -28,28 +12,28 @@ function _golden_spiral_from_ls_or_eql_to(from, to, point_distance, rt_dir) =
|
|||||||
let(
|
let(
|
||||||
f1 = __fast_fibonacci(from),
|
f1 = __fast_fibonacci(from),
|
||||||
f2 = __fast_fibonacci(from + 1),
|
f2 = __fast_fibonacci(from + 1),
|
||||||
fn = floor(f1 * 6.28312 / point_distance),
|
fn = floor(f1 * PI * 2 / point_distance),
|
||||||
$fn = fn + 4 - (fn % 4),
|
$fn = fn + 4 - (fn % 4),
|
||||||
circle_pts = shape_circle(radius = f1, n = $fn / 4 + 1),
|
circle_pts = shape_circle(radius = f1, n = $fn / 4 + 1),
|
||||||
len_pts = len(circle_pts),
|
len_pts = len(circle_pts),
|
||||||
a_step = 360 / $fn * rt_dir,
|
a_step = 360 / $fn * rt_dir,
|
||||||
range_i = [0:len_pts - 1],
|
range_i = [0:len_pts - 1],
|
||||||
arc_points_angles = (rt_dir == 1 ? [
|
arc_points_angles = (
|
||||||
for(i = range_i)
|
rt_dir == 1 ?
|
||||||
[circle_pts[i], a_step * i]
|
[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]]
|
||||||
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],
|
||||||
offset = f2 - f1
|
za = 90 * rt_dir,
|
||||||
|
ra = [0, 0, za]
|
||||||
) _remove_same_pts(
|
) _remove_same_pts(
|
||||||
arc_points_angles,
|
arc_points_angles,
|
||||||
[
|
[
|
||||||
for(pt_a = _golden_spiral(from + 1, to, point_distance, rt_dir))
|
for(pt_a = _golden_spiral(from + 1, to, point_distance, rt_dir))
|
||||||
[
|
[
|
||||||
ptf_rotate(pt_a[0], [0, 0, 90 * rt_dir]) +
|
ptf_rotate(pt_a[0], ra) + off_p,
|
||||||
(rt_dir == 1 ? [0, -offset, 0] : [-offset, 0, 0]),
|
pt_a[1] + za
|
||||||
pt_a[1] + 90 * rt_dir
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user