| | | 1 | | namespace Itinero.Profiles; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// An 'EdgeFactor' contains the essential information to perform route planning, such as speed and priority in forward |
| | | 5 | | /// </summary> |
| | | 6 | | public readonly struct EdgeFactor |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Creates a new edge factor. |
| | | 10 | | /// </summary> |
| | | 11 | | /// <param name="forwardFactor">The forward factor.</param> |
| | | 12 | | /// <param name="backwardFactor">The backward factor.</param> |
| | | 13 | | /// <param name="forwardSpeed">The forward speed in ms/s multiplied by 100.</param> |
| | | 14 | | /// <param name="backwardSpeed">The backward speed in ms/s multiplied by 100.</param> |
| | | 15 | | /// <param name="canStop">The can stop.</param> |
| | | 16 | | public EdgeFactor(uint forwardFactor, uint backwardFactor, |
| | | 17 | | ushort forwardSpeed, ushort backwardSpeed, bool canStop = true) |
| | 408 | 18 | | { |
| | 408 | 19 | | this.ForwardFactor = forwardFactor; |
| | 408 | 20 | | this.BackwardFactor = backwardFactor; |
| | 408 | 21 | | this.ForwardSpeed = forwardSpeed; |
| | 408 | 22 | | this.BackwardSpeed = backwardSpeed; |
| | 408 | 23 | | this.CanStop = canStop; |
| | 408 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// Gets the forward factor, multiplied by an edge distance this is the weight. |
| | | 28 | | /// </summary> |
| | 288 | 29 | | public uint ForwardFactor { get; } |
| | | 30 | | |
| | | 31 | | /// <summary> |
| | | 32 | | /// Gets the backward factor, multiplied by an edge distance this is the weight. |
| | | 33 | | /// </summary> |
| | 226 | 34 | | public uint BackwardFactor { get; } |
| | | 35 | | |
| | | 36 | | /// <summary> |
| | | 37 | | /// Gets the backward speed in m/s multiplied by 100. |
| | | 38 | | /// </summary> |
| | 117 | 39 | | public ushort BackwardSpeed { get; } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets the backward speed in m/s. |
| | | 43 | | /// </summary> |
| | 0 | 44 | | public double BackwardSpeedMeterPerSecond => this.BackwardSpeed / 100.0; |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// Gets the forward speed in ms/s multiplied by 100. |
| | | 48 | | /// </summary> |
| | 147 | 49 | | public ushort ForwardSpeed { get; } |
| | | 50 | | |
| | | 51 | | /// <summary> |
| | | 52 | | /// Gets the backward speed in m/s. |
| | | 53 | | /// </summary> |
| | 30 | 54 | | public double ForwardSpeedMeterPerSecond => this.ForwardSpeed / 100.0; |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets the can stop flag. |
| | | 58 | | /// </summary> |
| | 385 | 59 | | public bool CanStop { get; } |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Gets a static no-factor. |
| | | 63 | | /// </summary> |
| | 0 | 64 | | public static EdgeFactor NoFactor => new(0, 0, 0, 0); |
| | | 65 | | |
| | | 66 | | /// <summary> |
| | | 67 | | /// Gets the exact reverse, switches backward and forward. |
| | | 68 | | /// </summary> |
| | 117 | 69 | | public EdgeFactor Reverse => new(this.BackwardFactor, this.ForwardFactor, this.BackwardSpeed, this.ForwardSpeed, thi |
| | | 70 | | |
| | | 71 | | /// <inheritdoc/> |
| | | 72 | | public override string ToString() |
| | 0 | 73 | | { |
| | 0 | 74 | | var forwardSpeed = this.ForwardSpeed / 100.0 * 3.6; |
| | 0 | 75 | | if (this.ForwardFactor == this.BackwardFactor && |
| | 0 | 76 | | this.ForwardSpeed == this.BackwardSpeed) |
| | 0 | 77 | | { |
| | 0 | 78 | | return $"{this.ForwardFactor:F1}({forwardSpeed:F1}km/h)"; |
| | | 79 | | } |
| | | 80 | | |
| | 0 | 81 | | var backwardSpeed = this.BackwardSpeed / 100.0 * 3.6; |
| | 0 | 82 | | return $"F:{this.ForwardFactor:F1}({forwardSpeed:F1}km/h) B:{this.BackwardFactor:F1}({backwardSpeed:F1}km/h)"; |
| | 0 | 83 | | } |
| | | 84 | | |
| | | 85 | | public override int GetHashCode() |
| | 0 | 86 | | { |
| | 0 | 87 | | return (int)(this.ForwardFactor ^ (this.ForwardSpeed << 8) ^ (this.BackwardFactor << 16) ^ (this.ForwardSpeed << |
| | 0 | 88 | | } |
| | | 89 | | } |