< Summary

Class:Itinero.Instructions.Types.Generators.TurnGenerator
Assembly:Itinero.Instructions
File(s):/home/runner/work/routing2/routing2/src/Itinero.Instructions/Types/Generators/TurnGenerator.cs
Covered lines:27
Uncovered lines:9
Coverable lines:36
Total lines:69
Line coverage:75% (27 of 36)
Covered branches:10
Total branches:14
Branch coverage:71.4% (10 of 14)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Name()100%1100%
Generate(...)71.42%1474.28%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.Instructions/Types/Generators/TurnGenerator.cs

#LineLine coverage
 1using System;
 2
 3namespace Itinero.Instructions.Types.Generators;
 4
 5internal class TurnGenerator : IInstructionGenerator
 6{
 97    public string Name { get; } = "turn";
 8
 9    public BaseInstruction? Generate(IndexedRoute route, int offset)
 710    {
 711        if (offset == 0 || offset == route.Last)
 212        {
 13            // We never have a bend at first or as last...
 214            return null;
 15        }
 16        // Okay folks!
 17        // We will be walking forward - as long as we are turning in one direction, it is fine!
 18
 19
 520        var angleDiff = route.DirectionChangeAt(offset);
 521        var angleSign = Math.Sign(angleDiff);
 522        var usedShapes = 1;
 23
 524        var totalDistance = route.DistanceToNextPoint(offset);
 25        // We walk forward and detect a true gentle bend:
 526        while (offset + usedShapes < route.Last)
 227        {
 228            var distance = route.DistanceToNextPoint(offset + usedShapes);
 229            if (distance > 5)
 230            {
 31                // a sharp bend must have pieces that are short
 232                break;
 33            }
 34
 035            var dAngle = route.DirectionChangeAt(offset + usedShapes);
 036            if (Math.Sign(route.DirectionChangeAt(offset + usedShapes)) != angleSign)
 037            {
 38                // A turn should only go in the same direction as the first angle
 39                // Here, it doesn't have that...
 040                break;
 41            }
 42
 043            totalDistance += distance;
 044            angleDiff += dAngle;
 45            // We keep the total angle too; as it might turn more then 180°
 46            // We do NOT normalize the angle
 047            usedShapes++;
 048        }
 49
 50
 51        // A turn does turn, at least a few degrees per meter
 552        if (Math.Abs(angleDiff) < 45)
 253        {
 54            // There is little change - does it at least turn a bit?
 255            if (Math.Abs(angleDiff) / totalDistance < 2.5)
 256            {
 57                // Nope, we turn only 2.5° per meter - that isn't a lot
 258                return null;
 59            }
 060        }
 61
 362        return new TurnInstruction(
 363            route,
 364            offset,
 365            offset + usedShapes - 1,
 366            angleDiff
 367        );
 768    }
 69}

Methods/Properties

get_Name()
Generate(...)