mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-01-16 13:50:23 +01:00
Removed assert_in_list() in favor of assert(in_list())
This commit is contained in:
parent
fa572fc398
commit
302b8c4b2f
@ -848,7 +848,7 @@ function zip(vecs, v2, v3, fit=false, fill=undef) =
|
|||||||
(v3!=undef)? zip([vecs,v2,v3], fit=fit, fill=fill) :
|
(v3!=undef)? zip([vecs,v2,v3], fit=fit, fill=fill) :
|
||||||
(v2!=undef)? zip([vecs,v2], fit=fit, fill=fill) :
|
(v2!=undef)? zip([vecs,v2], fit=fit, fill=fill) :
|
||||||
let(
|
let(
|
||||||
dummy1 = assert_in_list("fit", fit, [false, "short", "long"]),
|
dummy1 = assert(in_list(fit, [false, "short", "long"])),
|
||||||
minlen = list_shortest(vecs),
|
minlen = list_shortest(vecs),
|
||||||
maxlen = list_longest(vecs),
|
maxlen = list_longest(vecs),
|
||||||
dummy2 = (fit==false)? assert(minlen==maxlen, "Input vectors must have the same length") : 0
|
dummy2 = (fit==false)? assert(minlen==maxlen, "Input vectors must have the same length") : 0
|
||||||
|
@ -379,7 +379,7 @@ function bezier_close_to_axis(bezier, N=3, axis="X") =
|
|||||||
[for (i=[1:1:N]) lerp(ep, [0,ep.y], i/N)],
|
[for (i=[1:1:N]) lerp(ep, [0,ep.y], i/N)],
|
||||||
[for (i=[1:1:N]) lerp([0,ep.y], [0,sp.y], i/N)]
|
[for (i=[1:1:N]) lerp([0,ep.y], [0,sp.y], i/N)]
|
||||||
) : (
|
) : (
|
||||||
assert_in_list("axis", axis, ["X","Y"])
|
assert(in_list(axis, ["X","Y"]))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
28
errors.scad
28
errors.scad
@ -12,34 +12,6 @@
|
|||||||
// Section: Warnings and Errors
|
// Section: Warnings and Errors
|
||||||
|
|
||||||
|
|
||||||
// Function&Module: assert_in_list()
|
|
||||||
// Usage:
|
|
||||||
// assert_in_list(argname, val, l, [idx]);
|
|
||||||
// Description:
|
|
||||||
// Emulates the newer OpenSCAD `assert()` with an `in_list()` test.
|
|
||||||
// You can also use this as a function call from a function.
|
|
||||||
// Arguments:
|
|
||||||
// argname = The name of the argument value being tested.
|
|
||||||
// val = The value to test if it exists in the list.
|
|
||||||
// l = The list to look for `val` in.
|
|
||||||
// idx = If given, and `l` is a list of lists, look for `val` in the given index of each sublist.
|
|
||||||
module assert_in_list(argname, val, l, idx=undef) {
|
|
||||||
dummy = assert_in_list(argname, val, l, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
function assert_in_list(argname, val, l, idx=undef) =
|
|
||||||
let(succ = search([val], l, num_returns_per_match=1, index_col_num=idx) != [[]])
|
|
||||||
succ? 0 : let(
|
|
||||||
msg = str(
|
|
||||||
"In argument '", argname, "', ",
|
|
||||||
(is_string(val)? str("\"", val, "\"") : val),
|
|
||||||
" must be one of ",
|
|
||||||
(!is_undef(idx)? [for (v=l) v[idx]] : l)
|
|
||||||
),
|
|
||||||
FAILED=succ
|
|
||||||
) assert(FAILED, msg);
|
|
||||||
|
|
||||||
|
|
||||||
// Module: no_children()
|
// Module: no_children()
|
||||||
// Usage:
|
// Usage:
|
||||||
// no_children($children);
|
// no_children($children);
|
||||||
|
@ -35,7 +35,7 @@ function _partition_cutpath(l, h, cutsize, cutpath, gap) =
|
|||||||
cutpath = is_path(cutpath)? cutpath : (
|
cutpath = is_path(cutpath)? cutpath : (
|
||||||
assert(is_string(cutpath), "cutpath must be a 2D path or a string.")
|
assert(is_string(cutpath), "cutpath must be a 2D path or a string.")
|
||||||
let(idx = search([cutpath], _partition_cutpaths))
|
let(idx = search([cutpath], _partition_cutpaths))
|
||||||
idx==[[]]? assert_in_list("cutpath",cutpath,_partition_cutpaths,idx=0) :
|
idx==[[]]? assert(in_list(cutpath,_partition_cutpaths,idx=0)) :
|
||||||
_partition_cutpaths[idx.x][1]
|
_partition_cutpaths[idx.x][1]
|
||||||
),
|
),
|
||||||
reps = ceil(l/(cutsize.x+gap)),
|
reps = ceil(l/(cutsize.x+gap)),
|
||||||
|
@ -1209,7 +1209,7 @@ module zdistribute(spacing=10, sizes=undef, l=undef)
|
|||||||
// }
|
// }
|
||||||
module grid2d(size=undef, spacing=undef, cols=undef, rows=undef, stagger=false, scale=[1,1,1], in_poly=undef, anchor=CENTER, spin=0, orient=UP)
|
module grid2d(size=undef, spacing=undef, cols=undef, rows=undef, stagger=false, scale=[1,1,1], in_poly=undef, anchor=CENTER, spin=0, orient=UP)
|
||||||
{
|
{
|
||||||
assert_in_list("stagger", stagger, [false, true, "alt"]);
|
assert(in_list(stagger, [false, true, "alt"]));
|
||||||
scl = vmul(scalar_vec3(scale, 1), (stagger!=false? [0.5, sin(60), 1] : [1,1,1]));
|
scl = vmul(scalar_vec3(scale, 1), (stagger!=false? [0.5, sin(60), 1] : [1,1,1]));
|
||||||
if (!is_undef(size)) {
|
if (!is_undef(size)) {
|
||||||
siz = scalar_vec3(size);
|
siz = scalar_vec3(size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user