CoffeeSCad icon indicating copy to clipboard operation
CoffeeSCad copied to clipboard

The last comprehension in this function gets a parse error in coffeescad but it works on coffescript.org

Open thatpixguy opened this issue 10 years ago • 0 comments

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:

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}))

thatpixguy avatar Mar 20 '14 22:03 thatpixguy