| | 1 | | using System.Linq; |
| | 2 | | using System.Threading; |
| | 3 | | using System.Threading.Tasks; |
| | 4 | | using Itinero.Routes; |
| | 5 | | using Itinero.Routes.Paths; |
| | 6 | |
|
| | 7 | | namespace Itinero.Routing; |
| | 8 | |
|
| | 9 | | /// <summary> |
| | 10 | | /// One to one extensions. |
| | 11 | | /// </summary> |
| | 12 | | public static class IRouterOneToOneExtensions |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Calculates the path. |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="oneToOneRouter">The router.</param> |
| | 18 | | /// <param name="cancellationToken"></param> |
| | 19 | | /// <returns>The path.</returns> |
| | 20 | | public static async Task<Result<Path>> PathAsync(this IRouterOneToOne oneToOneRouter, CancellationToken cancellation |
| 7 | 21 | | { |
| 7 | 22 | | var sources = new[] { oneToOneRouter.Source }; |
| 7 | 23 | | var targets = new[] { oneToOneRouter.Target }; |
| | 24 | |
|
| 7 | 25 | | if (!sources.TryToUndirected(out var sourcesUndirected) || |
| 7 | 26 | | !targets.TryToUndirected(out var targetsUndirected)) |
| 0 | 27 | | { |
| 0 | 28 | | return (await oneToOneRouter.CalculateAsync(sources, targets)).First().First(); |
| | 29 | | } |
| | 30 | |
|
| 7 | 31 | | return (await oneToOneRouter.CalculateAsync(sourcesUndirected, targetsUndirected, cancellationToken)).First().Fi |
| 7 | 32 | | } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Calculates the route. |
| | 36 | | /// </summary> |
| | 37 | | /// <param name="oneToOneRouter">The router.</param> |
| | 38 | | /// <param name="cancellationToken"></param> |
| | 39 | | /// <returns>The route.</returns> |
| | 40 | | public static async Task<Result<Route>> CalculateAsync(this IRouterOneToOne oneToOneRouter, CancellationToken cancel |
| 7 | 41 | | { |
| 7 | 42 | | var path = await oneToOneRouter.PathAsync(cancellationToken); |
| 7 | 43 | | if (path.IsError) |
| 0 | 44 | | { |
| 0 | 45 | | return new Result<Route>(path.ErrorMessage); |
| | 46 | | } |
| 7 | 47 | | return oneToOneRouter.Settings.RouteBuilder.Build(oneToOneRouter.Network, oneToOneRouter.Settings.Profile, path. |
| 7 | 48 | | } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Calculates the weights. |
| | 52 | | /// </summary> |
| | 53 | | /// <param name="oneToOneWeightRouter">The router.</param> |
| | 54 | | /// <returns>The weight</returns> |
| | 55 | | public static Task<Result<double?>> CalculateAsync(this IRouterWeights<IRouterOneToOne> oneToOneWeightRouter) |
| 0 | 56 | | { |
| 0 | 57 | | return Task.FromResult(new Result<double?>("Not implemented")); |
| | 58 | |
|
| | 59 | | // var profileHandler = oneToOneWeightRouter.Router.Network.GetCostFunctionFor( |
| | 60 | | // oneToOneWeightRouter.Router.Settings.Profile); |
| | 61 | | // return oneToOneWeightRouter.Router.Path().Weight(profileHandler.GetForwardWeight); |
| 0 | 62 | | } |
| | 63 | | } |