+//= require "sylvester.js"
+
 $ = jQuery
 
 Renderer = (canvas, handler) ->

        _mouseP = arbor.Point(e.pageX-pos.left, e.pageY-pos.top)
        object = particleSystem.nearest(_mouseP)

        hit = @hitTest(object.node, _mouseP)
        console.log hit

        if hit
          objectHandler.selectedNode(object.node.name)
        else
          # click on an edge?
          sys = particleSystem
          edges = sys.getEdgesFrom(object.node).concat(sys.getEdgesTo(object.node))
          threshold = 10 # pixels
          for edge in edges
            p1 = sys.toScreen edge.source.p
            p2 = sys.toScreen edge.target.p
            if @pointToLineDist(_mouseP, p1, p2) <= threshold
              objectHandler.selectedEdge edge.data._neo_id
              break


    ctx.fillStyle ='red'
    util.drawText(ctx, [edge.data.rel_type], x, y)

  nodeHitTest: (node, point) ->
    p = particleSystem.toScreen(node.p)
    distx = Math.sqrt(Math.pow(point.x - p.x, 2))
    disty = Math.sqrt(Math.pow(point.y - p.y, 2))
