             self.addNeighbor($0)
         }
     }
-    var component: PathComponent {
-        var end = self.next!.componentLocation
-        if end == self.pathComponent.startingIndexedLocation {
-            end = self.pathComponent.endingIndexedLocation
-        }
-        return self.pathComponent.split(from: self.componentLocation, to: end)
-    }
-    var backComponent: PathComponent {
-        var end = self.next!.componentLocation
-        if self.componentLocation == self.pathComponent.startingIndexedLocation {
-            return self.pathComponent.split(from: self.pathComponent.endingIndexedLocation, to: end)
-        }
-        return self.pathComponent.split(from: self.componentLocation, to: end)
+    func forwardComponent(to node: Node) -> PathComponent {
+        var nextLocation = node.componentLocation
+        if nextLocation == self.pathComponent.startingIndexedLocation {
+            nextLocation = self.pathComponent.endingIndexedLocation
+        }
+        return self.pathComponent.split(from: self.componentLocation, to: nextLocation)
+    }
+    func backwardComponent(to node: Node) -> PathComponent {
+        var startingLocation = self.componentLocation
+        if startingLocation == self.pathComponent.startingIndexedLocation {
+            startingLocation = self.pathComponent.endingIndexedLocation
+        }
+        return self.pathComponent.split(from: startingLocation, to: node.componentLocation)
     }
 }
 

        func drawGraph(_ graph: PathGraph) {
            for i in 0..<graph.components.count {
                graph.components[i].forEachNode { node, _ in
                    switch node.edge.inSolution {
                    case true:
                        Draw.setColor(context, color: Draw.red)
                    case false:
                        Draw.setColor(context, color: Draw.green)
                    }
                    for curve in node.component.curves {
                        Draw.drawCurve(context, curve: curve)
                    }
                }

    func classifyEdges(for graph: PathGraph, isForFirstPath: Bool) {
        func classifyEdge(for node: Node) {
            // TODO: we use a crummy point location
            guard let nextNode = node.next else { return }
            let component = node.forwardComponent(to: nextNode)
            let nextEdge = component.element(at: 0)
            let point = nextEdge.compute(0.5)
            let normal = nextEdge.normal(0.5)
            let smallDistance = CGFloat(Utils.epsilon)
