Revert "Merge remote-tracking branch 'upstream/master'"

This reverts commit fd2c073bb2, reversing
changes made to d4c7fab7ed.
This commit is contained in:
RonaldoCMP 2021-04-05 15:59:54 +01:00
parent 407c36a8ae
commit 2c03b19246
12 changed files with 53 additions and 115 deletions

View file

@ -142,59 +142,18 @@ function last(list) =
list[len(list)-1];
// Function: list_head()
// Function: delete_last()
// Usage:
// list = list_head(list,<to>);
// list = delete_last(list);
// Topics: List Handling
// See Also: select(), slice(), list_tail(), last()
// See Also: select(), slice(), subindex(), last()
// Description:
// Returns the head of the given list, from the first item up until the `to` index, inclusive.
// If the `to` index is negative, then the length of the list is added to it, such that
// `-1` is the last list item. `-2` is the second from last. `-3` is third from last, etc.
// If the list is shorter than the given index, then the full list is returned.
// 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"]
function list_head(list, to=-2) =
// Returns a list with all but the last entry from the input list. If input is empty, returns empty list.
// Example:
// nlist = delete_last(["foo", "bar", "baz"]); // Returns: ["foo", "bar"]
function delete_last(list) =
assert(is_list(list))
assert(is_finite(to))
to<0? [for (i=[0:1:len(list)+to]) list[i]] :
to<len(list)? [for (i=[0:1:to]) list[i]] :
list;
// Function: list_tail()
// Usage:
// list = list_tail(list,<from>);
// Topics: List Handling
// See Also: select(), slice(), list_tail(), last()
// Description:
// Returns the tail of the given list, from the `from` index up until the end of the list, inclusive.
// If the `from` index is negative, then the length of the list is added to it, such that
// `-1` is the last list item. `-2` is the second from last. `-3` is third from last, etc.
// If you want it to return the last three items of the list, use `from=-3`.
// 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: []
function list_tail(list, from=1) =
assert(is_list(list))
assert(is_finite(from))
from>=0? [for (i=[from:1:len(list)-1]) list[i]] :
let(from = from + len(list))
from>=0? [for (i=[from:1:len(list)-1]) list[i]] :
list;
list==[] ? [] : slice(list,0,-2);
// Function: force_list()

View file

@ -574,7 +574,7 @@ function bezier_line_intersection(curve, line) =
// p2 = [30, 30];
// trace_path([p0,p1,p2], showpts=true, size=0.5, color="green");
// fbez = fillet3pts(p0,p1,p2, 10);
// trace_bezier(select(fbez,1,-2), size=1);
// 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(
r = get_radius(r=r,d=d),
v0 = unit(p0-p1),
@ -942,7 +942,7 @@ module bezier_polygon(bezier, splinesteps=16, N=3) {
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_path(bezier, splinesteps, N);
polygon(points=polypoints);
polygon(points=slice(polypoints, 0, -1));
}

View file

@ -294,9 +294,9 @@ module distribute(spacing=undef, sizes=undef, dir=RIGHT, l=undef)
spc = !is_undef(l)? ((l - sum(gaps)) / ($children-1)) : default(spacing, 10);
gaps2 = [for (gap = gaps) gap+spc];
spos = dir * -sum(gaps2)/2;
spacings = cumsum([0, each gaps2]);
for (i=[0:1:$children-1]) {
$pos = spos + spacings[i] * dir;
totspc = sum(concat([0], slice(gaps2, 0, i)));
$pos = spos + totspc * dir;
$idx = i;
translate($pos) children(i);
}
@ -339,9 +339,9 @@ module xdistribute(spacing=10, sizes=undef, l=undef)
spc = !is_undef(l)? ((l - sum(gaps)) / ($children-1)) : default(spacing, 10);
gaps2 = [for (gap = gaps) gap+spc];
spos = dir * -sum(gaps2)/2;
spacings = cumsum([0, each gaps2]);
for (i=[0:1:$children-1]) {
$pos = spos + spacings[i] * dir;
totspc = sum(concat([0], slice(gaps2, 0, i)));
$pos = spos + totspc * dir;
$idx = i;
translate($pos) children(i);
}
@ -384,9 +384,9 @@ module ydistribute(spacing=10, sizes=undef, l=undef)
spc = !is_undef(l)? ((l - sum(gaps)) / ($children-1)) : default(spacing, 10);
gaps2 = [for (gap = gaps) gap+spc];
spos = dir * -sum(gaps2)/2;
spacings = cumsum([0, each gaps2]);
for (i=[0:1:$children-1]) {
$pos = spos + spacings[i] * dir;
totspc = sum(concat([0], slice(gaps2, 0, i)));
$pos = spos + totspc * dir;
$idx = i;
translate($pos) children(i);
}
@ -429,9 +429,9 @@ module zdistribute(spacing=10, sizes=undef, l=undef)
spc = !is_undef(l)? ((l - sum(gaps)) / ($children-1)) : default(spacing, 10);
gaps2 = [for (gap = gaps) gap+spc];
spos = dir * -sum(gaps2)/2;
spacings = cumsum([0, each gaps2]);
for (i=[0:1:$children-1]) {
$pos = spos + spacings[i] * dir;
totspc = sum(concat([0], slice(gaps2, 0, i)));
$pos = spos + totspc * dir;
$idx = i;
translate($pos) children(i);
}

View file

@ -544,8 +544,9 @@ function _lcm(a,b) =
// Computes lcm for a list of values
function _lcmlist(a) =
len(a)==1 ? a[0] :
_lcmlist(concat(lcm(a[0],a[1]),list_tail(a,2)));
len(a)==1
? a[0]
: _lcmlist(concat(slice(a,0,len(a)-2),[lcm(a[len(a)-2],a[len(a)-1])]));
// Function: lcm()

View file

@ -878,14 +878,14 @@ function assemble_a_path_from_fragments(fragments, rightmost=true, startfrag=0,
let(
// Found fragment intersects with initial path
hitidx = select(hits,-1),
newpath = list_head(path,hitidx),
newpath = slice(path,0,hitidx+1),
newfrags = concat(len(newpath)>1? [newpath] : [], remainder),
outpath = concat(slice(path,hitidx,-2), foundfrag)
)
[outpath, newfrags]
) : let(
// Path still incomplete. Continue building it.
newpath = concat(path, list_tail(foundfrag)),
newpath = concat(path, slice(foundfrag, 1, -1)),
newfrags = concat([newpath], remainder)
)
assemble_a_path_from_fragments(
@ -1244,7 +1244,7 @@ module path_spread(path, n, spacing, sp=undef, rotate_children=true, closed=fals
list_range(s=sp, step=spacing, e=length)
) : is_def(n) && is_undef(spacing)? (
closed?
let(range=list_range(s=0,e=length, n=n+1)) list_head(range) :
let(range=list_range(s=0,e=length, n=n+1)) slice(range,0,-2) :
list_range(s=0, e=length, n=n)
) : (
let(
@ -1426,14 +1426,14 @@ function path_cut(path,cutdist,closed) =
cuts = len(cutlist)
)
[
[ each list_head(path,cutlist[0][1]-1),
[ each slice(path,0,cutlist[0][1]),
if (!approx(cutlist[0][0], path[cutlist[0][1]-1])) cutlist[0][0]
],
for(i=[0:1:cuts-2])
cutlist[i][0]==cutlist[i+1][0] ? []
:
[ if (!approx(cutlist[i][0], select(path,cutlist[i][1]))) cutlist[i][0],
each slice(path, cutlist[i][1], cutlist[i+1][1]),
each slice(path,cutlist[i][1], cutlist[i+1][1]),
if (!approx(cutlist[i+1][0], select(path,cutlist[i+1][1]-1))) cutlist[i+1][0],
],
[

View file

@ -699,8 +699,7 @@ function regular_polyhedron_info(
face_normals,
radius_scale*entry[in_radius]
] :
// info == "vnf" ? [move(translation,p=scaled_points), stellate ? faces : face_triangles] :
info == "vnf" ? [move(translation,p=scaled_points), faces] :
info == "vnf" ? [move(translation,p=scaled_points), stellate ? faces : face_triangles] :
info == "vertices" ? move(translation,p=scaled_points) :
info == "faces" ? faces :
info == "face normals" ? face_normals :

View file

@ -88,7 +88,7 @@ function check_and_fix_path(path, valid_dim=undef, closed=false, name="path") =
is_list(valid_dim) ? str("one of ",valid_dim) : valid_dim
)
)
closed && approx(path[0], last(path))? list_head(path) : path;
closed && approx(path[0],select(path,-1))? slice(path,0,-2) : path;
// Function: cleanup_region()

View file

@ -413,7 +413,7 @@ function _rounding_offsets(edgespec,z_dir=1) =
assert(argsOK,str("Invalid specification with type ",edgetype))
let(
offsets =
edgetype == "profile"? scale([-1,z_dir], p=list_tail(points)) :
edgetype == "profile"? scale([-1,z_dir], p=slice(points,1,-1)) :
edgetype == "chamfer"? chamf_width==0 && chamf_height==0? [] : [[-chamf_width,z_dir*abs(chamf_height)]] :
edgetype == "teardrop"? (
radius==0? [] : concat(

View file

@ -533,7 +533,7 @@ module dashed_stroke(path, dashpat=[3,3], width=1, closed=false) {
function arc(N, r, angle, d, cp, points, width, thickness, start, wedge=false, long=false, cw=false, ccw=false, endpoint=true) =
assert(is_bool(endpoint))
!endpoint ? assert(!wedge, "endpoint cannot be false if wedge is true")
list_head(arc(N,r,angle,d,cp,points,width,thickness,start,wedge,long,cw,ccw,true)) :
slice(arc(N,r,angle,d,cp,points,width,thickness,start,wedge,long,cw,ccw,true),0,-2) :
assert(is_undef(N) || is_integer(N), "Number of points must be an integer")
// First try for 2D arc specified by width and thickness
is_def(width) && is_def(thickness)? (
@ -851,7 +851,7 @@ function _turtle_command(command, parm, parm2, state, index) =
)
list_set(
state, [path,step], [
concat(state[path], list_tail(arcpath)),
concat(state[path], slice(arcpath,1,-1)),
rot(lrsign * myangle,p=state[step],planar=true)
]
) :
@ -877,7 +877,7 @@ function _turtle_command(command, parm, parm2, state, index) =
)
list_set(
state, [path,step], [
concat(state[path], list_tail(arcpath)),
concat(state[path], slice(arcpath,1,-1)),
rot(delta_angle,p=state[step],planar=true)
]
) :

View file

@ -27,6 +27,21 @@ module test_select() {
}
test_select();
module test_last() {
list = [1,2,3,4];
assert(last(list)==4);
assert(last([])==undef);
}
test_last();
module test_delete_last() {
list = [1,2,3,4];
assert(delete_last(list) == [1,2,3]);
assert(delete_last([1]) == []);
assert(delete_last([]) == []);
}
test_delete_last();
module test_slice() {
assert(slice([3,4,5,6,7,8,9], 3, 5) == [6,7]);
@ -39,42 +54,6 @@ module test_slice() {
test_slice();
module test_last() {
list = [1,2,3,4];
assert(last(list)==4);
assert(last([])==undef);
}
test_last();
module test_list_head() {
list = [1,2,3,4];
assert_equal(list_head(list), [1,2,3]);
assert_equal(list_head([1]), []);
assert_equal(list_head([]), []);
assert_equal(list_head(list,-3), [1,2]);
assert_equal(list_head(list,1), [1,2]);
assert_equal(list_head(list,2), [1,2,3]);
assert_equal(list_head(list,6), [1,2,3,4]);
assert_equal(list_head(list,-6), []);
}
test_list_head();
module test_list_tail() {
list = [1,2,3,4];
assert_equal(list_tail(list), [2,3,4]);
assert_equal(list_tail([1]), []);
assert_equal(list_tail([]), []);
assert_equal(list_tail(list,-3), [2,3,4]);
assert_equal(list_tail(list,2), [3,4]);
assert_equal(list_tail(list,3), [4]);
assert_equal(list_tail(list,6), []);
assert_equal(list_tail(list,-6), [1,2,3,4]);
}
test_list_tail();
module test_in_list() {
assert(in_list("bar", ["foo", "bar", "baz"]));
assert(!in_list("bee", ["foo", "bar", "baz"]));

View file

@ -540,28 +540,28 @@ function _turtle3d_command(command, parm, parm2, state, index) =
command=="addlength" ? list_set(state, movestep, state[movestep]+parm) :
command=="arcsteps" ? assert(is_int(parm) && parm>0, str("\"",command,"\" requires a postive integer argument at index ",index))
list_set(state, arcsteps, parm) :
command=="roll" ? list_set(state, trlist, concat(list_head(state[trlist]), [lastT*xrot(parm)])):
command=="roll" ? list_set(state, trlist, concat(slice(state[trlist],0,-2), [lastT*xrot(parm)])):
in_list(command,["right","left","up","down"]) ?
list_set(state, trlist, concat(list_head(state[trlist]), [lastT*_turtle3d_rotation(command,default(parm,state[angle]))])):
list_set(state, trlist, concat(slice(state[trlist],0,-2), [lastT*_turtle3d_rotation(command,default(parm,state[angle]))])):
in_list(command,["xrot","yrot","zrot"]) ?
let(
Trot = _rotpart(lastT), // Extract rotational part of lastT
shift = _transpart(lastT) // Translation part of lastT
)
list_set(state, trlist, concat(list_head(state[trlist]),
list_set(state, trlist, concat(slice(state[trlist],0,-2),
[move(shift)*_turtle3d_rotation(command,default(parm,state[angle])) * Trot])):
command=="rot" ?
let(
Trot = _rotpart(lastT), // Extract rotational part of lastT
shift = _transpart(lastT) // Translation part of lastT
)
list_set(state, trlist, concat(list_head(state[trlist]),[move(shift) * parm * Trot])):
list_set(state, trlist, concat(slice(state[trlist],0,-2),[move(shift) * parm * Trot])):
command=="setdir" ?
let(
Trot = _rotpart(lastT),
shift = _transpart(lastT)
)
list_set(state, trlist, concat(list_head(state[trlist]),
list_set(state, trlist, concat(slice(state[trlist],0,-2),
[move(shift)*rot(from=apply(Trot,RIGHT),to=parm) * Trot ])):
in_list(command,["arcleft","arcright","arcup","arcdown"]) ?
assert(is_num(parm),str("\"",command,"\" command requires a numeric radius value at index ",index))

View file

@ -6,7 +6,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,597];
BOSL_VERSION = [2,0,595];
// Section: BOSL Library Version Functions