diff --git a/drawing.scad b/drawing.scad index 50261e9..2503d35 100644 --- a/drawing.scad +++ b/drawing.scad @@ -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 diff --git a/masks2d.scad b/masks2d.scad index 37812d2..798fa4e 100644 --- a/masks2d.scad +++ b/masks2d.scad @@ -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() @@ -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() diff --git a/regions.scad b/regions.scad index 7c64054..84b46b4 100644 --- a/regions.scad +++ b/regions.scad @@ -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()