< Summary

Class:Itinero.Network.TurnCosts.OrderCoder
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/TurnCosts/OrderCoder.cs
Covered lines:33
Uncovered lines:6
Coverable lines:39
Total lines:66
Line coverage:84.6% (33 of 39)
Covered branches:16
Total branches:18
Branch coverage:88.8% (16 of 18)
Tag:284_38118444584

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
SetTailHeadOrder(...)83.33%1270%
GetTailHeadOrder(...)100%6100%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/TurnCosts/OrderCoder.cs

#LineLine coverage
 1using System;
 2
 3namespace Itinero.Network.TurnCosts;
 4
 5internal static class OrderCoder
 6{
 7    // TODO: widen the tile format so a vertex can carry more than 4 bits of turn cost order.
 8    // Tail and head orders are packed into one byte here, capping a vertex at 15 turn cost
 9    // edges. Real data exceeds that - the AP-6 toll plaza (OSM node 2151903449) ends 26 ways
 10    // on one node - and callers currently drop the restriction, so the turn is left allowed.
 11    // Fixing it properly means a wider encoding and a tile format version bump.
 12    internal const int MaxOrderHeadTail = 14;
 13
 14    public static void SetTailHeadOrder(this byte[] data, long i, byte? tail, byte? head)
 7544315    {
 7544316        if (tail.HasValue && tail.Value > MaxOrderHeadTail)
 017        {
 018            throw new ArgumentOutOfRangeException(nameof(tail),
 019                $"Maximum order exceeded.");
 20        }
 21
 7544322        if (head.HasValue && head.Value > MaxOrderHeadTail)
 023        {
 024            throw new ArgumentOutOfRangeException(nameof(head),
 025                $"Maximum order exceeded.");
 26        }
 27
 7544328        var d = 0;
 7544329        if (tail.HasValue)
 555830        {
 555831            d = tail.Value + 1;
 555832        }
 33
 7544334        if (head.HasValue)
 514035        {
 514036            d += (head.Value + 1) * 16;
 514037        }
 38
 7544339        data[(int)i] = (byte)d;
 7544340    }
 41
 42    public static void GetTailHeadOrder(this byte[] data, long i, ref byte? tail, ref byte? head)
 657827243    {
 657827244        tail = null;
 657827245        head = null;
 46
 657827247        var d = data[(int)i];
 657827248        if (d == 0)
 559260549        {
 559260550            return;
 51        }
 52
 98566753        tail = null;
 98566754        var t = d % 16;
 98566755        if (t > 0)
 53182856        {
 53182857            tail = (byte)(t - 1);
 53182858        }
 59
 98566760        var h = d / 16;
 98566761        if (h > 0)
 52985762        {
 52985763            head = (byte)(h - 1);
 52985764        }
 657827265    }
 66}