       .concat(@front?.allPolygons() or [])
       .concat(@back?.allPolygons() or [])
 
-  invert: =>
+  invert: => returning this, =>
     for poly in @polygons
       do poly.invert
     for flipper in [@divider, @front, @back]
       flipper?.invert()
     [@front, @back] = [@back, @front]
-    @
 
   clipPolygons: (polygons) =>
     return polygons.slice() unless @divider

        f.push v
        b.push v

    polys = []
    polys.push new ThreeBSP.Polygon(f) if f.length >= 3
    polys.push new ThreeBSP.Polygon(b) if b.length >= 3
    polys

  subdivide: (polygon, coplanar_front, coplanar_back, front, back) =>
    for poly in @tessellate polygon

##
## ThreeBSP.Node
class ThreeBSP.Node
  clone: => returning (node = new ThreeBSP.Node()), =>
    node.divider  = @divider?.clone()
    node.polygons = (p.clone() for p in @polygons)
    node.front    = @front?.clone()
    node.back     = @back?.clone()

  constructor: (polygons) ->
    @polygons = []
    @build(polygons) if polygons? and polygons.length

  build: (polygons) => returning this, =>
    sides = front: [], back: []
    @divider ?= polygons[0].clone()
    for poly in polygons
