< Summary

Class:Itinero.Instructions.Types.Generators.FollowAlongGenerator
Assembly:Itinero.Instructions
File(s):/home/runner/work/routing2/routing2/src/Itinero.Instructions/Types/Generators/FollowAlongGenerator.cs
Covered lines:33
Uncovered lines:8
Coverable lines:41
Total lines:74
Line coverage:80.4% (33 of 41)
Covered branches:11
Total branches:16
Branch coverage:68.7% (11 of 16)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
get_Name()100%1100%
Generate(...)68.75%1680%

File(s)

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

#LineLine coverage
 1using System;
 2using Itinero.Network.Attributes;
 3
 4namespace Itinero.Instructions.Types.Generators;
 5
 6internal class FollowAlongGenerator : IInstructionGenerator
 7{
 88    public string Name { get; } = "followalong";
 9
 10    public BaseInstruction? Generate(IndexedRoute route, int offset)
 411    {
 412        if (offset == 0 || offset == route.Last)
 013        {
 14            // We can have never a follow along as first or as last locations...
 015            return null;
 16        }
 17
 418        var usedShapes = 1;
 419        var totalDistance = route.DistanceToNextPoint(offset);
 420        route.Meta[offset].Attributes.TryGetValue("name", out var name);
 1121        while (offset + usedShapes < route.Last)
 922        {
 923            var dAngle = route.DirectionChangeAt(offset + usedShapes);
 924            if (Math.Abs(dAngle) > 35)
 225            {
 26                // To much turn for a follow along...
 227                break;
 28            }
 29
 730            route.Meta[offset + usedShapes].Attributes.TryGetValue("name", out var newName);
 731            if (name != newName)
 032            {
 33                // Different street!
 034                break;
 35            }
 736            route.Meta[offset + usedShapes].Attributes.TryGetValue("junction", out var junctionType);
 737            if (junctionType == "roundabout")
 038            {
 39                // We cancel on roundabouts, in order to generate a roundabout-instruction for them
 040                break;
 41            }
 42
 43
 744            var distance = route.DistanceToNextPoint(offset + usedShapes);
 745            totalDistance += distance;
 46
 747            usedShapes++;
 748        }
 49        // In degrees. Difference in bearing between start- and end
 450        var totalChange =
 451            (route.ArrivingDirectionAt(offset + usedShapes) - route.ArrivingDirectionAt(offset)).NormalizeDegrees();
 52
 53        // A follow along is not allowed to turn more then 45 degrees in total; otherwise this is a 'followBend'
 454        if (Math.Abs(totalChange) >= 45)
 255        {
 256            return null;
 57        }
 58
 59        // THere is little directional change - does it turn at most a little bit?
 260        if (Math.Abs(totalChange) / totalDistance >= 2.5)
 061        {
 62            // Nope, we turn more then 2.5°/m, this is 'followBend'-material
 063            return null;
 64        }
 65
 66
 267        return new FollowAlongInstruction(
 268            route,
 269            offset,
 270            offset + usedShapes,
 271            totalChange
 272        );
 473    }
 74}

Methods/Properties

get_Name()
Generate(...)