< Summary

Class:Itinero.IO.Osm.Restrictions.Barriers.OsmBarrierExtensions
Assembly:Itinero.IO.Osm
File(s):/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/Restrictions/Barriers/OsmBarrierExtensions.cs
Covered lines:35
Uncovered lines:0
Coverable lines:35
Total lines:65
Line coverage:100% (35 of 35)
Covered branches:20
Total branches:20
Branch coverage:100% (20 of 20)
Tag:263_26948838820

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToGlobalNetworkRestrictions()80%10100%
GetTailHops()100%14100%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.IO.Osm/Restrictions/Barriers/OsmBarrierExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Itinero.Network.Tiles.Standalone.Global;
 5
 6namespace Itinero.IO.Osm.Restrictions.Barriers;
 7
 8/// <summary>
 9/// Extension methods for OsmBarrier.
 10/// </summary>
 11public static class OsmBarrierExtensions
 12{
 13    /// <summary>
 14    /// Converts the given barrier into two or more global network restrictions.
 15    /// </summary>
 16    /// <param name="osmBarrier">The OSM barrier.</param>
 17    /// <returns>The restrictions using network edges and vertices.</returns>
 18    public static IEnumerable<GlobalRestriction> ToGlobalNetworkRestrictions(
 19        this OsmBarrier osmBarrier)
 240120    {
 859021        var attributes = osmBarrier.Node.Tags?.Select(tag => (tag.Key, tag.Value)).ToArray() ??
 240122                         ArraySegment<(string key, string value)>.Empty;
 23
 1634124        foreach (var tailHop in osmBarrier.GetTailHops())
 3235325            foreach (var otherHop in osmBarrier.GetTailHops())
 932326            {
 1389227                if (tailHop == otherHop) continue;
 28
 475429                var headHop = otherHop.GetInverted();
 30
 475431                yield return new GlobalRestriction([tailHop, headHop], true, attributes);
 475432            }
 240133    }
 34
 35    private static IEnumerable<GlobalEdgeId> GetTailHops(
 36        this OsmBarrier osmBarrier)
 697037    {
 697038        var node = osmBarrier.Node.Id!.Value;
 39
 4275440        foreach (var fromWay in osmBarrier.Ways)
 1092241        {
 1092242            var previous = 0;
 10820243            for (var n = 1; n < fromWay.Nodes.Length; n++)
 4317944            {
 4317945                var current = fromWay.Nodes[n];
 7938146                if (current != node) continue;
 697747                if (n == previous) continue;
 48
 697749                yield return GlobalEdgeId.Create(fromWay.Id!.Value, tail: previous, head: n);
 697750                previous = n;
 697751            }
 52
 1092253            previous = fromWay.Nodes.Length - 1;
 10820254            for (var n = fromWay.Nodes.Length - 2; n >= 0; n--)
 4317955            {
 4317956                var current = fromWay.Nodes[n];
 7944357                if (current != node) continue;
 691558                if (n == previous) continue;
 59
 691560                yield return GlobalEdgeId.Create(fromWay.Id!.Value, tail: previous, head: n);
 691561                previous = n;
 691562            }
 1092263        }
 697064    }
 65}