     if @merging?
       @merging.x = pos.x
       @merging.y = pos.y
+
     return
 
   collection_dropdown_menu: huffman_collection_dropdown_menu

    for n in @contains
      n.forAll(fn)
    fn(this)

  tryAll: (fn) ->
    for n in @contains

  constructor: (shape) ->
    super shape

  defaultBBoxAt: (pos) ->
    min: (x: pos.x - default_node_radius*2, y: pos.y - default_node_radius*2)
    len: (x: default_node_radius*4, y: default_node_radius*4)

  copyNodesFrom: (nc) ->
    @nodes = [
      new ShannonFanoNode(nc.nodes, @shape, @defaultBBoxAt((x:100,y:100)), "") ]

  render: (ctx, idx, t) ->
    if @splitting?
      ctx.save()
      setStyle(ctx, light_link_style)
      ctx.beginPath()
      ctx.moveTo(@splitting.node.x, @splitting.node.y)
      ctx.lineTo(@splitting.pos0.x, @splitting.pos0.y)
      ctx.moveTo(@splitting.node.x, @splitting.node.y)
      ctx.lineTo(@splitting.pos1.x, @splitting.pos1.y)

      ctx.stroke()
      ctx.restore()

    super ctx, idx, t

  collection_dropdown_menu: shannon_fano_dropdown_menu

  mousedown: (pos, idx, t) ->
    if @splitting?
      hit_another = false
      for n in @nodes
        if n.isHit(pos)
          hit_another = true
          break

      if not hit_another
        @splitNode(@splitting.node, @splitting.pos0, @splitting.pos1)
        @splitting = null
        return true

      @splitting = null

    super pos, idx, t
  
  mousemove: (pos) ->
    super pos

    if @splitting?
      @splitting.pos0 = (x: pos.x, y: pos.y)
      @splitting.pos1 = (x: 2*@splitting.node.x - pos.x, y: pos.y)

    return

  mouseup: (pos, t) ->
    retval = super(pos,t)
    for n in @nodes
      if n.update?
        n.update()

    return retval

  clickend: (pos, t) ->
    if @selected.node in @nodes
      @splitting = node: @selected.node, pos0: pos, pos1: pos
    else
      super pos, t

  splitNode: (node, pos0, pos1) ->
    new0 = new ShannonFanoNode(node.contains, @shape, @defaultBBoxAt(pos0), 0)
    new1 = new ShannonFanoNode([], @shape, @defaultBBoxAt(pos1), 1)

    newnode = new Inner(node.value, new0, new1, @shape)

    new0.move(pos0.x, pos0.y)
    newnode.x = node.x
    newnode.y = node.y
    @replaceNode(node, newnode)

  replaceNode: (oldnode, newnode) ->
    # replace in any inner node
    replaceFn = (node) ->
      if node.child0 == oldnode
        node.child0 = newnode
      if node.child1 == oldnode
        node.child1 = newnode

    for n in @nodes
      n.forAll(replaceFn)

    # replace a root
    @nodes = for n in @nodes
      if n is oldnode
        newnode
      else
        n

    return
 
lerp2d = (t, p0, p1) ->
  if t < 0
