< Summary

Class:Itinero.Network.Tiles.Standalone.Writer.RoutingNetworkWriterExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/Writer/RoutingNetworkWriterExtensions.cs
Covered lines:0
Uncovered lines:56
Coverable lines:56
Total lines:102
Line coverage:0% (0 of 56)
Covered branches:0
Total branches:26
Branch coverage:0% (0 of 26)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
AddStandaloneTile(...)0%260%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Network/Tiles/Standalone/Writer/RoutingNetworkWriterExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Itinero.Data;
 5using Itinero.Network.Writer;
 6
 7namespace Itinero.Network.Tiles.Standalone.Writer;
 8
 9/// <summary>
 10/// Extension methods related to writing standalone tiles to a network.
 11/// </summary>
 12public static class RoutingNetworkWriterExtensions
 13{
 14    /// <summary>
 15    /// Adds a tile in the form of a standalone tile to the network.
 16    /// </summary>
 17    /// <param name="writer">The writer to write to.</param>
 18    /// <param name="tile">The tile to add.</param>
 19    /// <param name="globalIdSet">The global id set.</param>
 20    public static void AddStandaloneTile(this RoutingNetworkWriter writer, StandaloneNetworkTile tile,
 21        GlobalNetworkManager globalIdSet)
 022    {
 23        // add the tile without boundary crossings.
 024        writer.AddTile(tile.NetworkTile);
 25
 26        // add the boundary crossings for tiles that are already loaded.
 027        var boundaryEdges = new Dictionary<BoundaryEdgeId, EdgeId>();
 028        foreach (var crossing in tile.GetBoundaryCrossings())
 029        {
 30            // add crossings in target vertex already in global id set.
 031            var other = crossing.isToTile ? crossing.globalIdFrom : crossing.globalIdTo;
 032            if (globalIdSet.VertexIdSet.TryGet(other, out var otherVertexId))
 033            {
 34                // add the edge.
 35                EdgeId newEdge;
 036                if (crossing.isToTile)
 037                {
 038                    newEdge = writer.AddEdge(otherVertexId, crossing.vertex,
 039                        ArraySegment<(double longitude, double latitude, float? e)>.Empty,
 040                        crossing.attributes, crossing.edgeTypeId, crossing.length);
 041                }
 42                else
 043                {
 044                    newEdge = writer.AddEdge(crossing.vertex, otherVertexId,
 045                        ArraySegment<(double longitude, double latitude, float? e)>.Empty,
 046                        crossing.attributes, crossing.edgeTypeId, crossing.length);
 047                }
 48
 49                // register globally and index crossings.
 050                boundaryEdges[crossing.id] = newEdge;
 051            }
 52
 53            // update global id set with the vertex in the tile.
 054            globalIdSet.VertexIdSet.Set(crossing.isToTile ? crossing.globalIdTo : crossing.globalIdFrom,
 055                crossing.vertex);
 056        }
 57
 58        // read and store all global edge ids.
 059        foreach (var (globalEdgeId, edgeId, boundaryEdgeId) in tile.GetGlobalEdgeIds())
 060        {
 061            if (edgeId != null)
 062            {
 063                globalIdSet.EdgeIdSet.Set(globalEdgeId, edgeId.Value);
 064                continue;
 65            }
 66
 067            if (boundaryEdgeId == null) throw new Exception("global edge has to have at least one edge id");
 068            if (!boundaryEdges.TryGetValue(boundaryEdgeId.Value, out var newEdgeId)) continue;
 69
 070            globalIdSet.EdgeIdSet.Set(globalEdgeId, newEdgeId);
 071        }
 72
 73        // add boundary crossing turn cost or register globally.
 074        foreach (var crossingTurnCosts in tile.GetGlobalTurnCost())
 075        {
 76            // check if all edges are in the network and fetch them.
 077            var hasAllEdges = true;
 078            var edges = crossingTurnCosts.edges.Select(x =>
 079            {
 080                if (globalIdSet.EdgeIdSet.TryGet(x.globalEdgeId, out var newEdgeId)) return (newEdgeId, x.forward);
 081
 082                hasAllEdges = false;
 083                return (EdgeId.Empty, false);
 084            }).ToArray();
 85
 86            // if all edges are there add turn costs.
 87            // if not all edges are there it will be added when the last tile containing an edge for this restriction is
 088            if (hasAllEdges)
 089            {
 90                // figure out what vertex the turn costs need to be added at.
 091                var edgeEnumerator = writer.GetEdgeEnumerator();
 092                if (!edgeEnumerator.MoveTo(edges[^1].Item1, edges[^1].Item2))
 093                    throw new Exception("edge should exist");
 094                var turnCostVertex = edgeEnumerator.Tail;
 95
 096                writer.AddTurnCosts(turnCostVertex, crossingTurnCosts.attributes,
 097                    edges.Select(x => x.Item1).ToArray(),
 098                    crossingTurnCosts.costs, null, crossingTurnCosts.turnCostType);
 099            }
 0100        }
 0101    }
 102}

Methods/Properties

AddStandaloneTile(...)