You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been messing around with how to make a function that generates a cube with rounded edges... This function gets an error (can't read property 'length' of undefined). But if I put the same code in to coffeescript.org with some stub classes, it compiles fine.
roundCube = ({size,r,$fn}) ->
innerSize = (n-(2*r) for n in size)
offset = [r,r,r]
union(
(for axis in [0,1,2]
newSize = innerSize[..]
newSize[axis] = size[axis]
newOffset = offset[..]
newOffset[axis] = 0
(new Cube({size:newSize})).translate(newOffset)
).concat(
for z in [r,size[2]-r]
for y in [r, size[1]-r]
(new Cylinder({r:r,h:innerSize[0],$fn:$fn})).rotate([0,90,0]).translate([r,y,z])
).concat(
for y in [r,size[1]-r]
for x in [r, size[0]-r]
(new Cylinder({r:r,h:innerSize[2],$fn:$fn})).translate([x,y,r])
).concat(
for z in [r,size[2]-r]
for x in [r, size[0]-r]
(new Cylinder({r:r,h:innerSize[1],$fn:$fn})).rotate([-90,0,0]).translate([x,r,z])
).concat(
for z in [r,size[2]-r]
for y in [r,size[1]-r]
for x in [r,size[0]-r]
(new Sphere({r:r,$fn:$fn})).translate([x,y,z])
)
)
assembly.add(roundCube({size:[8,3,10],r:1,$fn:12}))
The error goes away if you remove the last concat which adds the corner spheres:
roundCube = ({size,r,$fn}) ->
innerSize = (n-(2*r) for n in size)
offset = [r,r,r]
union(
(for axis in [0,1,2]
newSize = innerSize[..]
newSize[axis] = size[axis]
newOffset = offset[..]
newOffset[axis] = 0
(new Cube({size:newSize})).translate(newOffset)
).concat(
for z in [r,size[2]-r]
for y in [r, size[1]-r]
(new Cylinder({r:r,h:innerSize[0],$fn:$fn})).rotate([0,90,0]).translate([r,y,z])
).concat(
for y in [r,size[1]-r]
for x in [r, size[0]-r]
(new Cylinder({r:r,h:innerSize[2],$fn:$fn})).translate([x,y,r])
).concat(
for z in [r,size[2]-r]
for x in [r, size[0]-r]
(new Cylinder({r:r,h:innerSize[1],$fn:$fn})).rotate([-90,0,0]).translate([x,r,z])
)
)
assembly.add(roundCube({size:[8,3,10],r:1,$fn:12}))
The text was updated successfully, but these errors were encountered:
I've been messing around with how to make a function that generates a cube with rounded edges... This function gets an error (can't read property 'length' of undefined). But if I put the same code in to coffeescript.org with some stub classes, it compiles fine.
Here is a link to the stubbed code on coffeescript.org
and here is my coffeescad code:
The error goes away if you remove the last
concat
which adds the corner spheres:The text was updated successfully, but these errors were encountered: