| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | |
|
| | 4 | | namespace Itinero.Profiles; |
| | 5 | |
|
| | 6 | | /// <summary> |
| | 7 | | /// A default profile where all factors are '1'. |
| | 8 | | /// </summary> |
| | 9 | | public sealed class DefaultProfile : Profile |
| | 10 | | { |
| | 11 | | private readonly Func<IEnumerable<(string key, string value)>, EdgeFactor>? _getEdgeFactor; |
| | 12 | | private readonly Func<IEnumerable<(string key, string value)>, TurnCostFactor>? _getTurnCostFactor; |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// Creates a new default profile. |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="name">The name.</param> |
| | 18 | | /// <param name="getEdgeFactor">A customizable function to get edge factors.</param> |
| | 19 | | /// <param name="getTurnCostFactor">A customizable function to get turn cost factors.</param> |
| 45 | 20 | | public DefaultProfile(string name = "Default", |
| 45 | 21 | | Func<IEnumerable<(string key, string value)>, EdgeFactor>? getEdgeFactor = null, |
| 45 | 22 | | Func<IEnumerable<(string key, string value)>, TurnCostFactor>? getTurnCostFactor = null) |
| 45 | 23 | | { |
| 45 | 24 | | this.Name = name; |
| 45 | 25 | | _getEdgeFactor = getEdgeFactor; |
| 45 | 26 | | _getTurnCostFactor = getTurnCostFactor; |
| 45 | 27 | | } |
| | 28 | |
|
| | 29 | | /// <inheritdoc/> |
| 98 | 30 | | public override string Name { get; } |
| | 31 | |
|
| | 32 | | /// <inheritdoc/> |
| | 33 | | public override EdgeFactor Factor(IEnumerable<(string key, string value)> attributes) |
| 217 | 34 | | { |
| 217 | 35 | | return _getEdgeFactor?.Invoke(attributes) ?? new EdgeFactor(1, 1, 1, 1); |
| 217 | 36 | | } |
| | 37 | |
|
| | 38 | | /// <inheritdoc/> |
| | 39 | | public override TurnCostFactor TurnCostFactor(IEnumerable<(string key, string value)> attributes) |
| 4 | 40 | | { |
| 4 | 41 | | return _getTurnCostFactor?.Invoke(attributes) ?? Profiles.TurnCostFactor.Empty; |
| 4 | 42 | | } |
| | 43 | | } |