Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Richard Milewski 2024-03-15 12:19:22 -07:00
commit d0330113fa
3 changed files with 103 additions and 44 deletions

View file

@ -1272,7 +1272,7 @@ function _turtle_command(command, parm, parm2, state, index) =
// Synopsis: Draws an annotated polygon.
// SynTags: Geom
// Topics: Shapes (2D)
// See Also: debug_vnf(), debug_bezier()
// See Also: debug_region(), debug_vnf(), debug_bezier()
//
// Usage:
// debug_polygon(points, paths, [vertices=], [edges=], [convexity=], [size=]);
@ -1302,19 +1302,32 @@ function _turtle_command(command, parm, parm2, state, index) =
module debug_polygon(points, paths, vertices=true, edges=true, convexity=2, size=1)
{
no_children($children);
print_paths=is_def(paths);
echo(points=points);
if (print_paths)
echo(paths=paths);
paths = is_undef(paths)? [count(points)] :
is_num(paths[0])? [paths] :
paths;
echo(points=points);
echo(paths=paths);
linear_extrude(height=0.01, convexity=convexity, center=true) {
polygon(points=points, paths=paths, convexity=convexity);
}
dups = vector_search(points, EPSILON, points);
if (vertices) color("red") {
if (vertices)
_debug_poly_verts(points,size);
if (edges)
for (j = [0:1:len(paths)-1]) _debug_poly_edges(j, points, paths[j], vertices, size);
}
module _debug_poly_verts(points, size)
{
labels=is_vector(points[0]) ? [for(i=idx(points)) str(i)]
:[for(j=idx(points), i=idx(points[j])) str(chr(97+j),i)];
points = is_vector(points[0]) ? points : flatten(points);
dups = vector_search(points, EPSILON, points);
color("red") {
for (ind=dups){
numstr = str_join([for(i=ind) str(i)],",");
numstr = str_join(select(labels,ind),",");
up(0.2) {
translate(points[ind[0]]) {
linear_extrude(height=0.1, convexity=10, center=true) {
@ -1324,10 +1337,13 @@ module debug_polygon(points, paths, vertices=true, edges=true, convexity=2, size
}
}
}
if (edges)
for (j = [0:1:len(paths)-1]) {
path = paths[j];
if (vertices){
}
module _debug_poly_edges(j,points, path,vertices,size)
{
path = default(path, count(len(points)));
if (vertices){
translate(points[path[0]]) {
color("cyan") up(0.1) cylinder(d=size*1.5, h=0.01, center=false, $fn=12);
}
@ -1347,8 +1363,6 @@ module debug_polygon(points, paths, vertices=true, edges=true, convexity=2, size
}
}
}
}
}
}
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View file

@ -30,7 +30,7 @@ function _inset_corner(corner, mask_angle, inset, excess, flat_top) =
// Section: 2D Masking Shapes
// Function&Module: mask2d_roundover()
// Synopsis: Creates a 2D beading mask shape useful for rounding edges.
// Synopsis: Creates a circular mask shape for rounding edges or beading.
// SynTags: Geom, Path
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable, Masks (2D)
// See Also: corner_profile(), edge_profile(), face_profile(), fillet()
@ -78,9 +78,9 @@ function _inset_corner(corner, mask_angle, inset, excess, flat_top) =
// Example(2D): 2D Bead Mask by Radius, acute angle
// mask2d_roundover(r=10, inset=2, mask_angle=50);
// Example(2D): 2D Bead Mask for obtuse angle, by height
// mask2d_roundover(h=10, inset=2, mask_angle=135);
// mask2d_roundover(h=10, inset=2, mask_angle=135, $fn=64);
// Example(2D): 2D Bead Mask for obtuse angle, by height with flat top
// mask2d_roundover(h=10, inset=2, mask_angle=135, flat_top=true);
// mask2d_roundover(h=10, inset=2, mask_angle=135, flat_top=true, $fn=64);
// Example(2D): 2D Angled Bead Mask by Joint Length. Joint length does not include the inset.
// mask2d_roundover(joint=10, inset=2, mask_angle=75);
// Example(2D): Increasing the Excess
@ -102,31 +102,31 @@ function _inset_corner(corner, mask_angle, inset, excess, flat_top) =
// xrot(90)
// linear_extrude(height=30, center=true)
// mask2d_roundover(r=10);
// Example: Rounding over top of an extreme prismoid using height option
// Example(3D,Med): Rounding over top of an extreme prismoid using height option
// diff()
// prismoid([30,20], [50,60], h=50, shift=[40,50])
// edge_profile(TOP, excess=20)
// mask2d_roundover(height=5, mask_angle=$edge_angle);
// Example: Using the quarter_round option results in a lip on obtuse angles, so it may not be the best choice for pure roundings.
// mask2d_roundover(height=5, mask_angle=$edge_angle, $fn=128);
// Example(3D,Med): Using the quarter_round option results in a lip on obtuse angles, so it may not be the best choice for pure roundings.
// diff()
// prismoid([30,20], [50,60], h=50, shift=[40,50])
// edge_profile(TOP, excess=20)
// mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round=true);
// Example: Can improve the quarter round option by using it only for acute angles and falling back on regular rounding for obtuse angles. Note that in this case, obtuse angles are fully rounded, but acute angles still have a corner, but one that is not as sharp as the original angle.
// mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round=true, $fn=128);
// Example(3D,Med): Can improve the quarter round option by using it only for acute angles and falling back on regular rounding for obtuse angles. Note that in this case, obtuse angles are fully rounded, but acute angles still have a corner, but one that is not as sharp as the original angle.
// diff()
// prismoid([30,20], [50,60], h=50, shift=[40,50])
// edge_profile(TOP, excess=20)
// mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round=$edge_angle<90);
// Example: Creating a bead on the prismoid using the height option with flat_top=true:
// mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round=$edge_angle<90, $fn=32);
// Example(3D,Med): Creating a bead on the prismoid using the height option with flat_top=true:
// diff()
// prismoid([30,20], [50,60], h=50, shift=[40,50])
// edge_profile(TOP, excess=20)
// mask2d_roundover(height=5, mask_angle=$edge_angle, inset=1.5, flat_top=true);
// Example: Bead may be more pleasing using the quarter_round option, with curves terminating in a plane parallel to the prismoid top. The size of the inset edge will be larger than requested when the angle is obtuse.
// mask2d_roundover(height=5, mask_angle=$edge_angle, inset=1.5, flat_top=true, $fn=128);
// Example(3D,Med): Bead may be more pleasing using the quarter_round option, with curves terminating in a plane parallel to the prismoid top. The size of the inset edge will be larger than requested when the angle is obtuse.
// diff()
// prismoid([30,20], [50,60], h=50, shift=[40,50])
// edge_profile(TOP, excess=20)
// mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round=true, inset=1.5);
// mask2d_roundover(r=5, mask_angle=$edge_angle, quarter_round=true, inset=1.5, $fn=128);
module mask2d_roundover(r, inset=0, mask_angle=90, excess=0.01, flat_top, d, h, height, cut, quarter_round=false, joint, anchor=CENTER,spin=0) {
path = mask2d_roundover(r=r, d=d, h=h, height=height, cut=cut, joint=joint, inset=inset,
flat_top=flat_top, mask_angle=mask_angle, excess=excess, quarter_round=quarter_round);
@ -204,7 +204,7 @@ function mask2d_roundover(r, inset=0, mask_angle=90, excess=0.01, flat_top, quar
// Function&Module: mask2d_teardrop()
// Synopsis: Creates a 2D teardrop mask shape with a controllable maximum angle from vertical.
// Synopsis: Creates a 2D teardrop shape with specified max angle from vertical.
// SynTags: Geom, Path
// Topics: Shapes (2D), Paths (2D), Path Generators, Attachable, Masks (2D), FDM Optimized
// See Also: corner_profile(), edge_profile(), face_profile()
@ -237,15 +237,15 @@ function mask2d_roundover(r, inset=0, mask_angle=90, excess=0.01, flat_top, quar
// Side Effects:
// Tags the children with "remove" (and hence sets `$tag`) if no tag is already set.
// Example(2D): 2D Teardrop Mask
// mask2d_teardrop(r=10);
// mask2d_teardrop(r=10,$fn=64);
// Example(2D): 2D Teardrop Mask for acute angle
// mask2d_teardrop(r=10, mask_angle=75);
// mask2d_teardrop(r=10, mask_angle=75,$fn=64);
// Example(2D): 2D Teardrop Mask for obtuse angle, specifying height
// mask2d_teardrop(h=10, mask_angle=115);
// mask2d_teardrop(h=10, mask_angle=115,$fn=128);
// Example(2D): Increasing Excess
// mask2d_teardrop(r=10, mask_angle=75, excess=2);
// Example(2D): Using a Custom Angle
// mask2d_teardrop(r=10,angle=30);
// mask2d_teardrop(r=10,angle=30,$fn=128);
// Example(2D): With an acute mask_angle you can choose an angle of zero:
// mask2d_teardrop(r=10,mask_angle=44,angle=0);
// Example(2D): With an acute mask_angle you can even choose a negative angle
@ -379,7 +379,7 @@ module mask2d_teardrop(r, angle=45, mask_angle=90, excess=0.01, inset=0, flat_to
// Example(2D): 2D Cove Mask for obtuse angle with flat top. This is one solution to the problem of the previous example. Max height is achieved at the left corner.
// mask2d_cove(h=10,mask_angle=145,flat_top=true);
// Example(2D): 2D Cove Mask for obtuse angle, specified by height with bulge parameter. Another way to fix the problem of the previous example: the max height is again achieved at the left corner.
// mask2d_cove(h=10,mask_angle=145, bulge=3);
// mask2d_cove(h=10,mask_angle=145, bulge=3, $fn=128);
// Example(2D): 2D Cove Mask for acute angle with quarter_round enabled
// mask2d_cove(r=10,mask_angle=55,quarter_round=true);
// Example(2D): 2D Cove Mask for obtuse angle, specified by height. Note that flat_top is on by default in quarter_round mode.
@ -399,21 +399,21 @@ module mask2d_teardrop(r, angle=45, mask_angle=90, excess=0.01, inset=0, flat_to
// xrot(90)
// linear_extrude(height=30, center=true)
// mask2d_cove(r=5, inset=5);
// Example: A cove on top of an extreme prismoid top by setting height and using flat_top mode. This creates **long** flat tops sections at obtuse angles.
// Example(3D,Med): A cove on top of an extreme prismoid top by setting height and using flat_top mode. This creates **long** flat tops sections at obtuse angles.
// diff()
// prismoid([50,60], [20,30], h=20, shift=[25,16])
// edge_profile(TOP, excess=20)
// mask2d_cove(h=5, inset=0, mask_angle=$edge_angle, flat_top=true);
// Example: Cove on an extreme prismoid top by setting height and bulge. Obtuse angles have long **curved** sections.
// mask2d_cove(h=5, inset=0, mask_angle=$edge_angle, flat_top=true, $fn=128);
// Example(3D,Med): Cove on an extreme prismoid top by setting height and bulge. Obtuse angles have long **curved** sections.
// diff()
// prismoid([50,60], [20,30], h=20, shift=[25,16])
// edge_profile(TOP, excess=20)
// mask2d_cove(h=5, inset=0, mask_angle=$edge_angle, bulge=1);
// Example: Rounding an extreme prismoid top using quarter_round. Another way to handle this situation.
// mask2d_cove(h=5, inset=0, mask_angle=$edge_angle, bulge=1, $fn=128);
// Example(3D,Med): Rounding an extreme prismoid top using quarter_round. Another way to handle this situation.
// diff()
// prismoid([50,60], [20,30], h=20, shift=[25,16])
// edge_profile(TOP, excess=20)
// mask2d_cove(r=5, inset=0, mask_angle=$edge_angle, quarter_round=true);
// mask2d_cove(r=5, inset=0, mask_angle=$edge_angle, quarter_round=true, $fn=128);
module mask2d_cove(r, inset=0, mask_angle=90, excess=0.01, flat_top, bulge, d, h, height, quarter_round=false, anchor=CENTER, spin=0) {
path = mask2d_cove(r=r, d=d, h=h, height=height, bulge=bulge, flat_top=flat_top, quarter_round=quarter_round, inset=inset, mask_angle=mask_angle, excess=excess);
@ -572,17 +572,17 @@ function mask2d_cove(r, inset=0, mask_angle=90, excess=0.01, flat_top, d, h, hei
// xrot(90)
// linear_extrude(height=30, center=true)
// mask2d_chamfer(edge=10);
// Example: Chamfering an extreme prismoid by setting height
// Example(3D,Med): Chamfering an extreme prismoid by setting height
// diff()
// prismoid([50,60], [20,30], h=20, shift=[25,16])
// edge_profile(TOP, excess=20)//let(f=$edge_angle)
// mask2d_chamfer(h=5,mask_angle=$edge_angle);
// Example: Chamfering an extreme prismoid with a fixed chamfer angle. Note that a very large chamfer angle is required because of the large obtuse angles.
// Example(3D,Med): Chamfering an extreme prismoid with a fixed chamfer angle. Note that a very large chamfer angle is required because of the large obtuse angles.
// diff()
// prismoid([50,60], [20,30], h=20, shift=[25,16])
// edge_profile(TOP, excess=20)//let(f=$edge_angle)
// mask2d_chamfer(h=5,mask_angle=$edge_angle,angle=64);
// Example: Chamfering an extreme prismoid by setting height with inset and flat_top=true.
// Example(3D,Med): Chamfering an extreme prismoid by setting height with inset and flat_top=true.
// diff()
// prismoid([50,60], [20,30], h=20, shift=[25,16])
// edge_profile(TOP, excess=20)//let(f=$edge_angle)

View file

@ -300,7 +300,7 @@ function force_region(poly) = is_path(poly) ? [poly] : poly;
// Synopsis: Creates the 2D polygons described by the given region or list of polygons.
// SynTags: Geom
// Topics: Regions, Paths, Polygons, List Handling
// See Also: make_region(), region()
// See Also: make_region(), debug_region()
// Usage:
// region(r, [anchor], [spin=], [cp=], [atype=]) [ATTACHMENTS];
// Description:
@ -339,6 +339,51 @@ module region(r, anchor="origin", spin=0, cp="centroid", atype="hull")
// Module: debug_region()
// Synopsis: Draws an annotated region.
// SynTags: Geom
// Topics: Shapes (2D)
// See Also: region(), debug_polygon(), debug_vnf(), debug_bezier()
//
// Usage:
// debug_region(region, [vertices=], [edges=], [convexity=], [size=]);
// Description:
// A replacement for {{region()}} that displays the region and labels the vertices and
// edges. The region vertices and edges are labeled with letters to identify the path
// component in the region, starting with A.
// The start of each path is marked with a blue circle and the end with a pink diamond.
// You can suppress the display of vertex or edge labeling using the `vertices` and `edges` arguments.
// Arguments:
// region = region to display
// ---
// vertices = if true display vertex labels and start/end markers. Default: true
// edges = if true display edge labels. Default: true
// convexity = The max number of walls a ray can pass through the given polygon paths.
// size = The base size of the line and labels.
// Example(2D,Big):
// region = make_region([square(15), move([5,5],square(15))]);
// debug_region(region,size=1);
module debug_region(region, vertices=true, edges=true, convexity=2, size=1)
{
if (is_path(region) || (is_region(region) && len(region)==1))
debug_polygon(force_path(region), vertices=vertices, edges=edges, convexity=convexity, size=size);
else {
for(i=idx(region))
echo(str("points_",chr(97+i)," = ",region[i]))
linear_extrude(height=0.01, convexity=convexity, center=true)
region(region);
if(vertices)
_debug_poly_verts(region,size);
for(j=idx(region)){
if(edges)
_debug_poly_edges(j,region[j],vertices=vertices,size=size);
}
}
}
// Section: Geometrical calculations with regions
// Function: point_in_region()
@ -578,7 +623,7 @@ function split_region_at_region_crossings(region1, region2, closed1=true, closed
// Function: region_parts()
// Synopsis: Splits a region into a list of regions.
// Synopsis: Splits a region into a list of connected regions.
// SynTags: RegList
// Topics: Regions, List Handling
// See Also: split_region_at_region_crossings()