< 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:284_38118444584

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)
 466320    {
 1311421        var attributes = osmBarrier.Node.Tags?.Select(tag => (tag.Key, tag.Value)).ToArray() ??
 466322                         ArraySegment<(string key, string value)>.Empty;
 23
 3217524        foreach (var tailHop in osmBarrier.GetTailHops())
 6402125            foreach (var otherHop in osmBarrier.GetTailHops())
 1837126            {
 2746427                if (tailHop == otherHop) continue;
 28
 927829                var headHop = otherHop.GetInverted();
 30
 927831                yield return new GlobalRestriction([tailHop, headHop], true, attributes);
 927832            }
 466333    }
 34
 35    private static IEnumerable<GlobalEdgeId> GetTailHops(
 36        this OsmBarrier osmBarrier)
 1375637    {
 1375638        var node = osmBarrier.Node.Id!.Value;
 39
 7668440        foreach (var fromWay in osmBarrier.Ways)
 1770841        {
 1770842            var previous = 0;
 417980243            for (var n = 1; n < fromWay.Nodes.Length; n++)
 207219344            {
 207219345                var current = fromWay.Nodes[n];
 413062346                if (current != node) continue;
 1376347                if (n == previous) continue;
 48
 1376349                yield return GlobalEdgeId.Create(fromWay.Id!.Value, tail: previous, head: n);
 1376350                previous = n;
 1376351            }
 52
 1770853            previous = fromWay.Nodes.Length - 1;
 417980254            for (var n = fromWay.Nodes.Length - 2; n >= 0; n--)
 207219355            {
 207219356                var current = fromWay.Nodes[n];
 413068557                if (current != node) continue;
 1370158                if (n == previous) continue;
 59
 1370160                yield return GlobalEdgeId.Create(fromWay.Id!.Value, tail: previous, head: n);
 1370161                previous = n;
 1370162            }
 1770863        }
 1375664    }
 65}