public TransportPathfindResult FindShortestPath(TransportPathfindOptions options)
        {
            var optionsInterop = options.ToInterop();

            var pathfindResultInterop = NativeTransportApi_FindShortestPath(NativePluginRunner.API, ref optionsInterop);

            if (pathfindResultInterop.IsPathFound)
            {
                // alloc and pin buffers
                var pathDirectedEdgeIdsBuffer         = new TransportDirectedEdgeIdInterop[pathfindResultInterop.PathDirectedEdgesSize];
                var pathDirectedEdgeIdsBufferGCHandle = GCHandle.Alloc(pathDirectedEdgeIdsBuffer, GCHandleType.Pinned);
                pathfindResultInterop.PathDirectedEdges = pathDirectedEdgeIdsBufferGCHandle.AddrOfPinnedObject();

                var pathPointsBuffer         = new DoubleVector3[pathfindResultInterop.PathPointsSize];
                var pathPointsBufferGCHandle = GCHandle.Alloc(pathPointsBuffer, GCHandleType.Pinned);
                pathfindResultInterop.PathPoints = pathPointsBufferGCHandle.AddrOfPinnedObject();

                var pathPointParamsBuffer         = new double[pathfindResultInterop.PathPointsSize];
                var pathPointParamsBufferGCHandle = GCHandle.Alloc(pathPointParamsBuffer, GCHandleType.Pinned);
                pathfindResultInterop.PathPointParams = pathPointParamsBufferGCHandle.AddrOfPinnedObject();

                var result = PopulateAndReleaseTransportPathfindResult(pathDirectedEdgeIdsBuffer, pathPointsBuffer, pathPointParamsBuffer, ref pathfindResultInterop);

                pathDirectedEdgeIdsBufferGCHandle.Free();
                pathPointsBufferGCHandle.Free();
                pathPointParamsBufferGCHandle.Free();

                return(result);
            }
            else
            {
                var failedResult = new TransportPathfindResult();
                return(failedResult);
            }
        }
예제 #2
0
 /// <summary>
 /// Find the shortest path, if any, between two points on a transport network as specified in options.
 /// Note that the shortest path from point A to point B is not necessarily the reverse of the shortest
 /// path from point B to point A, as some TransportWays may only be traversed in one direction.
 /// The method considers the currently streamed-in set of the transport network only. As such, it
 /// is provided primarily as a convenience for connecting relatively nearby points for visualization
 /// purposes - it is not intended to be useful for large-scale route planning.
 /// </summary>
 /// <param name="options">A TransportPathfindOptions object that provides input parameters.
 /// TransportPathfindOptionsBuilder may be used to help construct an appropriate options object.</param>
 /// <returns>A result object, indicating whether a path was found, and providing the path if successful.</returns>
 public TransportPathfindResult FindShortestPath(TransportPathfindOptions options)
 {
     return(m_apiInternal.FindShortestPath(options));
 }