< Summary

Class:Itinero.Snapping.ISnapperExtensions
Assembly:Itinero
File(s):/home/runner/work/routing2/routing2/src/Itinero/Snapping/ISnapperExtensions.cs
Covered lines:10
Uncovered lines:16
Coverable lines:26
Total lines:88
Line coverage:38.4% (10 of 26)
Covered branches:3
Total branches:12
Branch coverage:25% (3 of 12)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ToAsync()100%1100%
ToAsync()0%60%
ToVertexAsync()100%10%
ToVerticesAsync()0%20%
ToExactAsync()75%487.5%

File(s)

/home/runner/work/routing2/routing2/src/Itinero/Snapping/ISnapperExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Runtime.CompilerServices;
 4using System.Threading;
 5using System.Threading.Tasks;
 6using Itinero.Network;
 7
 8namespace Itinero.Snapping;
 9
 10/// <summary>
 11/// Contains extensions for ILocations
 12/// </summary>
 13public static class ISnapperExtensions
 14{
 15    /// <summary>
 16    /// Snap to the given location.
 17    /// </summary>
 18    /// <param name="snapper">The snappable.</param>
 19    /// <param name="location">The location.</param>
 20    /// <param name="cancellationToken">The cancellation token.</param>
 21    /// <returns></returns>
 22    public static async Task<Result<SnapPoint>> ToAsync(this ISnapper snapper,
 23        (double longitude, double latitude, float? e) location, CancellationToken cancellationToken = default)
 2124    {
 2125        return await snapper.ToAsync(location.longitude, location.latitude, cancellationToken);
 2126    }
 27
 28    /// <summary>
 29    /// Snaps to the given locations.
 30    /// </summary>
 31    /// <param name="snapper"></param>
 32    /// <param name="locations"></param>
 33    /// <param name="cancellationToken">The cancellation token.</param>
 34    /// <returns></returns>
 35    public static async IAsyncEnumerable<Result<SnapPoint>> ToAsync(this ISnapper snapper, IEnumerable<(double longitude
 36        [EnumeratorCancellation] CancellationToken cancellationToken = default)
 037    {
 038        foreach (var location in locations)
 039        {
 040            yield return await snapper.ToAsync(location, cancellationToken: cancellationToken);
 041        }
 042    }
 43
 44    /// <summary>
 45    /// Snap to the given location.
 46    /// </summary>
 47    /// <param name="snapper">The snappable.</param>
 48    /// <param name="location">The location.</param>
 49    /// <param name="cancellationToken">The cancellation token.</param>
 50    /// <returns></returns>
 51    public static async Task<Result<VertexId>> ToVertexAsync(this ISnapper snapper,
 52        (double longitude, double latitude, float? e) location, CancellationToken cancellationToken = default)
 053    {
 054        return await snapper.ToVertexAsync(location.longitude, location.latitude, cancellationToken);
 055    }
 56
 57    /// <summary>
 58    /// Snaps to the given locations.
 59    /// </summary>
 60    /// <param name="snapper">The locations snapper.</param>
 61    /// <param name="locations">The locations.</param>
 62    /// <returns>The vertices snapped to.</returns>
 63    public static async IAsyncEnumerable<Result<VertexId>> ToVerticesAsync(this ISnapper snapper, IEnumerable<(double lo
 064    {
 065        foreach (var location in locations)
 066        {
 067            yield return await snapper.ToVertexAsync(location);
 068        }
 069    }
 70
 71    /// <summary>
 72    /// Snaps to the given vertex and edge exactly.
 73    /// </summary>
 74    /// <param name="snapper">The snapper.</param>
 75    /// <param name="vertexId">The vertex to snap to.</param>
 76    /// <param name="edgeId">The edge.</param>
 77    /// <param name="asDeparture">When this has a value, any edge will be checked against the configured profile(s) as s
 78    /// <returns>The result if any. Snapping will fail if a vertex has no edges.</returns>
 79    public static async Task<Result<SnapPoint>> ToExactAsync(this ISnapper snapper, VertexId vertexId, EdgeId edgeId, bo
 480    {
 481        var result = snapper.ToAsync(vertexId, asDeparture);
 2082        await foreach (var result1 in result)
 683        {
 1084            if (result1.Value.EdgeId == edgeId) return result1;
 285        }
 086        return new Result<SnapPoint>("Vertex probably does not have edge as neighbour or edge id not snappable by config
 487    }
 88}