From e4f249786363676419c360a23c3dda3cf86077af Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Mon, 16 Nov 2020 17:50:08 -0800 Subject: [PATCH] Changes all references to polyline to path. --- beziers.scad | 42 +++++++++++++-------------- debug.scad | 28 +++++++++--------- joiners.scad | 3 +- paths.scad | 76 +++++++++++++------------------------------------ regions.scad | 8 +++--- rounding.scad | 3 +- shapes2d.scad | 2 +- skin.scad | 3 +- std.scad | 1 + transforms.scad | 6 ++-- version.scad | 2 +- wiring.scad | 4 +-- 12 files changed, 67 insertions(+), 111 deletions(-) diff --git a/beziers.scad b/beziers.scad index a8484b6..af9675e 100644 --- a/beziers.scad +++ b/beziers.scad @@ -9,10 +9,8 @@ ////////////////////////////////////////////////////////////////////// -include - // Section: Terminology -// **Polyline**: A series of points joined by straight line segements. +// **Path**: A series of points joined by straight line segements. // . // **Bezier Curve**: A mathematical curve that joins two endpoints, following a curve determined by one or more control points. // . @@ -27,7 +25,7 @@ include // . // **Bezier Path**: A list of bezier segments flattened out into a list of points, where each segment shares the endpoint of the previous segment as a start point. A cubic Bezier Path looks something like: // `[endpt1, cp1, cp2, endpt2, cp3, cp4, endpt3]` -// **NOTE**: A bezier path is *NOT* a polyline. It is only the points and controls used to define the curve. +// **NOTE**: A "bezier path" is *NOT* a standard path. It is only the points and controls used to define the curve. // . // **Bezier Patch**: A surface defining grid of (N+1) by (N+1) bezier points. If a Bezier Segment defines a curved line, a Bezier Patch defines a curved surface. // . @@ -374,7 +372,7 @@ function bezier_segment_length(curve, start_u=0, end_u=1, max_deflect=0.01) = // p0 = [40, 0]; // p1 = [0, 0]; // p2 = [30, 30]; -// trace_polyline([p0,p1,p2], showpts=true, size=0.5, color="green"); +// trace_path([p0,p1,p2], showpts=true, size=0.5, color="green"); // fbez = fillet3pts(p0,p1,p2, 10); // trace_bezier(slice(fbez, 1, -2), size=1); function fillet3pts(p0, p1, p2, r, d, maxerr=0.1, w=0.5, dw=0.25) = let( @@ -482,11 +480,11 @@ function bezier_path_length(path, N=3, max_deflect=0.001) = -// Function: bezier_polyline() +// Function: bezier_path() // Usage: -// bezier_polyline(bezier, [splinesteps], [N]) +// bezier_path(bezier, [splinesteps], [N]) // Description: -// Takes a bezier path and converts it into a polyline. +// Takes a bezier path and converts it into a path of points. // Arguments: // bezier = A bezier path to approximate. // splinesteps = Number of straight lines to split each bezier segment into. default=16 @@ -498,9 +496,9 @@ function bezier_path_length(path, N=3, max_deflect=0.001) = // [60,25], [70,0], [80,-25], // [80,-50], [50,-50] // ]; -// trace_polyline(bez, size=1, N=3, showpts=true); -// trace_polyline(bezier_polyline(bez, N=3), size=3); -function bezier_polyline(bezier, splinesteps=16, N=3) = +// trace_path(bez, size=1, N=3, showpts=true); +// trace_path(bezier_path(bez, N=3), size=3); +function bezier_path(bezier, splinesteps=16, N=3) = assert(is_path(bezier)) assert(is_int(N)) assert(is_int(splinesteps)) @@ -598,15 +596,15 @@ function path_to_bezier(path, tangents, size, relsize, uniform=false, closed=fal // Usage: // fillet_path(pts, fillet, [maxerr]); // Description: -// Takes a 3D polyline path and fillets the corners, returning a 3d cubic (degree 3) bezier path. +// Takes a 3D path and fillets the corners, returning a 3d cubic (degree 3) bezier path. // Arguments: -// pts = 3D Polyline path to fillet. -// fillet = The radius to fillet/round the polyline corners by. +// pts = 3D path to fillet. +// fillet = The radius to fillet/round the path corners by. // maxerr = Max amount bezier curve should diverge from actual radius curve. Default: 0.1 // Example(2D): // pline = [[40,0], [0,0], [35,35], [0,70], [-10,60], [-5,55], [0,60]]; // bez = fillet_path(pline, 10); -// trace_polyline(pline, showpts=true, size=0.5, color="green"); +// trace_path(pline, showpts=true, size=0.5, color="green"); // trace_bezier(bez, size=1); function fillet_path(pts, fillet, maxerr=0.1) = concat( [pts[0], pts[0]], @@ -722,7 +720,7 @@ module bezier_polygon(bezier, splinesteps=16, N=3) { assert(is_int(N)); assert(is_int(splinesteps)); assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); - polypoints=bezier_polyline(bezier, splinesteps, N); + polypoints=bezier_path(bezier, splinesteps, N); polygon(points=slice(polypoints, 0, -1)); } @@ -803,7 +801,7 @@ module rotate_sweep_bezier(bezier, splinesteps=16, N=3, convexity=undef, angle=3 assert(is_int(N)); assert(is_num(angle)); assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); - oline = bezier_polyline(bezier, splinesteps=splinesteps, N=N); + oline = bezier_path(bezier, splinesteps=splinesteps, N=N); maxx = max([for (pt = oline) abs(pt[0])]); miny = min(subindex(oline,1)); maxy = max(subindex(oline,1)); @@ -839,7 +837,7 @@ module bezier_path_extrude(bezier, splinesteps=16, N=3, convexity=undef, clipsiz assert(is_int(N)); assert(is_num(clipsize)); assert(len(bezier)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); - path = slice(bezier_polyline(bezier, splinesteps, N), 0, -1); + path = slice(bezier_path(bezier, splinesteps, N), 0, -1); path_extrude(path, convexity=convexity, clipsize=clipsize) children(); } @@ -876,8 +874,8 @@ module bezier_sweep_bezier(bezier, path, pathsteps=16, bezsteps=16, bezN=3, path assert(is_int(pathN)); assert(len(bezier)%bezN == 1, str("For argument bezier, a degree ",bezN," bezier path shound have a multiple of ",bezN," points in it, plus 1.")); assert(len(path)%pathN == 1, str("For argument bezier, a degree ",pathN," bezier path shound have a multiple of ",pathN," points in it, plus 1.")); - bez_points = simplify_path(bezier_polyline(bezier, bezsteps, bezN)); - path_points = simplify_path(path3d(bezier_polyline(path, pathsteps, pathN))); + bez_points = simplify_path(bezier_path(bezier, bezsteps, bezN)); + path_points = simplify_path(path3d(bezier_path(path, pathsteps, pathN))); path_sweep(bez_points, path_points); } @@ -902,8 +900,8 @@ module trace_bezier(bez, N=3, size=1) { assert(is_path(bez)); assert(is_int(N)); assert(len(bez)%N == 1, str("A degree ",N," bezier path shound have a multiple of ",N," points in it, plus 1.")); - trace_polyline(bez, N=N, showpts=true, size=size, color="green"); - trace_polyline(bezier_polyline(bez, N=N), size=size, color="cyan"); + trace_path(bez, N=N, showpts=true, size=size, color="green"); + trace_path(bezier_path(bez, N=N), size=size, color="cyan"); } diff --git a/debug.scad b/debug.scad index 545e25e..c2568c9 100644 --- a/debug.scad +++ b/debug.scad @@ -8,32 +8,30 @@ // ``` ////////////////////////////////////////////////////////////////////// -include - // Section: Debugging Paths and Polygons -// Module: trace_polyline() +// Module: trace_path() // Description: -// Renders lines between each point of a polyline path. +// Renders lines between each point of a path. // Can also optionally show the individual vertex points. // Arguments: -// pline = The array of points in the polyline. +// path = The list of points in the path. // closed = If true, draw the segment from the last vertex to the first. Default: false // showpts = If true, draw vertices and control points. // N = Mark the first and every Nth vertex after in a different color and shape. // size = Diameter of the lines drawn. // color = Color to draw the lines (but not vertices) in. // Example(FlatSpin): -// polyline = [for (a=[0:30:210]) 10*[cos(a), sin(a), sin(a)]]; -// trace_polyline(polyline, showpts=true, size=0.5, color="lightgreen"); -module trace_polyline(pline, closed=false, showpts=false, N=1, size=1, color="yellow") { - assert(is_path(pline),"Input pline is not a path"); +// path = [for (a=[0:30:210]) 10*[cos(a), sin(a), sin(a)]]; +// trace_path(path, showpts=true, size=0.5, color="lightgreen"); +module trace_path(path, closed=false, showpts=false, N=1, size=1, color="yellow") { + assert(is_path(path),"Invalid path argument"); sides = segs(size/2); - pline = closed? close_path(pline) : pline; + path = closed? close_path(path) : path; if (showpts) { - for (i = [0:1:len(pline)-1]) { - translate(pline[i]) { + for (i = [0:1:len(path)-1]) { + translate(path[i]) { if (i%N == 0) { color("blue") sphere(d=size*2.5, $fn=8); } else { @@ -47,11 +45,11 @@ module trace_polyline(pline, closed=false, showpts=false, N=1, size=1, color="ye } } if (N!=3) { - color(color) stroke(path3d(pline), width=size, $fn=8); + color(color) stroke(path3d(path), width=size, $fn=8); } else { - for (i = [0:1:len(pline)-2]) { + for (i = [0:1:len(path)-2]) { if (N!=3 || (i%N) != 1) { - color(color) extrude_from_to(pline[i], pline[i+1]) circle(d=size, $fn=sides); + color(color) extrude_from_to(path[i], path[i+1]) circle(d=size, $fn=sides); } } } diff --git a/joiners.scad b/joiners.scad index f68b124..38594a8 100644 --- a/joiners.scad +++ b/joiners.scad @@ -10,7 +10,6 @@ include -include // Section: Half Joiners @@ -989,7 +988,7 @@ module rabbit_clip(type, length, width, snap, thickness, depth, compression=0.1 : let(side_smooth=select(pin_smooth, 0, 2)) concat(side_smooth, [socket_smooth], reverse(side_smooth)); bez = path_to_bezier(path,relsize=smoothing,tangents=tangent); - rounded = bezier_polyline(bez,splinesteps=splinesteps); + rounded = bezier_path(bez,splinesteps=splinesteps); bounds = pointlist_bounds(rounded); //kk = search([bounds[1].y], subindex(rounded,1)); //echo(rounded[kk[0]]); diff --git a/paths.scad b/paths.scad index e0e7c95..ac95666 100644 --- a/paths.scad +++ b/paths.scad @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////// // LibFile: paths.scad -// Polylines, polygons and paths. +// Support for polygons and paths. // To use, add the following lines to the beginning of your file: // ``` // include @@ -421,7 +421,7 @@ function path_torsion(path, closed=false) = // cp = Centerpoint of spiral. Default: `[0,0]` // scale = [X,Y] scaling factors for each axis. Default: `[1,1]` // Example(3D): -// trace_polyline(path3d_spiral(turns=2.5, h=100, n=24, r=50), N=1, showpts=true); +// trace_path(path3d_spiral(turns=2.5, h=100, n=24, r=50), N=1, showpts=true); function path3d_spiral(turns=3, h=100, n=12, r, d, cp=[0,0], scale=[1,1]) = let( rr=get_radius(r=r, d=d, dflt=100), cnt=floor(turns*n), @@ -435,44 +435,6 @@ function path3d_spiral(turns=3, h=100, n=12, r, d, cp=[0,0], scale=[1,1]) = let( ]; -// Function: points_along_path3d() -// Usage: -// points_along_path3d(polyline, path); -// Description: -// Calculates the vertices needed to create a `polyhedron()` of the -// extrusion of `polyline` along `path`. The closed 2D path shold be -// centered on the XY plane. The 2D path is extruded perpendicularly -// along the 3D path. Produces a list of 3D vertices. Vertex count -// is `len(polyline)*len(path)`. Gives all the reoriented vertices -// for `polyline` at the first point in `path`, then for the second, -// and so on. -// Arguments: -// polyline = A closed list of 2D path points. -// path = A list of 3D path points. -function points_along_path3d( - polyline, // The 2D polyline to drag along the 3D path. - path, // The 3D polyline path to follow. - q=Q_Ident(), // Used in recursion - n=0 // Used in recursion -) = let( - end = len(path)-1, - v1 = (n == 0)? [0, 0, 1] : unit(path[n]-path[n-1]), - v2 = (n == end)? unit(path[n]-path[n-1]) : unit(path[n+1]-path[n]), - crs = cross(v1, v2), - axis = norm(crs) <= 0.001? [0, 0, 1] : crs, - ang = vector_angle(v1, v2), - hang = ang * (n==0? 1.0 : 0.5), - hrot = Quat(axis, hang), - arot = Quat(axis, ang), - roth = Q_Mul(hrot, q), - rotm = Q_Mul(arot, q) -) concat( - [for (i = [0:1:len(polyline)-1]) Qrot(roth,p=point3d(polyline[i])) + path[n]], - (n == end)? [] : points_along_path3d(polyline, path, rotm, n+1) -); - - - // Function: path_self_intersections() // Usage: // isects = path_self_intersections(path, [eps]); @@ -529,9 +491,9 @@ function path_self_intersections(path, closed=true, eps=EPSILON) = // Function: split_path_at_self_crossings() // Usage: -// polylines = split_path_at_self_crossings(path, [closed], [eps]); +// paths = split_path_at_self_crossings(path, [closed], [eps]); // Description: -// Splits a path into polyline sections wherever the path crosses itself. +// Splits a path into sub-paths wherever the original path crosses itself. // Splits may occur mid-segment, so new vertices will be created at the intersection points. // Arguments: // path = The path to split up. @@ -539,8 +501,8 @@ function path_self_intersections(path, closed=true, eps=EPSILON) = // eps = Acceptable variance. Default: `EPSILON` (1e-9) // Example(2D): // path = [ [-100,100], [0,-50], [100,100], [100,-100], [0,50], [-100,-100] ]; -// polylines = split_path_at_self_crossings(path); -// rainbow(polylines) stroke($item, closed=false, width=2); +// paths = split_path_at_self_crossings(path); +// rainbow(paths) stroke($item, closed=false, width=2); function split_path_at_self_crossings(path, closed=true, eps=EPSILON) = let( path = cleanup_path(path, eps=eps), @@ -681,11 +643,11 @@ function _extreme_angle_fragment(seg, fragments, rightmost=true, eps=EPSILON) = // Usage: // assemble_a_path_from_fragments(subpaths); // Description: -// Given a list of incomplete paths, assembles them together into one complete closed path, and +// Given a list of paths, assembles them together into one complete closed polygon path, and // remainder fragments. Returns [PATH, FRAGMENTS] where FRAGMENTS is the list of remaining -// polyline path fragments. +// unused path fragments. // Arguments: -// fragments = List of polylines to be assembled into complete polygons. +// fragments = List of paths to be assembled into complete polygons. // rightmost = If true, assemble paths using rightmost turns. Leftmost if false. // startfrag = The fragment to start with. Default: 0 // eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9) @@ -738,9 +700,9 @@ function assemble_a_path_from_fragments(fragments, rightmost=true, startfrag=0, // Usage: // assemble_path_fragments(subpaths); // Description: -// Given a list of incomplete paths, assembles them together into complete closed paths if it can. +// Given a list of paths, assembles them together into complete closed polygon paths if it can. // Arguments: -// fragments = List of polylines to be assembled into complete polygons. +// fragments = List of paths to be assembled into complete polygons. // eps = The epsilon error value to determine whether two points coincide. Default: `EPSILON` (1e-9) function assemble_path_fragments(fragments, eps=EPSILON, _finished=[]) = len(fragments)==0? _finished : @@ -832,10 +794,10 @@ module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slic // Module: spiral_sweep() // Description: -// Takes a closed 2D polyline path, centered on the XY plane, and -// extrudes it along a 3D spiral path of a given radius, height and twist. +// Takes a closed 2D polygon path, centered on the XY plane, and sweeps/extrudes it along a 3D spiral path +// of a given radius, height and twist. // Arguments: -// polyline = Array of points of a polyline path, to be extruded. +// path = Array of points of a polygon path, to be extruded. // h = height of the spiral to extrude along. // r = Radius of the spiral to extrude along. Default: 50 // d = Diameter of the spiral to extrude along. @@ -847,10 +809,10 @@ module extrude_from_to(pt1, pt2, convexity=undef, twist=undef, scale=undef, slic // Example: // poly = [[-10,0], [-3,-5], [3,-5], [10,0], [0,-30]]; // spiral_sweep(poly, h=200, r=50, twist=1080, $fn=36); -module spiral_sweep(polyline, h, r, twist=360, center, d, anchor, spin=0, orient=UP) { +module spiral_sweep(poly, h, r, twist=360, center, d, anchor, spin=0, orient=UP) { r = get_radius(r=r, d=d, dflt=50); - polyline = path3d(polyline); - pline_count = len(polyline); + poly = path3d(poly); + pline_count = len(poly); steps = ceil(segs(r)*(twist/360)); anchor = get_anchor(anchor,center,BOT,BOT); @@ -863,7 +825,7 @@ module spiral_sweep(polyline, h, r, twist=360, center, d, anchor, spin=0, orient dy = r*sin(a), dz = h * (p/steps), pts = apply_list( - polyline, [ + poly, [ affine3d_xrot(90), affine3d_zrot(a), affine3d_translate([dx, dy, dz-h/2]) @@ -902,7 +864,7 @@ module spiral_sweep(polyline, h, r, twist=360, center, d, anchor, spin=0, orient // Module: path_extrude() // Description: -// Extrudes 2D children along a 3D polyline path. This may be slow. +// Extrudes 2D children along a 3D path. This may be slow. // Arguments: // path = array of points for the bezier path to extrude along. // convexity = maximum number of walls a ran can pass through. diff --git a/regions.scad b/regions.scad index b55a4f1..0a45673 100644 --- a/regions.scad +++ b/regions.scad @@ -154,9 +154,9 @@ function region_path_crossings(path, region, closed=true, eps=EPSILON) = sort([ // Function: split_path_at_region_crossings() // Usage: -// polylines = split_path_at_region_crossings(path, region, [eps]); +// paths = split_path_at_region_crossings(path, region, [eps]); // Description: -// Splits a path into polyline sections wherever the path crosses the perimeter of a region. +// Splits a path into sub-paths wherever the path crosses the perimeter of a region. // Splits may occur mid-segment, so new vertices will be created at the intersection points. // Arguments: // path = The path to split up. @@ -166,9 +166,9 @@ function region_path_crossings(path, region, closed=true, eps=EPSILON) = sort([ // Example(2D): // path = square(50,center=false); // region = [circle(d=80), circle(d=40)]; -// polylines = split_path_at_region_crossings(path, region); +// paths = split_path_at_region_crossings(path, region); // color("#aaa") region(region); -// rainbow(polylines) stroke($item, closed=false, width=2); +// rainbow(paths) stroke($item, closed=false, width=2); function split_path_at_region_crossings(path, region, closed=true, eps=EPSILON) = let( path = deduplicate(path, eps=eps), diff --git a/rounding.scad b/rounding.scad index 876c420..2a3516c 100644 --- a/rounding.scad +++ b/rounding.scad @@ -181,7 +181,6 @@ include // path_sweep(regular_ngon(n=36,or=.1),round_corners(list2,closed=false, method="circle", cut = 0.75)); // Example(FlatSpin): Rounding a spiral with increased rounding along the length // // Construct a square spiral path in 3D -// include // $fn=36; // square = [[0,0],[1,0],[1,1],[0,1]]; // spiral = flatten(repeat(concat(square,reverse(square)),5)); // Squares repeat 10 times, forward and backward @@ -454,7 +453,7 @@ function smooth_path(path, tangents, size, relsize, splinesteps=10, uniform=fals let ( bez = path_to_bezier(path, tangents=tangents, size=size, relsize=relsize, uniform=uniform, closed=closed) ) - bezier_polyline(bez,splinesteps=splinesteps); + bezier_path(bez,splinesteps=splinesteps); diff --git a/shapes2d.scad b/shapes2d.scad index 6b5a6dd..4eda015 100644 --- a/shapes2d.scad +++ b/shapes2d.scad @@ -377,7 +377,7 @@ module stroke( // stroke(closed=true, path); // Example(FlatSpin): // path = arc(points=[[0,30,0],[0,0,30],[30,0,0]]); -// trace_polyline(path, showpts=true, color="cyan"); +// trace_path(path, showpts=true, color="cyan"); function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, long=false, cw=false, ccw=false) = // First try for 2D arc specified by width and thickness is_def(width) && is_def(thickness)? ( diff --git a/skin.scad b/skin.scad index 37b5c51..1c1c45a 100644 --- a/skin.scad +++ b/skin.scad @@ -10,7 +10,6 @@ // - https://github.com/openscad/list-comprehension-demos/blob/master/skin.scad ////////////////////////////////////////////////////////////////////// -include // Section: Skinning @@ -824,7 +823,7 @@ function associate_vertices(polygons, split, curpoly=0) = // Function&Module: sweep() // Usage: As Module -// sweep(shape, transformations, ) +// sweep(shape, transformations, , ) // Usage: As Function // vnf = sweep(shape, transformations, , ); // Description: diff --git a/std.scad b/std.scad index 685b6ab..94d80a0 100644 --- a/std.scad +++ b/std.scad @@ -31,6 +31,7 @@ include include include include +include include include include diff --git a/transforms.scad b/transforms.scad index e9cfafd..43cb257 100644 --- a/transforms.scad +++ b/transforms.scad @@ -671,8 +671,8 @@ function yscale(y=1, p=undef, planar=false) = (planar || (!is_undef(p) && len(p) // // Example: Scaling Points // path = xrot(90,p=path3d(circle(d=50,$fn=12))); -// #trace_polyline(path); -// trace_polyline(zscale(2,p=path)); +// #trace_path(path); +// trace_path(zscale(2,p=path)); module zscale(z=1) scale([1,1,z]) children(); function zscale(z=1, p=undef) = scale([1,1,z],p=p); @@ -917,7 +917,7 @@ function zflip(z=0,p) = // color("blue") move_copies(pts) circle(d=3, $fn=8); // Example(FlatSpin): Calling as a 3D Function // pts = skew(p=path3d(square(40,center=true)), szx=0.5, szy=0.3); -// trace_polyline(close_path(pts), showpts=true); +// trace_path(close_path(pts), showpts=true); module skew(sxy=0, sxz=0, syx=0, syz=0, szx=0, szy=0) { multmatrix( diff --git a/version.scad b/version.scad index f0e7380..9d44c69 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,465]; +BOSL_VERSION = [2,0,466]; // Section: BOSL Library Version Functions diff --git a/wiring.scad b/wiring.scad index bc970d2..d16120a 100644 --- a/wiring.scad +++ b/wiring.scad @@ -72,7 +72,7 @@ function hex_offsets(n, d, lev=0, arr=[]) = // Usage: // wiring(path, wires, [wirediam], [rounding], [wirenum], [bezsteps]); // Arguments: -// path = The 3D polyline path that the wire bundle should follow. +// path = The 3D path that the wire bundle should follow. // wires = The number of wires in the wiring bundle. // wirediam = The diameter of each wire in the bundle. // rounding = The radius that the path corners will be rounded to. @@ -90,7 +90,7 @@ module wiring(path, wires, wirediam=2, rounding=10, wirenum=0, bezsteps=12) { ]; offsets = hex_offsets(wires, wirediam); bezpath = fillet_path(path, rounding); - poly = simplify_path(path3d(bezier_polyline(bezpath, bezsteps))); + poly = simplify_path(path3d(bezier_path(bezpath, bezsteps))); n = max(segs(wirediam), 8); r = wirediam/2; for (i = [0:1:wires-1]) {