     func classifyEdges(for graph: PathGraph, isForFirstPath: Bool) {
         func classifyEdge(for node: Node) {
             // TODO: we use a crummy point location
-            let nextEdge = node.component.element(at: 0)
+            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)

            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)
    }
}


        nodes = duplicatesRemoved
    }
    func createComponent(from startingNode: Node) -> PathComponent {
        let firstPoint = startingNode.pathComponent.point(at: startingNode.componentLocation)
        var points: [CGPoint] = [firstPoint]
        var orders: [Int] = []
        func visit(from node: Node) -> Node? {
            if let next = node.next {
                let forwardEdge = node.edge
                if forwardEdge.inSolution, forwardEdge.visited == false {
                    let component = node.forwardComponent(to: next)
                    visit(component)
                    forwardEdge.visited = true
                    return next
                }
            } else {
                assert(node.pathComponent.isClosed == false, "expected next node to exist")
            }
            if let previous = node.previous {
                let backwardsEdge = previous.edge
                if backwardsEdge.inSolution, backwardsEdge.visited == false {
                    let component = node.backwardComponent(to: previous)
                    visit(component)
                    backwardsEdge.visited = true
                    return previous
                }
            } else {
                assert(node.pathComponent.isClosed == false, "expected previous node to exist")
            }
            return nil
        }
