From 855aa0cf3637f0f009520fc0e0fe9aec34dd402f Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Fri, 31 Jan 2020 21:35:04 -0800 Subject: [PATCH] Re-organized region.scad docs. --- regions.scad | 72 ++++++++++++++++++++++++++-------------------------- version.scad | 2 +- 2 files changed, 37 insertions(+), 37 deletions(-) diff --git a/regions.scad b/regions.scad index 128636e..91b1cfd 100644 --- a/regions.scad +++ b/regions.scad @@ -152,6 +152,42 @@ 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]); +// Description: +// Splits a path into polyline sections 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. +// region = The region to check for perimeter crossings of. +// closed = If true, treat path as a closed polygon. Default: true +// eps = Acceptable variance. Default: `EPSILON` (1e-9) +// Example(2D): +// path = square(50,center=false); +// region = [circle(d=80), circle(d=40)]; +// polylines = split_path_at_region_crossings(path, region); +// color("#aaa") region(region); +// rainbow(polylines) stroke($item, closed=false, width=2); +function split_path_at_region_crossings(path, region, closed=true, eps=EPSILON) = + let( + path = deduplicate(path, eps=eps), + region = [for (path=region) deduplicate(path, eps=eps)], + xings = region_path_crossings(path, region, closed=closed, eps=eps), + crossings = deduplicate( + concat([[0,0]], xings, [[len(path)-1,1]]), + eps=eps + ), + subpaths = [ + for (p = pair(crossings)) + deduplicate(eps=eps, + path_subselect(path, p[0][0], p[0][1], p[1][0], p[1][1], closed=closed) + ) + ] + ) + subpaths; + + // Section: Offsets and Boolean 2D Geometry @@ -512,42 +548,6 @@ function offset( ) return_faces? [edges,faces] : edges; -// Function: split_path_at_region_crossings() -// Usage: -// polylines = 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 may occur mid-segment, so new vertices will be created at the intersection points. -// Arguments: -// path = The path to split up. -// region = The region to check for perimeter crossings of. -// closed = If true, treat path as a closed polygon. Default: true -// eps = Acceptable variance. Default: `EPSILON` (1e-9) -// Example(2D): -// path = square(50,center=false); -// region = [circle(d=80), circle(d=40)]; -// polylines = split_path_at_region_crossings(path, region); -// color("#aaa") region(region); -// rainbow(polylines) stroke($item, closed=false, width=2); -function split_path_at_region_crossings(path, region, closed=true, eps=EPSILON) = - let( - path = deduplicate(path, eps=eps), - region = [for (path=region) deduplicate(path, eps=eps)], - xings = region_path_crossings(path, region, closed=closed, eps=eps), - crossings = deduplicate( - concat([[0,0]], xings, [[len(path)-1,1]]), - eps=eps - ), - subpaths = [ - for (p = pair(crossings)) - deduplicate(eps=eps, - path_subselect(path, p[0][0], p[0][1], p[1][0], p[1][1], closed=closed) - ) - ] - ) - subpaths; - - function _tag_subpaths(path, region, eps=EPSILON) = let( subpaths = split_path_at_region_crossings(path, region, eps=eps), diff --git a/version.scad b/version.scad index a749aba..90bd9fe 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,111]; +BOSL_VERSION = [2,0,112]; // Section: BOSL Library Version Functions