             let first = endCappedIntersections.first!
             first.previous = last.previous
             last.previous?.next = first
-            first.isIntersection = first.isIntersection || last.isIntersection
+            first.mergeNeighbors(of: last)
             endCappedIntersections.removeLast()
         }
         return endCappedIntersections.first!

    var next: IntersectionNode?
    var previous: IntersectionNode?
    var edge: Edge?
    var isIntersection: Bool
    /// links to locations on neighboring paths, indexed by path number
    var neighbors: [Int: [IntersectionNode]] = [:]
    init(location: IndexedPathLocation, isIntersection: Bool) {
        self.location = location
        self.isIntersection = isIntersection
    }
    func addNeighbor(_ neighbor: IntersectionNode, pathNumber: Int) {
        if neighbors[pathNumber] == nil { neighbors[pathNumber] = [] }
        neighbors[pathNumber]!.append(neighbor)
    }
    func mergeNeighbors(of node: IntersectionNode) {
        // TODO: point the links from node.neighbors.neighbors back to self

        // point the links from self.neighbors to node.neighbors
        for (key, value) in node.neighbors {
            for node in value {
                self.addNeighbor(node, pathNumber: key)
            }
        }
    }
}

    private func createComponent(from node: IntersectionNode) -> PathComponent {
        var points: [CGPoint] = [node.edge!.component.startingPoint]
        var orders = [Int]()
        func visit(from node: IntersectionNode) -> IntersectionNode? {
            guard let forwardEdge = node.edge else {
                assertionFailure("consistency failure")
                return nil
            }
            guard let backwardsEdge = node.previous?.edge else {
                assertionFailure("consistency failure")
                return nil
            }
            if forwardEdge.inSolution, forwardEdge.visited == false {
                visit(forwardEdge.component)
                forwardEdge.visited = true
                return node.next
            } else if backwardsEdge.inSolution, backwardsEdge.visited == false {
                visit(backwardsEdge.component.reversed())
                backwardsEdge.visited = true
                return node.previous
            } else {
                return nil
            }
        }
        func visit(_ component: PathComponent) {
            points += component.points[1..<component.points.count]
            orders += component.orders
        }

        var nextNode: IntersectionNode? = node
        while let currentNode = nextNode {
            nextNode = nil
            if let temp = visit(from: currentNode) {
                nextNode = temp
            } else {
                for neighbor in currentNode.neighbors {
                    if let temp = visit(from: neighbor) {
                        nextNode = temp
                        break
                    }
                }
            }
        }

        if points.last != points.first {
            points.append(points.first!)
            orders.append(1)
        }

        return PathComponent(points: points, orders: orders)
