Fix Examples: -> Example: when there's no render

This commit is contained in:
Adrian Mariano 2021-09-16 19:33:55 -04:00
parent fd0bcc0903
commit e6a2ee2084
8 changed files with 87 additions and 86 deletions

View file

@ -161,12 +161,12 @@ function last(list) =
// Arguments:
// list = The list to get the head of.
// to = The last index to include. If negative, adds the list length to it. ie: -1 is the last list item.
// Examples:
// hlist = list_head(["foo", "bar", "baz"]); // Returns: ["foo", "bar"]
// hlist = list_head(["foo", "bar", "baz"], -3); // Returns: ["foo"]
// hlist = list_head(["foo", "bar", "baz"], 2); // Returns: ["foo","bar"]
// hlist = list_head(["foo", "bar", "baz"], -5); // Returns: []
// hlist = list_head(["foo", "bar", "baz"], 5); // Returns: ["foo","bar","baz"]
// Example:
// hlist1 = list_head(["foo", "bar", "baz"]); // Returns: ["foo", "bar"]
// hlist2 = list_head(["foo", "bar", "baz"], -3); // Returns: ["foo"]
// hlist3 = list_head(["foo", "bar", "baz"], 2); // Returns: ["foo","bar"]
// hlist4 = list_head(["foo", "bar", "baz"], -5); // Returns: []
// hlist5 = list_head(["foo", "bar", "baz"], 5); // Returns: ["foo","bar","baz"]
function list_head(list, to=-2) =
assert(is_list(list))
assert(is_finite(to))
@ -188,12 +188,12 @@ function list_head(list, to=-2) =
// Arguments:
// list = The list to get the tail of.
// from = The first index to include. If negative, adds the list length to it. ie: -1 is the last list item.
// Examples:
// tlist = list_tail(["foo", "bar", "baz"]); // Returns: ["bar", "baz"]
// tlist = list_tail(["foo", "bar", "baz"], -1); // Returns: ["baz"]
// tlist = list_tail(["foo", "bar", "baz"], 2); // Returns: ["baz"]
// tlist = list_tail(["foo", "bar", "baz"], -5); // Returns: ["foo","bar","baz"]
// tlist = list_tail(["foo", "bar", "baz"], 5); // Returns: []
// Example:
// tlist1 = list_tail(["foo", "bar", "baz"]); // Returns: ["bar", "baz"]
// tlist2 = list_tail(["foo", "bar", "baz"], -1); // Returns: ["baz"]
// tlist3 = list_tail(["foo", "bar", "baz"], 2); // Returns: ["baz"]
// tlist4 = list_tail(["foo", "bar", "baz"], -5); // Returns: ["foo","bar","baz"]
// tlist5 = list_tail(["foo", "bar", "baz"], 5); // Returns: []
function list_tail(list, from=1) =
assert(is_list(list))
assert(is_finite(from))
@ -236,7 +236,7 @@ function list(l) = is_list(l)? l : [for (x=l) x];
// value = The value or list to coerce into a list.
// n = The number of items in the coerced list. Default: 1
// fill = The value to pad the coerced list with, after the firt value. Default: undef (pad with copies of `value`)
// Examples:
// Example:
// x = force_list([3,4,5]); // Returns: [3,4,5]
// y = force_list(5); // Returns: [5]
// z = force_list(7, n=3); // Returns: [7,7,7]
@ -509,7 +509,7 @@ function list_rotate(list,n=1) =
// list = The list to deduplicate.
// closed = If true, drops trailing items if they match the first list item.
// eps = The maximum tolerance between items.
// Examples:
// Example:
// a = deduplicate([8,3,4,4,4,8,2,3,3,8,8]); // Returns: [8,3,4,8,2,3,8]
// b = deduplicate(closed=true, [8,3,4,4,4,8,2,3,3,8,8]); // Returns: [8,3,4,8,2,3]
// c = deduplicate("Hello"); // Returns: "Helo"
@ -539,7 +539,7 @@ function deduplicate(list, closed=false, eps=EPSILON) =
// indices = The list of indices to deduplicate.
// closed = If true, drops trailing indices if what they index matches what the first index indexes.
// eps = The maximum difference to allow between numbers or vectors.
// Examples:
// Example:
// a = deduplicate_indexed([8,6,4,6,3], [1,4,3,1,2,2,0,1]); // Returns: [1,4,3,2,0,1]
// b = deduplicate_indexed([8,6,4,6,3], [1,4,3,1,2,2,0,1], closed=true); // Returns: [1,4,3,2,0]
// c = deduplicate_indexed([[7,undef],[7,undef],[1,4],[1,4],[1,4+1e-12]],eps=0); // Returns: [0,2,4]
@ -592,7 +592,7 @@ function deduplicate_indexed(list, indices, closed=false, eps=EPSILON) =
// list = list whose entries will be repeated
// N = scalar total number of points desired or vector requesting N[i] copies of vertex i.
// exact = if true return exactly the requested number of points, possibly sacrificing uniformity. If false, return uniform points that may not match the number of points requested. Default: True
// Examples:
// Example:
// list = [0,1,2,3];
// a = repeat_entries(list, 6); // Returns: [0,0,1,2,2,3]
// b = repeat_entries(list, 6, exact=false); // Returns: [0,0,1,1,2,2,3,3]
@ -629,7 +629,7 @@ function repeat_entries(list, N, exact=true) =
// values = List of values to set.
// dflt = Default value to store in sparse skipped indices.
// minlen = Minimum length to expand list to.
// Examples:
// Example:
// a = list_set([2,3,4,5], 2, 21); // Returns: [2,3,21,5]
// b = list_set([2,3,4,5], [1,3], [81,47]); // Returns: [2,81,4,47]
function list_set(list=[],indices,values,dflt=0,minlen=0) =
@ -1890,7 +1890,7 @@ function _array_dim_recurse(v) =
// Arguments:
// v = Array to get dimensions of.
// depth = Dimension to get size of. If not given, returns a list of dimension lengths.
// Examples:
// Example:
// a = array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]); // Returns [2,2,3]
// b = array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]], 0); // Returns 2
// c = array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]], 2); // Returns 3

View file

@ -18,7 +18,7 @@
// Description:
// Returns a string representing the type of the value. One of "undef", "boolean", "number", "nan", "string", "list", "range", "function" or "invalid".
// Some malformed "ranges", like '[0:NAN:INF]' and '[0:"a":INF]', may be classified as "undef" or "invalid".
// Examples:
// Example:
// typ = typeof(undef); // Returns: "undef"
// typ = typeof(true); // Returns: "boolean"
// typ = typeof(42); // Returns: "number"
@ -294,7 +294,7 @@ function default(v,dflt=undef) = is_undef(v)? dflt : v;
// Arguments:
// v = The list whose items are being checked.
// recursive = If true, sublists are checked recursively for defined values. The first sublist that has a defined item is returned.
// Examples:
// Example:
// val = first_defined([undef,7,undef,true]); // Returns: 7
function first_defined(v,recursive=false,_i=0) =
_i<len(v) && (
@ -321,9 +321,9 @@ function first_defined(v,recursive=false,_i=0) =
// vals = The values to return the first one which is not `undef`.
// names = A string with comma-separated names for the arguments whose values are passed in `vals`.
// dflt = If given, the value returned if all `vals` are `undef`.
// Examples:
// length = one_defined([length,L,l], ["length","L","l"]);
// length = one_defined([length,L,l], "length,L,l", dflt=1);
// Example:
// length1 = one_defined([length,L,l], ["length","L","l"]);
// length2 = one_defined([length,L,l], "length,L,l", dflt=1);
function one_defined(vals, names, dflt=_UNDEF) =
let(
@ -420,13 +420,13 @@ function all_defined(v,recursive=false) =
// center = If not `undef`, this overrides the value of `anchor`.
// uncentered = The value to return if `center` is not `undef` and evaluates as false. Default: ALLNEG
// dflt = The default value to return if both `anchor` and `center` are `undef`. Default: `CENTER`
// Examples:
// anchr = get_anchor(undef, undef, BOTTOM, TOP); // Returns: [0, 0, 1] (TOP)
// anchr = get_anchor(RIGHT, undef, BOTTOM, TOP); // Returns: [1, 0, 0] (RIGHT)
// anchr = get_anchor(undef, false, BOTTOM, TOP); // Returns: [0, 0,-1] (BOTTOM)
// anchr = get_anchor(RIGHT, false, BOTTOM, TOP); // Returns: [0, 0,-1] (BOTTOM)
// anchr = get_anchor(undef, true, BOTTOM, TOP); // Returns: [0, 0, 0] (CENTER)
// anchr = get_anchor(RIGHT, true, BOTTOM, TOP); // Returns: [0, 0, 0] (CENTER)
// Example:
// anchr1 = get_anchor(undef, undef, BOTTOM, TOP); // Returns: [0, 0, 1] (TOP)
// anchr2 = get_anchor(RIGHT, undef, BOTTOM, TOP); // Returns: [1, 0, 0] (RIGHT)
// anchr3 = get_anchor(undef, false, BOTTOM, TOP); // Returns: [0, 0,-1] (BOTTOM)
// anchr4 = get_anchor(RIGHT, false, BOTTOM, TOP); // Returns: [0, 0,-1] (BOTTOM)
// anchr5 = get_anchor(undef, true, BOTTOM, TOP); // Returns: [0, 0, 0] (CENTER)
// anchr6 = get_anchor(RIGHT, true, BOTTOM, TOP); // Returns: [0, 0, 0] (CENTER)
function get_anchor(anchor,center,uncentered=BOT,dflt=CENTER) =
!is_undef(center)? (center? CENTER : uncentered) :
!is_undef(anchor)? anchor :
@ -454,7 +454,7 @@ function get_anchor(anchor,center,uncentered=BOT,dflt=CENTER) =
// d2 = Second most specific diameter.
// d = Most general diameter.
// dflt = Value to return if all other values given are `undef`.
// Examples:
// Example:
// r = get_radius(r1=undef, r=undef, dflt=undef); // Returns: undef
// r = get_radius(r1=undef, r=undef, dflt=1); // Returns: 1
// r = get_radius(r1=undef, r=6, dflt=1); // Returns: 6
@ -495,7 +495,7 @@ function get_radius(r1, r2, r, d1, d2, d, dflt) =
// Arguments:
// v = Value to return vector from.
// dflt = Default value to set empty vector parts from.
// Examples:
// Example:
// vec = scalar_vec3(undef); // Returns: undef
// vec = scalar_vec3(10); // Returns: [10,10,10]
// vec = scalar_vec3(10,1); // Returns: [10,1,1]
@ -514,7 +514,7 @@ function scalar_vec3(v, dflt) =
// Calculate the standard number of sides OpenSCAD would give a circle based on `$fn`, `$fa`, and `$fs`.
// Arguments:
// r = Radius of circle to get the number of segments for.
// Examples:
// Example:
// $fn=12; sides=segs(10); // Returns: 12
// $fa=2; $fs=3, sides=segs(10); // Returns: 21
function segs(r) =

View file

@ -133,7 +133,7 @@ function path4d(points, fill=0) =
// Arguments:
// r = distance from the origin.
// theta = angle in degrees, counter-clockwise of X+.
// Examples:
// Example:
// xy = polar_to_xy(20,45); // Returns: ~[14.1421365, 14.1421365]
// xy = polar_to_xy(40,30); // Returns: ~[34.6410162, 15]
// xy = polar_to_xy([40,30]); // Returns: ~[34.6410162, 15]
@ -162,7 +162,7 @@ function polar_to_xy(r,theta=undef) = let(
// Arguments:
// x = X coordinate.
// y = Y coordinate.
// Examples:
// Example:
// plr = xy_to_polar(20,30);
// plr = xy_to_polar([40,60]);
// Example(2D):
@ -317,7 +317,7 @@ function lift_plane(plane, p) =
// r = distance from the Z axis.
// theta = angle in degrees, counter-clockwise of X+ on the XY plane.
// z = Height above XY plane.
// Examples:
// Example:
// xyz = cylindrical_to_xyz(20,30,40);
// xyz = cylindrical_to_xyz([40,60,50]);
function cylindrical_to_xyz(r,theta=undef,z=undef) = let(
@ -340,7 +340,7 @@ function cylindrical_to_xyz(r,theta=undef,z=undef) = let(
// x = X coordinate.
// y = Y coordinate.
// z = Z coordinate.
// Examples:
// Example:
// cyl = xyz_to_cylindrical(20,30,40);
// cyl = xyz_to_cylindrical([40,50,70]);
function xyz_to_cylindrical(x,y=undef,z=undef) = let(
@ -360,7 +360,7 @@ function xyz_to_cylindrical(x,y=undef,z=undef) = let(
// r = distance from origin.
// theta = angle in degrees, counter-clockwise of X+ on the XY plane.
// phi = angle in degrees from the vertical Z+ axis.
// Examples:
// Example:
// xyz = spherical_to_xyz(20,30,40);
// xyz = spherical_to_xyz([40,60,50]);
function spherical_to_xyz(r,theta=undef,phi=undef) = let(
@ -383,7 +383,7 @@ function spherical_to_xyz(r,theta=undef,phi=undef) = let(
// x = X coordinate.
// y = Y coordinate.
// z = Z coordinate.
// Examples:
// Example:
// sph = xyz_to_spherical(20,30,40);
// sph = xyz_to_spherical([40,50,70]);
function xyz_to_spherical(x,y=undef,z=undef) = let(
@ -404,7 +404,7 @@ function xyz_to_spherical(x,y=undef,z=undef) = let(
// alt = altitude angle in degrees above the XY plane.
// az = azimuth angle in degrees clockwise of Y+ on the XY plane.
// r = distance from origin.
// Examples:
// Example:
// xyz = altaz_to_xyz(20,30,40);
// xyz = altaz_to_xyz([40,60,50]);
function altaz_to_xyz(alt,az=undef,r=undef) = let(
@ -429,7 +429,7 @@ function altaz_to_xyz(alt,az=undef,r=undef) = let(
// x = X coordinate.
// y = Y coordinate.
// z = Z coordinate.
// Examples:
// Example:
// aa = xyz_to_altaz(20,30,40);
// aa = xyz_to_altaz([40,50,70]);
function xyz_to_altaz(x,y=undef,z=undef) = let(

View file

@ -35,7 +35,7 @@ NAN = acos(2);
// If given a number, returns the square of that number,
// If given a vector, returns the sum-of-squares/dot product of the vector elements.
// If given a matrix, returns the matrix multiplication of the matrix with itself.
// Examples:
// Example:
// sqr(3); // Returns: 9
// sqr(-4); // Returns: 16
// sqr([2,3,4]); // Returns: 29
@ -50,7 +50,7 @@ function sqr(x) =
// foo = log2(x);
// Description:
// Returns the logarithm base 2 of the value given.
// Examples:
// Example:
// log2(0.125); // Returns: -3
// log2(16); // Returns: 4
// log2(256); // Returns: 8
@ -187,7 +187,7 @@ function lerp(a,b,u) =
// b = Second value or vector.
// n = The number of values to return.
// endpoint = If true, the last value will be exactly `b`. If false, the last value will be one step less.
// Examples:
// Example:
// l = lerpn(-4,4,9); // Returns: [-4,-3,-2,-1,0,1,2,3,4]
// l = lerpn(-4,4,8,false); // Returns: [-4,-3,-2,-1,0,1,2,3]
// l = lerpn(0,1,6); // Returns: [0, 0.2, 0.4, 0.6, 0.8, 1]
@ -350,7 +350,7 @@ function quant(x,y) =
// Arguments:
// x = The value to quantize.
// y = The non-zero integer quantum of the quantization.
// Examples:
// Example:
// a = quantdn(12,4); // Returns: 12
// b = quantdn(13,4); // Returns: 12
// c = quantdn(13.1,4); // Returns: 12
@ -387,7 +387,7 @@ function quantdn(x,y) =
// Arguments:
// x = The value to quantize.
// y = The non-zero integer quantum of the quantization.
// Examples:
// Example:
// a = quantup(12,4); // Returns: 12
// b = quantup(13,4); // Returns: 16
// c = quantup(13.1,4); // Returns: 16
@ -639,7 +639,7 @@ function _cumsum(v,_i=0,_acc=[]) =
// Arguments:
// a = Angle to get the value for.
// sines = List of [amplitude, frequency, offset] items, where the frequency is the number of times the cycle repeats around the circle.
// Examples:
// Example:
// v = sum_of_sines(30, [[10,3,0], [5,5.5,60]]);
function sum_of_sines(a, sines) =
assert( is_finite(a) && is_matrix(sines,undef,3), "Invalid input.")
@ -1225,7 +1225,7 @@ function all_equal(vec,eps=0) =
// true if every item of the list is an integer. Otherwise, returns false.
// Arguments:
// x = The value to check.
// Examples:
// Example:
// b = all_integer(true); // Returns: false
// b = all_integer("foo"); // Returns: false
// b = all_integer(4); // Returns: true

View file

@ -17,22 +17,22 @@
// All vectors must of the same size, and may only contain numbers that are not inf or nan.
// By default the vectors in a path must be 2d or 3d. Set the `dim` parameter to specify a list
// of allowed dimensions, or set it to `undef` to allow any dimension.
// Examples:
// is_path([[3,4],[5,6]]); // Returns true
// is_path([[3,4]]); // Returns false
// is_path([[3,4],[4,5]],2); // Returns true
// is_path([[3,4,3],[5,4,5]],2); // Returns false
// is_path([[3,4,3],[5,4,5]],2); // Returns false
// is_path([[3,4,5],undef,[4,5,6]]); // Returns false
// is_path([[3,5],[undef,undef],[4,5]]); // Returns false
// is_path([[3,4],[5,6],[5,3]]); // Returns true
// is_path([3,4,5,6,7,8]); // Returns false
// is_path([[3,4],[5,6]], dim=[2,3]);// Returns true
// is_path([[3,4],[5,6]], dim=[1,3]);// Returns false
// is_path([[3,4],"hello"], fast=true); // Returns true
// is_path([[3,4],[3,4,5]]); // Returns false
// is_path([[1,2,3,4],[2,3,4,5]]); // Returns false
// is_path([[1,2,3,4],[2,3,4,5]],undef);// Returns true
// Example:
// bool1 = is_path([[3,4],[5,6]]); // Returns true
// bool2 = is_path([[3,4]]); // Returns false
// bool3 = is_path([[3,4],[4,5]],2); // Returns true
// bool4 = is_path([[3,4,3],[5,4,5]],2); // Returns false
// bool5 = is_path([[3,4,3],[5,4,5]],2); // Returns false
// bool6 = is_path([[3,4,5],undef,[4,5,6]]); // Returns false
// bool7 = is_path([[3,5],[undef,undef],[4,5]]); // Returns false
// bool8 = is_path([[3,4],[5,6],[5,3]]); // Returns true
// bool9 = is_path([3,4,5,6,7,8]); // Returns false
// bool10 = is_path([[3,4],[5,6]], dim=[2,3]);// Returns true
// bool11 = is_path([[3,4],[5,6]], dim=[1,3]);// Returns false
// bool12 = is_path([[3,4],"hello"], fast=true); // Returns true
// bool13 = is_path([[3,4],[3,4,5]]); // Returns false
// bool14 = is_path([[1,2,3,4],[2,3,4,5]]); // Returns false
// bool15 = is_path([[1,2,3,4],[2,3,4,5]],undef);// Returns true
// Arguments:
// list = list to check
// dim = list of allowed dimensions of the vectors in the path. Default: [2,3]

View file

@ -96,7 +96,7 @@ function law_of_sines(a, A, b, B) =
// p1 = The first vertex of the triangle.
// p2 = The second vertex of the triangle.
// p3 = The third vertex of the triangle.
// Examples:
// Example:
// triangle_area([0,0], [5,10], [10,0]); // Returns -50
// triangle_area([10,0], [5,10], [0,0]); // Returns 50
function triangle_area(p1,p2,p3) =

View file

@ -163,13 +163,13 @@ function pointlist_bounds(pts) =
// Arguments:
// v = The vector to normalize.
// error = If given, and input is a zero-length vector, this value is returned. Default: Assert error on zero-length vector.
// Examples:
// unit([10,0,0]); // Returns: [1,0,0]
// unit([0,10,0]); // Returns: [0,1,0]
// unit([0,0,10]); // Returns: [0,0,1]
// unit([0,-10,0]); // Returns: [0,-1,0]
// unit([0,0,0],[1,2,3]); // Returns: [1,2,3]
// unit([0,0,0]); // Asserts an error.
// Example:
// v1 = unit([10,0,0]); // Returns: [1,0,0]
// v2 = unit([0,10,0]); // Returns: [0,1,0]
// v3 = unit([0,0,10]); // Returns: [0,0,1]
// v4 = unit([0,-10,0]); // Returns: [0,-1,0]
// v5 = unit([0,0,0],[1,2,3]); // Returns: [1,2,3]
// v6 = unit([0,0,0]); // Asserts an error.
function unit(v, error=[[["ASSERT"]]]) =
assert(is_vector(v), str("Expected a vector. Got: ",v))
norm(v)<EPSILON? (error==[[["ASSERT"]]]? assert(norm(v)>=EPSILON,"Tried to normalize a zero vector") : error) :
@ -191,13 +191,13 @@ function unit(v, error=[[["ASSERT"]]]) =
// v1 = First vector or point.
// v2 = Second vector or point.
// v3 = Third point in three point mode.
// Examples:
// vector_angle(UP,LEFT); // Returns: 90
// vector_angle(RIGHT,LEFT); // Returns: 180
// vector_angle(UP+RIGHT,RIGHT); // Returns: 45
// vector_angle([10,10], [0,0], [10,-10]); // Returns: 90
// vector_angle([10,0,10], [0,0,0], [-10,10,0]); // Returns: 120
// vector_angle([[10,0,10], [0,0,0], [-10,10,0]]); // Returns: 120
// Example:
// ang1 = vector_angle(UP,LEFT); // Returns: 90
// ang2 = vector_angle(RIGHT,LEFT); // Returns: 180
// ang3 = vector_angle(UP+RIGHT,RIGHT); // Returns: 45
// ang4 = vector_angle([10,10], [0,0], [10,-10]); // Returns: 90
// ang5 = vector_angle([10,0,10], [0,0,0], [-10,10,0]); // Returns: 120
// ang6 = vector_angle([[10,0,10], [0,0,0], [-10,10,0]]); // Returns: 120
function vector_angle(v1,v2,v3) =
assert( ( is_undef(v3) && ( is_undef(v2) || same_shape(v1,v2) ) )
|| is_consistent([v1,v2,v3]) ,
@ -233,13 +233,13 @@ function vector_angle(v1,v2,v3) =
// v1 = First vector or point.
// v2 = Second vector or point.
// v3 = Third point in three point mode.
// Examples:
// vector_axis(UP,LEFT); // Returns: [0,-1,0] (FWD)
// vector_axis(RIGHT,LEFT); // Returns: [0,-1,0] (FWD)
// vector_axis(UP+RIGHT,RIGHT); // Returns: [0,1,0] (BACK)
// vector_axis([10,10], [0,0], [10,-10]); // Returns: [0,0,-1] (DOWN)
// vector_axis([10,0,10], [0,0,0], [-10,10,0]); // Returns: [-0.57735, -0.57735, 0.57735]
// vector_axis([[10,0,10], [0,0,0], [-10,10,0]]); // Returns: [-0.57735, -0.57735, 0.57735]
// Example:
// axis1 = vector_axis(UP,LEFT); // Returns: [0,-1,0] (FWD)
// axis2 = vector_axis(RIGHT,LEFT); // Returns: [0,-1,0] (FWD)
// axis3 = vector_axis(UP+RIGHT,RIGHT); // Returns: [0,1,0] (BACK)
// axis4 = vector_axis([10,10], [0,0], [10,-10]); // Returns: [0,0,-1] (DOWN)
// axis5 = vector_axis([10,0,10], [0,0,0], [-10,10,0]); // Returns: [-0.57735, -0.57735, 0.57735]
// axis6 = vector_axis([[10,0,10], [0,0,0], [-10,10,0]]); // Returns: [-0.57735, -0.57735, 0.57735]
function vector_axis(v1,v2=undef,v3=undef) =
is_vector(v3)
? assert(is_consistent([v3,v2,v1]), "Bad arguments.")

View file

@ -963,6 +963,7 @@ function _split_polygons_at_each_y(polys, ys, _i=0) =
// bad edges and vertices, overlaid on a transparent gray polyhedron of the VNF.
// .
// Currently checks for these problems:
// .
// Type | Color | Code | Message
// ------- | -------- | ------------ | ---------------------------------
// WARNING | Yellow | BIG_FACE | Face has more than 3 vertices, and may confuse CGAL.