< Summary

Class:Itinero.Routing.RouterExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Routing/RouterExtensions.cs
Covered lines:18
Uncovered lines:73
Coverable lines:91
Total lines:157
Line coverage:19.7% (18 of 91)
Covered branches:4
Total branches:26
Branch coverage:15.3% (4 of 26)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToDirected(...)0%20%
ToDirected(...)100%10%
ToDirected(...)0%20%
ToDirected(...)0%20%
ToDirected(...)0%20%
ToUndirected(...)0%40%
TryToUndirected(...)75%471.42%
MaxBoxFor(...)100%10%
MaxBoxFor(...)16.66%653.33%
MaxBoxFor(...)0%40%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Routing/RouterExtensions.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.IO;
 3using System.Linq;
 4using Itinero.Geo;
 5using Itinero.Geo.Directions;
 6using Itinero.Network;
 7using Itinero.Snapping;
 8
 9namespace Itinero.Routing;
 10
 11internal static class RouterExtensions
 12{
 13    internal static (SnapPoint snapPoint, bool? direction) ToDirected(
 14        this (SnapPoint snapPoint, DirectionEnum? angle) snapPointAndDirection, RoutingNetwork routerDb)
 015    {
 016        if (snapPointAndDirection.angle == null)
 017        {
 018            return (snapPointAndDirection.snapPoint, null);
 19        }
 20
 021        return (snapPointAndDirection.snapPoint,
 022            snapPointAndDirection.snapPoint.DirectionFromAngle(routerDb, (double)snapPointAndDirection.angle,
 023                out _));
 024    }
 25
 26    internal static (SnapPoint snapPoint, bool? direction) ToDirected(
 27        this (SnapPoint snapPoint, double angle) snapPointAndDirection, RoutingNetwork routerDb)
 028    {
 029        return (snapPointAndDirection.snapPoint,
 030            snapPointAndDirection.snapPoint.DirectionFromAngle(routerDb, snapPointAndDirection.angle, out _));
 031    }
 32
 33    internal static IReadOnlyList<(SnapPoint sp, bool? directed)> ToDirected(
 34        this IEnumerable<(SnapPoint snapPoint, DirectionEnum? directionEnum)> sps,
 35        RoutingNetwork routerDb)
 036    {
 037        var directedSps = new List<(SnapPoint sp, bool? directed)>();
 038        foreach (var sp in sps)
 039        {
 040            directedSps.Add((sp.snapPoint, (double)sp.directionEnum).ToDirected(routerDb));
 041        }
 42
 043        return directedSps;
 044    }
 45
 46    internal static IReadOnlyList<(SnapPoint sp, bool? directed)> ToDirected(
 47        this IReadOnlyList<(SnapPoint snapPoint, double angle)> sps,
 48        RoutingNetwork routerDb)
 049    {
 050        var directedSps = new List<(SnapPoint sp, bool? directed)>();
 051        foreach (var sp in sps)
 052        {
 053            directedSps.Add(sp.ToDirected(routerDb));
 054        }
 55
 056        return directedSps;
 057    }
 58
 59    internal static IReadOnlyList<(SnapPoint sp, bool? directed)> ToDirected(this IReadOnlyList<SnapPoint> sps)
 060    {
 061        var directedSps = new List<(SnapPoint sp, bool? directed)>();
 062        foreach (var sp in sps)
 063        {
 064            directedSps.Add((sp, null));
 065        }
 66
 067        return directedSps;
 068    }
 69
 70    internal static IReadOnlyList<SnapPoint> ToUndirected(
 71        this IReadOnlyList<(SnapPoint sp, bool? directed)> directedSps)
 072    {
 073        var sps = new List<SnapPoint>();
 074        foreach (var (sp, direction) in directedSps)
 075        {
 076            if (direction != null)
 077            {
 078                throw new InvalidDataException($"{nameof(SnapPoint)} is directed cannot convert to undirected.");
 79            }
 80
 081            sps.Add(sp);
 082        }
 83
 084        return sps;
 085    }
 86
 87    internal static bool TryToUndirected(
 88        this IEnumerable<(SnapPoint sp, bool? directed)> directedSps, out IReadOnlyList<SnapPoint> undirected)
 1489    {
 1490        var sps = new List<SnapPoint>();
 7091        foreach (var (sp, direction) in directedSps)
 1492        {
 1493            if (direction != null)
 094            {
 095                sps.Clear();
 096                undirected = sps;
 097                return false;
 98            }
 99
 14100            sps.Add(sp);
 14101        }
 102
 14103        undirected = sps;
 14104        return true;
 14105    }
 106
 107    internal static ((double longitude, double latitude, float? e) topLeft, (double longitude, double latitude,
 108        float? e) bottomRight)?
 109        MaxBoxFor(this RoutingSettings settings,
 110            RoutingNetwork routerDb, IEnumerable<(SnapPoint sp, bool? direction)> sps)
 0111    {
 0112        return settings.MaxBoxFor(routerDb, sps.Select(x => x.sp));
 0113    }
 114
 115    internal static ((double longitude, double latitude, float? e) topLeft, (double longitude, double latitude,
 116        float? e) bottomRight)? MaxBoxFor(this RoutingSettings settings,
 117            RoutingNetwork routerDb, IEnumerable<SnapPoint> sp)
 7118    {
 7119        ((double longitude, double latitude, float? e) topLeft, (double longitude, double latitude, float? e)
 7120            bottomRight)? maxBox =
 7121                null;
 122
 7123        if (!(settings.MaxDistance < double.MaxValue))
 7124        {
 7125            return null;
 126        }
 127
 0128        foreach (var source in sp)
 0129        {
 0130            var sourceLocation = source.LocationOnNetwork(routerDb);
 0131            var sourceBox = sourceLocation.BoxAround(settings.MaxDistance);
 0132            maxBox = maxBox?.Expand(sourceBox) ?? sourceBox;
 0133        }
 134
 0135        return maxBox;
 7136    }
 137
 138    internal static ((double longitude, double latitude, float? e) topLeft, (double longitude, double latitude,
 139        float? e) bottomRight)? MaxBoxFor(this RoutingSettings settings,
 140            RoutingNetwork routerDb, SnapPoint sp)
 0141    {
 0142        ((double longitude, double latitude, float? e) topLeft, (double longitude, double latitude, float? e)
 0143            bottomRight)? maxBox =
 0144                null;
 145
 0146        if (!(settings.MaxDistance < double.MaxValue))
 0147        {
 0148            return null;
 149        }
 150
 0151        var sourceLocation = sp.LocationOnNetwork(routerDb);
 0152        var sourceBox = sourceLocation.BoxAround(settings.MaxDistance);
 0153        maxBox = maxBox?.Expand(sourceBox) ?? sourceBox;
 154
 0155        return maxBox;
 0156    }
 157}