Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thatpixguy opened this issue Mar 20, 2014 · 0 comments

Comments

@thatpixguy
Copy link

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}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant