         _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
+        if @nodeHitTest(object.node, _mouseP)
           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
+            if (@edgeHitTest(edge, _mouseP, 20))
               objectHandler.selectedEdge edge.data._neo_id
               break
 


    Math.abs((x2-x1)*(y1-y0)-(x1-x0)*(y2-y1)) / Math.sqrt(Math.pow(x2-x1,2) + Math.pow(y2-y1,2))

  initMouseHandling: ->

    handler =

//= require "sylvester.js"

$ = jQuery

Renderer = (canvas, handler) ->
