Skip to content

Commit

Permalink
expose findNearestNode methods and findPointOnEdge, as they can be us…
Browse files Browse the repository at this point in the history
…eful being public
  • Loading branch information
maxxfrazer committed Apr 13, 2020
1 parent b88f6b9 commit ada7019
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Sources/Graph3D/Graph3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,20 @@ public class Graph3D: GKGraph {
}


internal func findNearestNode(to position: SIMD3<Float>, between nodes: [RouteVertex]) -> RouteVertex {
public func findNearestNode(to position: SIMD3<Float>, between nodes: [RouteVertex]) -> RouteVertex {
let newNode = RouteVertex(position)
return nodes.reduce(nodes[0]) { (best, next) -> RouteVertex in
return newNode.cost(to: next) < newNode.cost(to: best) ? next : best
}
}

internal func findNearestNode(to position: SIMD3<Float>) -> RouteVertex {
public func findNearestNode(to position: SIMD3<Float>) -> RouteVertex {
return self.findNearestNode(to: position, between: self.vertexNodes)
}


/// Find the closest point on the graph to a given point
internal func findPointOnEdge(from startPoint: SIMD3<Float>) -> (SIMD3<Float>, [RouteVertex]) {
public func findPointOnEdge(from startPoint: SIMD3<Float>) -> (SIMD3<Float>, [RouteVertex]) {
var closestPoint = self.vertexNodes[edges[0][0]].getVectorPos()
var closestDistance = startPoint.distance(to: closestPoint)
var matchingNodes = [self.vertexNodes[edges[0][0]], self.vertexNodes[edges[0][1]]]
Expand Down
8 changes: 4 additions & 4 deletions Sources/Graph3D/RouteVertex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@

import GameplayKit.GKGraph

internal class RouteVertex: GKGraphNode3D {
public class RouteVertex: GKGraphNode3D {
var travelCost: [GKGraphNode: Float] = [:]

var simdPos: SIMD3<Float> {
return SIMD3<Float>(self.position)
}

convenience init(position: [Float]) {
internal convenience init(position: [Float]) {
self.init(point: vector_float3(position))
}

convenience init(_ position: SIMD3<Float>) {
internal convenience init(_ position: SIMD3<Float>) {
self.init(point: vector_float3(position))
}

override init(point: vector_float3) {
internal override init(point: vector_float3) {
super.init(point: point)
}

Expand Down

0 comments on commit ada7019

Please sign in to comment.