From 88314af127b821265ab8d225f07b5fa0c24e4140 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Mon, 17 Jun 2019 00:10:01 -0700 Subject: [PATCH] Moved some paths functions to geometry.scad --- geometry.scad | 92 ++++++++++++++++++++++++++++++++++++++++ paths.scad | 92 ---------------------------------------- scripts/make_all_docs.sh | 2 +- 3 files changed, 93 insertions(+), 93 deletions(-) diff --git a/geometry.scad b/geometry.scad index 6f88649..e8b1e7b 100644 --- a/geometry.scad +++ b/geometry.scad @@ -329,6 +329,98 @@ function in_front_of_plane(plane, point) = // Section: Paths and Polygons +// Function: is_path() +// Usage: +// is_path(x); +// Description: +// Returns true if the given item looks like a path. +function is_path(x) = is_list(x) && is_vector(x.x); + + +// Function: is_closed_path() +// Usage: +// is_closed_path(path, [eps]); +// Description: +// Returns true if the first and last points in the given path are coincident. +function is_closed_path(path, eps=1e-6) = approx(path[0], path[len(path)-1], eps=eps); + + +// Function: close_path(path) +// Usage: +// close_path(path); +// Description: +// If a path's last point does not coincide with its first point, closes the path so it does. +function close_path(path) = approx(path[0],path[len(path)-1])? path : concat(path,[path[0]]); + + +// Function path_subselect() +// Usage: +// path_subselect(path,s1,u1,s2,u2): +// Description: +// Returns a portion of a path, from between the `u1` part of segment `s1`, to the `u2` part of +// segment `s2`. Both `u1` and `u2` are values between 0.0 and 1.0, inclusive, where 0 is the start +// of the segment, and 1 is the end. Both `s1` and `s2` are integers, where 0 is the first segment. +// Arguments: +// s1 = The number of the starting segment. +// u1 = The proportion along the starting segment, between 0.0 and 1.0, inclusive. +// s2 = The number of the ending segment. +// u2 = The proportion along the ending segment, between 0.0 and 1.0, inclusive. +function path_subselect(path,s1,u1,s2,u2) = + let( + l = len(path)-1, + u1 = s1<0? 0 : s1>l? 1 : u1, + u2 = s2<0? 0 : s2>l? 1 : u2, + s1 = constrain(s1,0,l), + s2 = constrain(s2,0,l), + pathout = concat( + (s1 // Section: Functions -// Function: is_path() -// Usage: -// is_path(x); -// Description: -// Returns true if the given item looks like a path. -function is_path(x) = is_list(x) && is_vector(x.x); - - -// Function: is_closed_path() -// Usage: -// is_closed_path(path, [eps]); -// Description: -// Returns true if the first and last points in the given path are coincident. -function is_closed_path(path, eps=1e-6) = approx(path[0], path[len(path)-1], eps=eps); - - -// Function: close_path(path) -// Usage: -// close_path(path); -// Description: -// If a path's last point does not coincide with its first point, closes the path so it does. -function close_path(path) = approx(path[0],path[len(path)-1])? path : concat(path,[path[0]]); - - // Function: simplify2d_path() // Description: // Takes a 2D polyline and removes unnecessary collinear points. @@ -75,74 +51,6 @@ function path_length(path) = sum([for (i = [0:1:len(path)-2]) norm(path[i+1]-path[i])]); -// Function path_subselect() -// Usage: -// path_subselect(path,s1,u1,s2,u2): -// Description: -// Returns a portion of a path, from between the `u1` part of segment `s1`, to the `u2` part of -// segment `s2`. Both `u1` and `u2` are values between 0.0 and 1.0, inclusive, where 0 is the start -// of the segment, and 1 is the end. Both `s1` and `s2` are integers, where 0 is the first segment. -// Arguments: -// s1 = The number of the starting segment. -// u1 = The proportion along the starting segment, between 0.0 and 1.0, inclusive. -// s2 = The number of the ending segment. -// u2 = The proportion along the ending segment, between 0.0 and 1.0, inclusive. -function path_subselect(path,s1,u1,s2,u2) = - let( - l = len(path)-1, - u1 = s1<0? 0 : s1>l? 1 : u1, - u2 = s2<0? 0 : s2>l? 1 : u2, - s1 = constrain(s1,0,l), - s2 = constrain(s2,0,l), - pathout = concat( - (s1