< 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:0
Uncovered lines:17
Coverable lines:17
Total lines:50
Line coverage:0% (0 of 17)
Covered branches:0
Total branches:10
Branch coverage:0% (0 of 10)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToNetworkRestrictions(...)0%100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Itinero.Network;
 4using Itinero.Network.Enumerators.Edges;
 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    /// The signature of a function to get edges for the given nodes pair along the given way.
 15    /// </summary>
 16    public delegate IEdgeEnumerator GetEdgesFor(long node);
 17
 18    /// <summary>
 19    /// Converts the given barrier into one or more network restrictions
 20    /// </summary>
 21    /// <param name="osmBarrier">The OSM barrier.</param>
 22    /// <param name="getEdgesFor">A function to get edges for a given node.</param>
 23    /// <returns>The restrictions using network edges and vertices.</returns>
 24    public static Result<IEnumerable<NetworkRestriction>> ToNetworkRestrictions(
 25        this OsmBarrier osmBarrier,
 26        GetEdgesFor getEdgesFor)
 027    {
 28        // get all edges starting at the given node.
 029        var edges = new List<(EdgeId edge, bool forward)>();
 030        var enumerator = getEdgesFor(osmBarrier.Node);
 031        while (enumerator.MoveNext())
 032        {
 033            edges.Add((enumerator.EdgeId, enumerator.Forward));
 034        }
 35
 036        if (edges.Count < 2) return new Result<IEnumerable<NetworkRestriction>>(ArraySegment<NetworkRestriction>.Empty);
 37
 38        // for each two edges create one restriction.
 039        var restrictions = new List<NetworkRestriction>();
 040        foreach (var from in edges)
 041            foreach (var to in edges)
 042            {
 043                if (from.edge == to.edge) continue;
 44
 045                restrictions.Add(new NetworkRestriction(new[] { from, to }, true, osmBarrier.Attributes));
 046            }
 47
 048        return new Result<IEnumerable<NetworkRestriction>>(restrictions);
 049    }
 50}

Methods/Properties

ToNetworkRestrictions(...)