 
         sidePoints = sidePoints.filter(notUsed)
 
-        paLine = new Line2D(max.point, dividingLine.a)
-        paIsLeft = paLine.isPointOnTheLeftSide(projectedMaxPoint)
-        paPoints = sidePoints.filter((p) -> paLine.isPointOnTheLeftSide(p) != paIsLeft)
-
-        pbLine = new Line2D(max.point, dividingLine.b)
-        pbIsLeft = pbLine.isPointOnTheLeftSide(projectedMaxPoint)
-        pbPoints = sidePoints.filter((p) -> pbLine.isPointOnTheLeftSide(p) == paIsLeft)
+        paLine = new Line2D(dividingLine.a, max.point)
+        paPoints = sidePoints.filter((p) -> paLine.isPointOnTheLeftSide(p) == left)
+
+        pbLine = new Line2D(dividingLine.b, max.point)
+        pbPoints = sidePoints.filter((p) -> pbLine.isPointOnTheLeftSide(p) == !left)
 
         resultA = quickHullStep(paPoints, edgePoints, paLine, dividingEdgeA, depth + 1)
         resultB = quickHullStep(pbPoints, edgePoints, pbLine, dividingEdgeB, depth + 1)

    edgePoints.push(points[minX])
    edgePoints.push(points[maxX])
    dividingEdge = new Edge(points[minX], points[maxX])
    edges.push(dividingEdge)

    quickHullStep = (points, edgePoints, dividingLine, dividingEdge, depth) ->
      leftPoints = points.filter(isLeft(dividingLine))

        if idx > -1
          edges.splice(idx, 1)


      increasedSides

    result = quickHullStep(points.filter(notUsed), edgePoints, dividingLine, dividingEdge, 0)
    #if result == 2
    #  if dividingEdge != null
    #    idx = edges.indexOf(dividingEdge)
    #    if idx > -1
    #      edges.splice(idx, 1)

    #ordering edges
    for i in [0..edges.length-1] by 1
