mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
add $idx to grid_copies
This commit is contained in:
parent
869888c7ec
commit
077ec7402f
1 changed files with 39 additions and 36 deletions
|
@ -587,6 +587,7 @@ function line_copies(spacing, n, l, p1, p2, p=_NO_ARG) =
|
||||||
// `$pos` is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
|
// `$pos` is set to the relative centerpoint of each child copy, and can be used to modify each child individually.
|
||||||
// `$col` is set to the integer column number for each child.
|
// `$col` is set to the integer column number for each child.
|
||||||
// `$row` is set to the integer row number for each child.
|
// `$row` is set to the integer row number for each child.
|
||||||
|
// `$idx` is set to a unique index for each child, progressing across rows first, from the bottom
|
||||||
//
|
//
|
||||||
// Examples:
|
// Examples:
|
||||||
// grid_copies(size=50, spacing=10) cylinder(d=10, h=1);
|
// grid_copies(size=50, spacing=10) cylinder(d=10, h=1);
|
||||||
|
@ -654,46 +655,48 @@ module grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero)
|
||||||
size!=undef && spacing!=undef? v_floor(v_div(size,spacing))+[1,1] :
|
size!=undef && spacing!=undef? v_floor(v_div(size,spacing))+[1,1] :
|
||||||
[2,2];
|
[2,2];
|
||||||
offset = v_mul(spacing, n-[1,1])/2;
|
offset = v_mul(spacing, n-[1,1])/2;
|
||||||
if (stagger == false) {
|
|
||||||
for (row = [0:1:n.y-1]) {
|
poslist =
|
||||||
for (col = [0:1:n.x-1]) {
|
stagger==false ?
|
||||||
pos = v_mul([col,row],spacing) - offset;
|
[for (row = [0:1:n.y-1], col = [0:1:n.x-1])
|
||||||
if (
|
let(
|
||||||
is_undef(inside) ||
|
pos = v_mul([col,row],spacing) - offset
|
||||||
(is_path(inside) && point_in_polygon(pos, inside, nonzero=nonzero)>=0) ||
|
)
|
||||||
(is_region(inside) && point_in_region(pos, inside)>=0)
|
if (
|
||||||
) {
|
is_undef(inside) ||
|
||||||
$col = col;
|
(is_path(inside) && point_in_polygon(pos, inside, nonzero=nonzero)>=0) ||
|
||||||
$row = row;
|
(is_region(inside) && point_in_region(pos, inside)>=0)
|
||||||
$pos = pos;
|
)
|
||||||
translate(pos) children();
|
[pos,row,col]
|
||||||
}
|
]
|
||||||
}
|
:
|
||||||
}
|
let( // stagger == true or stagger == "alt"
|
||||||
} else {
|
staggermod = (stagger == "alt")? 1 : 0,
|
||||||
// stagger == true or stagger == "alt"
|
cols1 = ceil(n.x/2),
|
||||||
staggermod = (stagger == "alt")? 1 : 0;
|
cols2 = n.x - cols1
|
||||||
cols1 = ceil(n.x/2);
|
)
|
||||||
cols2 = n.x - cols1;
|
[for (row = [0:1:n.y-1])
|
||||||
for (row = [0:1:n.y-1]) {
|
let(
|
||||||
rowcols = ((row%2) == staggermod)? cols1 : cols2;
|
rowcols = ((row%2) == staggermod)? cols1 : cols2
|
||||||
if (rowcols > 0) {
|
)
|
||||||
for (col = [0:1:rowcols-1]) {
|
if (rowcols > 0)
|
||||||
rowdx = (row%2 != staggermod)? spacing.x : 0;
|
for (col = [0:1:rowcols-1])
|
||||||
pos = v_mul([2*col,row],spacing) + [rowdx,0] - offset;
|
let(
|
||||||
|
rowdx = (row%2 != staggermod)? spacing.x : 0,
|
||||||
|
pos = v_mul([2*col,row],spacing) + [rowdx,0] - offset
|
||||||
|
)
|
||||||
if (
|
if (
|
||||||
is_undef(inside) ||
|
is_undef(inside) ||
|
||||||
(is_path(inside) && point_in_polygon(pos, inside, nonzero=nonzero)>=0) ||
|
(is_path(inside) && point_in_polygon(pos, inside, nonzero=nonzero)>=0) ||
|
||||||
(is_region(inside) && point_in_region(pos, inside)>=0)
|
(is_region(inside) && point_in_region(pos, inside)>=0)
|
||||||
) {
|
)
|
||||||
$col = col * 2 + ((row%2!=staggermod)? 1 : 0);
|
[pos, row, col * 2 + ((row%2!=staggermod)? 1 : 0)]
|
||||||
$row = row;
|
];
|
||||||
$pos = pos;
|
for(i=idx(poslist)){
|
||||||
translate(pos) children();
|
$idx=i;
|
||||||
}
|
$row=poslist[i][1];
|
||||||
}
|
$col=poslist[i][2];
|
||||||
}
|
translate(poslist[i][0])children();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue