< Summary

Class:Itinero.Instructions.Types.BaseInstruction
Assembly:Itinero.Instructions
File(s):/home/runner/work/routing2/routing2/src/Itinero.Instructions/Types/BaseInstruction.cs
Covered lines:26
Uncovered lines:3
Coverable lines:29
Total lines:97
Line coverage:89.6% (26 of 29)
Covered branches:1
Total branches:2
Branch coverage:50% (1 of 2)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.ctor(...)100%1100%
.ctor(...)100%1100%
get_ShapeIndex()100%1100%
get_ShapeIndexEnd()100%1100%
get_TurnDegrees()100%1100%
get_Type()100%1100%
get_Route()100%1100%
Tp(...)50%2100%
ToString()100%10%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.Instructions/Types/BaseInstruction.cs

#LineLine coverage
 1namespace Itinero.Instructions.Types;
 2
 3/// <summary>
 4///     A base instruction.
 5/// </summary>
 6/// <remarks>
 7///     An instruction is a piece that describes a traveller how they should behave to reach their destination.
 8///     An instruction applies on one or more segments, and contains two parts:
 9///     - The next meters to travel, e.g. 'follow along road XYZ, which has properties P and Q'
 10///     - What to do at the end of the segment, e.g. 'turn left' or even 'follow along then next road'
 11///     An instruction thus can be
 12///     - 'Follow along road XYZ, then turn right'
 13///     - 'Follow road XYZ, then cross street ABC'
 14///     - 'Follow road XYZ, then get onto the roundabout'
 15///     - 'Take the Nth exit of the roundabout, this is ~straight on' (note that this instruction possibly spans multipl
 16///     segments of the roundabout)
 17///     A client which outputs actual text for humans, might even need a little bit more of lookahead in the instruction
 18///     in order to generate stuff as:
 19///     - 'Follow road XYZ, then cross the street into DEF'.
 20///     This is _not_ handled here
 21///     This means we have two things to track:
 22///     - The properties of the road segment we are travelling
 23///     - The next maneuver to make
 24///     Subclasses of Instruction might add additional information, such as 'cross XYZ at the end', 'you are currently
 25///     travelling a roundabout', ...
 26///     Note that we should also consider the multiple presentations of the instructions:
 27///     - Voice instructions, which should be spoken at the right time before the traveller has to make a maneuver
 28///     - Written instructions, on app, which should show the appropriate text at the right time
 29///     - Extra information, e.g. about the street currently travelled, the next street, the upcoming turn, ...
 30/// </remarks>
 31public class BaseInstruction
 32{
 33    /// <summary>
 34    /// Constructs a BaseInstruction. See class definition for documentation
 35    /// </summary>
 36    /// <param name="route"><see cref="Route"/></param>
 37    /// <param name="shapeIndex"><see cref="ShapeIndex"/></param>
 38    /// <param name="shapeIndexEnd"><see cref="ShapeIndexEnd"/></param>
 39    /// <param name="turnDegrees"><see cref="TurnDegrees"/></param>
 5940    public BaseInstruction(IndexedRoute route,
 5941        int shapeIndex, int shapeIndexEnd, int turnDegrees)
 5942    {
 5943        this.Route = route;
 5944        this.ShapeIndex = shapeIndex;
 5945        this.ShapeIndexEnd = shapeIndexEnd;
 5946        this.TurnDegrees = turnDegrees;
 5947        this.Type = Tp(this);
 5948    }
 49
 4450    public BaseInstruction(IndexedRoute route, int shapeIndex, double turnDegrees)
 4451    {
 4452        this.Route = route;
 4453        this.ShapeIndex = shapeIndex;
 4454        this.ShapeIndexEnd = shapeIndex + 1;
 4455        this.TurnDegrees = turnDegrees.NormalizeDegrees();
 4456        this.Type = Tp(this);
 4457    }
 58
 59    /// <summary>
 60    ///     The index of the start of the segment this instruction is applicable on; i.e. the traveller arrived at the s
 61    ///     which starts at 'ShapeIndex', what should they do next?
 62    /// </summary>
 20263    public int ShapeIndex { get; }
 64
 65    /// <summary>
 66    ///     The index where the described instruction stops.
 67    ///     <remarks>
 68    ///         Will often (but not always) be ShapeIndex + 1. The start- and endinstruction have ShapeIndexEnd ==
 69    ///         ShapeIndex; some others describe multiple segments
 70    ///     </remarks>
 71    /// </summary>
 26272    public int ShapeIndexEnd { get; }
 73
 74    /// <summary>
 75    ///     The amount of degrees to turn at the end of the road.
 76    ///     0° is straight on, positive is turning left and negative is turning right
 77    /// </summary>
 20778    public int TurnDegrees { get; }
 79
 80    /// <summary>
 81    ///     Gets the type of instruction.
 82    /// </summary>
 22683    public string Type { get; }
 84
 20585    public IndexedRoute Route { get; }
 86
 87    private static string Tp(object o)
 10388    {
 10389        var tp = o.GetType().Name.ToLower();
 10390        return tp.EndsWith("instruction") ? tp.Substring(0, tp.Length - "instruction".Length) : tp;
 10391    }
 92
 93    public override string ToString()
 094    {
 095        return $"Follow from p{this.ShapeIndex} to p{this.ShapeIndexEnd}, where you turn {this.TurnDegrees}°";
 096    }
 97}