Skip to content

Commit f96e521

Browse files
bugfix for rot_copies: sa parameter was ignored
1 parent 7c737fd commit f96e521

1 file changed

Lines changed: 23 additions & 11 deletions

File tree

distributors.scad

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ function grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero, p=_
814814
// n = Optional number of evenly distributed copies, rotated around the axis.
815815
// sa = Starting angle, in degrees. For use with `n`. Angle is in degrees counter-clockwise. Default: 0
816816
// delta = [X,Y,Z] amount to move away from cp before rotating. Makes rings of copies. Default: `[0,0,0]`
817-
// subrot = If false, don't sub-rotate children as they are copied around the ring. Only makes sense when used with `delta`. Default: `true`
817+
// subrot = If false, don't sub-rotate children as they are copied around the ring. Instead maintain their native orientation. The false setting is only allowed when `delta` is given. Default: `true`
818818
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
819819
//
820820
// Side Effects:
@@ -852,26 +852,23 @@ function grid_copies(spacing, n, size, stagger=false, inside=undef, nonzero, p=_
852852
// yrot(90) cylinder(h=20, r1=5, r2=0);
853853
// color("red",0.333) yrot(90) cylinder(h=20, r1=5, r2=0);
854854
module rot_copies(rots=[], v, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], subrot=true)
855-
{ echo("hi");
855+
{
856+
assert(subrot || norm(delta)>0, "subrot can only be false if delta is not zero");
856857
req_children($children);
857858
sang = sa + offset;
858-
echo(sang=sang);
859859
angs = !is_undef(n)?
860860
(n<=0? [] : [for (i=[0:1:n-1]) i/n*360+sang]) :
861861
rots==[]? [] :
862862
assert(!is_string(rots), "Argument rots must be an angle, a list of angles, or a range of angles.")
863863
assert(!is_undef(rots[0]), "Argument rots must be an angle, a list of angles, or a range of angles.")
864864
[for (a=rots) a];
865-
echo(angs=angs);
866-
echo(subrot=subrot);
867865
for ($idx = idx(angs)) {
868866
$ang = angs[$idx];
869867
$axis = v;
870868
translate(cp) {
871-
echo(rotang=$ang);
872869
rotate(a=$ang, v=v) {
873-
translate(delta) { echo(sang=sang);
874-
rot(a=(subrot? sang : $ang), v=v, reverse=true) {
870+
translate(delta) {
871+
rot(a=subrot? 0 : $ang, v=v, reverse=true) {
875872
translate(-cp) {
876873
children();
877874
}
@@ -884,6 +881,7 @@ module rot_copies(rots=[], v, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], subr
884881

885882

886883
function rot_copies(rots=[], v, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], subrot=true, p=_NO_ARG) =
884+
assert(subrot || norm(delta)>0, "subrot can only be false if delta is not zero")
887885
let(
888886
sang = sa + offset,
889887
angs = !is_undef(n)?
@@ -897,7 +895,7 @@ function rot_copies(rots=[], v, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], su
897895
translate(cp) *
898896
rot(a=ang, v=v) *
899897
translate(delta) *
900-
rot(a=(subrot? sang : ang), v=v, reverse=true) *
898+
rot(a=subrot? 0 : ang, v=v, reverse=true) *
901899
translate(-cp)
902900
]
903901
)
@@ -939,6 +937,7 @@ function rot_copies(rots=[], v, cp=[0,0,0], n, sa=0, offset=0, delta=[0,0,0], su
939937
// sa = Starting angle, in degrees. For use with `n`. Angle is in degrees counter-clockwise from Y+, when facing the origin from X+. First unrotated copy is placed at that angle.
940938
// r = If given, makes a ring of child copies around the X axis, at the given radius. Default: 0
941939
// d = If given, makes a ring of child copies around the X axis, at the given diameter.
940+
// subrot = If false, don't sub-rotate children as they are copied around the ring. Instead maintain their native orientation. The false setting is only allowed when `d` or `r` is given. Default: `true`
942941
// subrot = If false, don't sub-rotate children as they are copied around the ring.
943942
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
944943
//
@@ -976,12 +975,16 @@ module xrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true)
976975
{
977976
req_children($children);
978977
r = get_radius(r=r, d=d, dflt=0);
978+
assert(all_nonnegative([r]), "d/r must be nonnegative");
979+
assert(subrot || r>0, "subrot can only be false if d or r is given");
979980
rot_copies(rots=rots, v=RIGHT, cp=cp, n=n, sa=sa, delta=[0, r, 0], subrot=subrot) children();
980981
}
981982

982983

983984
function xrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true, p=_NO_ARG) =
984985
let( r = get_radius(r=r, d=d, dflt=0) )
986+
assert(all_nonnegative([r]), "d/r must be nonnegative")
987+
assert(subrot || r>0, "subrot can only be false if d or r is given")
985988
rot_copies(rots=rots, v=RIGHT, cp=cp, n=n, sa=sa, delta=[0, r, 0], subrot=subrot, p=p);
986989

987990

@@ -1020,7 +1023,7 @@ function xrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true, p=_NO_ARG)
10201023
// sa = Starting angle, in degrees. For use with `n`. Angle is in degrees counter-clockwise from X-, when facing the origin from Y+.
10211024
// r = If given, makes a ring of child copies around the Y axis, at the given radius. Default: 0
10221025
// d = If given, makes a ring of child copies around the Y axis, at the given diameter.
1023-
// subrot = If false, don't sub-rotate children as they are copied around the ring.
1026+
// subrot = If false, don't sub-rotate children as they are copied around the ring. Instead maintain their native orientation. The false setting is only allowed when `d` or `r` is given. Default: `true`
10241027
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
10251028
//
10261029
// Side Effects:
@@ -1057,12 +1060,16 @@ module yrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true)
10571060
{
10581061
req_children($children);
10591062
r = get_radius(r=r, d=d, dflt=0);
1063+
assert(all_nonnegative([r]), "d/r must be nonnegative");
1064+
assert(subrot || r>0, "subrot can only be false if d or r is given");
10601065
rot_copies(rots=rots, v=BACK, cp=cp, n=n, sa=sa, delta=[-r, 0, 0], subrot=subrot) children();
10611066
}
10621067

10631068

10641069
function yrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true, p=_NO_ARG) =
10651070
let( r = get_radius(r=r, d=d, dflt=0) )
1071+
assert(all_nonnegative([r]), "d/r must be nonnegative")
1072+
assert(subrot || r>0, "subrot can only be false if d or r is given")
10661073
rot_copies(rots=rots, v=BACK, cp=cp, n=n, sa=sa, delta=[-r, 0, 0], subrot=subrot, p=p);
10671074

10681075

@@ -1102,7 +1109,7 @@ function yrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true, p=_NO_ARG)
11021109
// sa = Starting angle, in degrees. For use with `n`. Angle is in degrees counter-clockwise from X+, when facing the origin from Z+. Default: 0
11031110
// r = If given, makes a ring of child copies around the Z axis, at the given radius. Default: 0
11041111
// d = If given, makes a ring of child copies around the Z axis, at the given diameter.
1105-
// subrot = If false, don't sub-rotate children as they are copied around the ring. Default: true
1112+
// subrot = If false, don't sub-rotate children as they are copied around the ring. Instead maintain their native orientation. The false setting is only allowed when `d` or `r` is given. Default: `true`
11061113
// p = Either a point, pointlist, VNF or Bezier patch to be translated when used as a function.
11071114
//
11081115
// Side Effects:
@@ -1137,13 +1144,18 @@ function yrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true, p=_NO_ARG)
11371144
// color("red",0.333) yrot(-90) cylinder(h=20, r1=5, r2=0, center=true);
11381145
module zrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true)
11391146
{
1147+
req_children($children);
11401148
r = get_radius(r=r, d=d, dflt=0);
1149+
assert(all_nonnegative([r]), "d/r must be nonnegative");
1150+
assert(subrot || r>0, "subrot can only be false if d or r is given");
11411151
rot_copies(rots=rots, v=UP, cp=cp, n=n, sa=sa, delta=[r, 0, 0], subrot=subrot) children();
11421152
}
11431153

11441154

11451155
function zrot_copies(rots=[], cp=[0,0,0], n, sa=0, r, d, subrot=true, p=_NO_ARG) =
11461156
let( r = get_radius(r=r, d=d, dflt=0) )
1157+
assert(all_nonnegative([r]), "d/r must be nonnegative")
1158+
assert(subrot || r>0, "subrot can only be false if d or r is given")
11471159
rot_copies(rots=rots, v=UP, cp=cp, n=n, sa=sa, delta=[r, 0, 0], subrot=subrot, p=p);
11481160

11491161

0 commit comments

Comments
 (0)