1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-09 00:06:42 +02:00
This commit is contained in:
Justin Lin
2022-05-05 08:12:32 +08:00
parent 2f274c299b
commit 7bdb470285

View File

@@ -28,29 +28,28 @@ function _corner_ctrl_pts(round_d, p1, p2, p3) =
function _bezier_corner(round_d, t_step, p1, p2, p3) = function _bezier_corner(round_d, t_step, p1, p2, p3) =
bezier_curve(t_step, _corner_ctrl_pts(round_d, p1, p2, p3)); bezier_curve(t_step, _corner_ctrl_pts(round_d, p1, p2, p3));
function _recursive_bezier_smooth(pts, round_d, t_step, leng, angle_threshold) = function _bezier_smooth_corners(pts, round_d, t_step, leng, angle_threshold) =
let(end_i = leng - 2) let(end_i = leng - 2)
[ [
for(i = 0; i < end_i; i = i + 1) for(i = 0; i < end_i; i = i + 1)
each each angle_between(pts[i] - pts[i + 1], pts[i + 1] - pts[i + 2]) > angle_threshold ?
angle_between(pts[i] - pts[i + 1], pts[i + 1] - pts[i + 2]) > angle_threshold ? _bezier_corner(round_d, t_step, pts[i], pts[i + 1], pts[i + 2]) :
_bezier_corner(round_d, t_step, pts[i], pts[i + 1], pts[i + 2]) : [pts[i + 1]]
[pts[i + 1]]
]; ];
function _bezier_smooth_impl(path_pts, round_d, t_step, closed, angle_threshold) = function _bezier_smooth_impl(path_pts, round_d, t_step, closed, angle_threshold) =
let( let(
pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)], pts = len(path_pts[0]) == 3 ? path_pts : [for(p = path_pts) __to3d(p)],
leng = len(pts), leng = len(pts),
middle_pts = _recursive_bezier_smooth(pts, round_d, t_step, leng, angle_threshold), middle_pts = _bezier_smooth_corners(pts, round_d, t_step, leng, angle_threshold),
pth_pts = closed ? pth_pts = closed ?
concat( concat(
_recursive_bezier_smooth( _bezier_smooth_corners(
[pts[leng - 1], pts[0], pts[1]], [pts[leng - 1], pts[0], pts[1]],
round_d, t_step, 3, angle_threshold round_d, t_step, 3, angle_threshold
), ),
middle_pts, middle_pts,
_recursive_bezier_smooth( _bezier_smooth_corners(
[pts[leng - 2], pts[leng - 1], pts[0]], [pts[leng - 2], pts[leng - 1], pts[0]],
round_d, t_step, 3, angle_threshold round_d, t_step, 3, angle_threshold
) )