欢迎来到 Connection,一个 Swift 寻路库。它的主要目标是扩展 Apple 的 GameplayKit
框架。
Connection 定义了两个新的泛型类:Node
和 Graph
,它们分别是 GKGraphNode
和 GKGraph
的对应项。
import Connection
// Create nodes.
let nodeA = Node(value: "A")
let nodeB = Node(value: "B")
let nodeC = Node(value: "C")
// Make connections.
nodeA.addConnection(to: nodeB, bidirectional: false, weight: 1)
nodeB.addConnection(to: nodeC, bidirectional: true, weight: 2)
// Create graph.
let graph = Graph([nodeA, nodeB, nodeC])
// Find path.
let shortestAtoCPath = graph.findPath(from: nodeA, to: nodeC)
print(shortestAtoCPath) // ["A", "B", "C"]
您可以在 Tests
文件夹中找到更多示例。
Connection 使用 Swift Package Manager 分发。 要将其安装到项目中,请按照此教程 并使用此仓库 URL:https://github.com/zntfdr/Connection.git
。
Connection 由 Federico Zanetello 构建,作为 Bangkok Metro 的一个组件。
如果您想更深入地了解 iOS 寻路算法,请阅读这篇分为两部分的系列文章
欢迎并鼓励所有用户积极参与项目的持续开发 - 通过修复他们遇到的任何错误,或者通过改进文档中任何发现不足之处。
如果您想进行更改,请打开一个 Pull Request,即使它只包含您计划的更改草案,或者是一个重现问题的测试。
感谢您,希望您喜欢使用 Connection!