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);
            }
        }
        private TransportPathfindResult PopulateAndReleaseTransportPathfindResult(
            TransportDirectedEdgeIdInterop[] pathDirectedEdgeIdsBuffer,
            DoubleVector3[] pathPointsBuffer,
            double[] pathPointParamsBuffer,
            ref TransportPathfindResultInterop pathfindResultInterop
            )
        {
            var success = NativeTransportApi_TryPopulateAndReleaseTransportPathfindResult(NativePluginRunner.API, ref pathfindResultInterop);

            if (!success)
            {
                return(new TransportPathfindResult());
            }
            var pathDirectedEdgeIds = new List <TransportDirectedEdgeId>();

            for (int i = 0; i < pathfindResultInterop.PathDirectedEdgesSize; ++i)
            {
                var directedEdgeId = pathDirectedEdgeIdsBuffer[i].FromInterop();
                pathDirectedEdgeIds.Add(directedEdgeId);
            }

            var pathPoints      = pathPointsBuffer.ToList();
            var pathPointParams = pathPointParamsBuffer.ToList();

            var result = new TransportPathfindResult(
                pathfindResultInterop.IsPathFound,
                pathDirectedEdgeIds.AsReadOnly(),
                pathfindResultInterop.FirstEdgeParam,
                pathfindResultInterop.LastEdgeParam,
                pathfindResultInterop.DistanceMeters,
                pathPoints.AsReadOnly(),
                pathPointParams.AsReadOnly()
                );

            return(result);
        }
 /// <summary>
 /// Get the center-line direction at a parameterized distance along the path represented by a given TransportPathfindResult.
 /// </summary>
 /// <param name="transportApi">TransportApi instance.</param>
 /// <param name="pathfindResult">Pathfind result, as returned by TransportApi.FindShortestPath.</param>
 /// <param name="t">A parameterized distance along the path, in the range 0.0 to 1.0.</param>
 /// <returns>A unit direction vector in ECEF coordinates.</returns>
 static public DoubleVector3 GetDirectionEcefOnPath(this TransportApi transportApi, TransportPathfindResult pathfindResult, double t)
 {
     return(transportApi.GetDirectionEcefOnPolyline(pathfindResult.PathPoints.ToArray(), pathfindResult.PathPointParams.ToArray(), t));
 }