< 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:251_23667616543

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)
 237820    {
 854421        var attributes = osmBarrier.Node.Tags?.Select(tag => (tag.Key, tag.Value)).ToArray() ??
 237822                         ArraySegment<(string key, string value)>.Empty;
 23
 1618024        foreach (var tailHop in osmBarrier.GetTailHops())
 3202725            foreach (var otherHop in osmBarrier.GetTailHops())
 922926            {
 1375227                if (tailHop == otherHop) continue;
 28
 470629                var headHop = otherHop.GetInverted();
 30
 470631                yield return new GlobalRestriction([tailHop, headHop], true, attributes);
 470632            }
 237833    }
 34
 35    private static IEnumerable<GlobalEdgeId> GetTailHops(
 36        this OsmBarrier osmBarrier)
 690137    {
 690138        var node = osmBarrier.Node.Id!.Value;
 39
 4232140        foreach (var fromWay in osmBarrier.Ways)
 1080941        {
 1080942            var previous = 0;
 10749243            for (var n = 1; n < fromWay.Nodes.Length; n++)
 4293744            {
 4293745                var current = fromWay.Nodes[n];
 7897446                if (current != node) continue;
 690047                if (n == previous) continue;
 48
 690049                yield return GlobalEdgeId.Create(fromWay.Id!.Value, tail: previous, head: n);
 690050                previous = n;
 690051            }
 52
 1080953            previous = fromWay.Nodes.Length - 1;
 10749254            for (var n = fromWay.Nodes.Length - 2; n >= 0; n--)
 4293755            {
 4293756                var current = fromWay.Nodes[n];
 7902257                if (current != node) continue;
 685258                if (n == previous) continue;
 59
 685260                yield return GlobalEdgeId.Create(fromWay.Id!.Value, tail: previous, head: n);
 685261                previous = n;
 685262            }
 1080963        }
 690164    }
 65}