mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Enable passing a region to stroke().
This commit is contained in:
parent
724e49385b
commit
83f61f5a6a
1 changed files with 188 additions and 182 deletions
34
drawing.scad
34
drawing.scad
|
@ -132,7 +132,7 @@
|
|||
// path = [for (i=[0:15:360]) [(i-180)/3,20*cos(2*i)]];
|
||||
// stroke(path, width=2, dots=true, color="lightgreen", dots_color="red", $fn=18);
|
||||
function stroke(
|
||||
path, width=1, closed=false,
|
||||
path, width=1, closed,
|
||||
endcaps, endcap1, endcap2, joints, dots,
|
||||
endcap_width, endcap_width1, endcap_width2, joint_width, dots_width,
|
||||
endcap_length, endcap_length1, endcap_length2, joint_length, dots_length,
|
||||
|
@ -143,7 +143,7 @@ function stroke(
|
|||
convexity=10, hull=true
|
||||
) = no_function("stroke");
|
||||
module stroke(
|
||||
path, width=1, closed=false,
|
||||
path, width=1, closed,
|
||||
endcaps, endcap1, endcap2, joints, dots,
|
||||
endcap_width, endcap_width1, endcap_width2, joint_width, dots_width,
|
||||
endcap_length, endcap_length1, endcap_length2, joint_length, dots_length,
|
||||
|
@ -200,16 +200,8 @@ module stroke(
|
|||
assert(false, str("Invalid endcap: ",cap))
|
||||
) * linewidth;
|
||||
|
||||
closed = default(closed, is_region(path));
|
||||
assert(is_bool(closed));
|
||||
assert(is_list(path));
|
||||
if (len(path) > 1) {
|
||||
assert(is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points.");
|
||||
}
|
||||
path = deduplicate( closed? close_path(path) : path );
|
||||
|
||||
assert(is_num(width) || (is_vector(width) && len(width)==len(path)));
|
||||
width = is_num(width)? [for (x=path) width] : width;
|
||||
assert(all([for (w=width) w>0]));
|
||||
|
||||
dots = dots==true? "dot" : dots;
|
||||
|
||||
|
@ -247,17 +239,30 @@ module stroke(
|
|||
|
||||
endcap_angle1 = first_defined([endcap_angle1, endcap_angle, dots_angle]);
|
||||
endcap_angle2 = first_defined([endcap_angle2, endcap_angle, dots_angle]);
|
||||
joint_angle = first_defined([joint_angle, dots_angle]);
|
||||
assert(is_undef(endcap_angle1)||is_num(endcap_angle1));
|
||||
assert(is_undef(endcap_angle2)||is_num(endcap_angle2));
|
||||
assert(is_undef(joint_angle)||is_num(joint_angle));
|
||||
|
||||
endcap_shape1 = _shape_path(endcap1, width[0], endcap_width1, endcap_length1, endcap_extent1);
|
||||
endcap_shape2 = _shape_path(endcap2, last(width), endcap_width2, endcap_length2, endcap_extent2);
|
||||
|
||||
endcap_color1 = first_defined([endcap_color1, endcap_color, dots_color, color]);
|
||||
endcap_color2 = first_defined([endcap_color2, endcap_color, dots_color, color]);
|
||||
joint_color = first_defined([joint_color, dots_color, color]);
|
||||
|
||||
paths = is_region(path)? path : [path];
|
||||
for (path = paths) {
|
||||
assert(is_list(path));
|
||||
if (len(path) > 1) {
|
||||
assert(is_path(path,[2,3]), "The path argument must be a list of 2D or 3D points, or a region.");
|
||||
}
|
||||
path = deduplicate( closed? close_path(path) : path );
|
||||
|
||||
assert(is_num(width) || (is_vector(width) && len(width)==len(path)));
|
||||
width = is_num(width)? [for (x=path) width] : width;
|
||||
assert(all([for (w=width) w>0]));
|
||||
|
||||
endcap_shape1 = _shape_path(endcap1, width[0], endcap_width1, endcap_length1, endcap_extent1);
|
||||
endcap_shape2 = _shape_path(endcap2, last(width), endcap_width2, endcap_length2, endcap_extent2);
|
||||
|
||||
trim1 = width[0] * first_defined([
|
||||
trim1, trim,
|
||||
(endcap1=="arrow")? endcap_length1-0.01 :
|
||||
|
@ -481,6 +486,7 @@ module stroke(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Function&Module: dashed_stroke()
|
||||
|
|
Loading…
Reference in a new issue