1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-14 02:34:12 +02:00
This commit is contained in:
Justin Lin
2022-05-07 16:41:00 +08:00
parent 871bee3d50
commit 916f833107

View File

@@ -32,27 +32,29 @@ 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 angle_between(pts[i] - pts[i + 1], pts[i + 1] - pts[i + 2]) > angle_threshold ? let(pi = pts[i], pi1 = pts[i + 1], pi2 = pts[i + 2])
_bezier_corner(round_d, t_step, pts[i], pts[i + 1], pts[i + 2]) : each angle_between(pi - pi1, pi1 - pi2) > angle_threshold ?
[pts[i + 1]] _bezier_corner(round_d, t_step, pi, pi1, pi2) : [pi1]
]; ];
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),
first = pts[0],
middle_pts = _bezier_smooth_corners(pts, round_d, t_step, leng, angle_threshold), middle_pts = _bezier_smooth_corners(pts, round_d, t_step, leng, angle_threshold),
last = pts[leng - 1],
pth_pts = closed ? pth_pts = closed ?
concat( concat(
_bezier_smooth_corners( _bezier_smooth_corners(
[pts[leng - 1], pts[0], pts[1]], [last, first, pts[1]],
round_d, t_step, 3, angle_threshold round_d, t_step, 3, angle_threshold
), ),
middle_pts, middle_pts,
_bezier_smooth_corners( _bezier_smooth_corners(
[pts[leng - 2], pts[leng - 1], pts[0]], [pts[leng - 2], last, first],
round_d, t_step, 3, angle_threshold round_d, t_step, 3, angle_threshold
) )
) : [pts[0], each middle_pts, pts[leng - 1]] ) : [first, each middle_pts, last]
) )
len(path_pts[0]) == 2 ? [for(p = pth_pts) __to2d(p)] : pth_pts; len(path_pts[0]) == 2 ? [for(p = pth_pts) __to2d(p)] : pth_pts;