-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPolylineDecoderExtensions.cs
More file actions
86 lines (78 loc) · 3.57 KB
/
PolylineDecoderExtensions.cs
File metadata and controls
86 lines (78 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// Copyright © Pete Sramek. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace PolylineAlgorithm.Extensions;
using PolylineAlgorithm;
using PolylineAlgorithm.Abstraction;
using PolylineAlgorithm.Internal.Diagnostics;
using System;
using System.Collections.Generic;
/// <summary>
/// Provides extension methods for the <see cref="IPolylineDecoder{TPolyline, TCoordinate}"/> interface to facilitate decoding encoded polylines.
/// </summary>
public static class PolylineDecoderExtensions {
/// <summary>
/// Decodes an encoded polyline string into a sequence of geographic coordinates.
/// </summary>
/// <param name="decoder">
/// The <see cref="IPolylineDecoder{TPolyline, TCoordinate}"/> instance used to perform the decoding operation.
/// </param>
/// <param name="polyline">
/// The encoded polyline string to decode.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{Coordinate}"/> containing the decoded latitude and longitude pairs.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="decoder"/> or <paramref name="polyline"/> is <see langword="null"/>.
/// </exception>
public static IEnumerable<Coordinate> Decode(this IPolylineDecoder<Polyline, Coordinate> decoder, string polyline) {
if (decoder is null) {
ExceptionGuard.ThrowArgumentNull(nameof(decoder));
}
return decoder.Decode(Polyline.FromString(polyline));
}
/// <summary>
/// Decodes an encoded polyline represented as a character array into a sequence of geographic coordinates.
/// </summary>
/// <param name="decoder">
/// The <see cref="IPolylineDecoder{TPolyline, TCoordinate}"/> instance used to perform the decoding operation.
/// </param>
/// <param name="polyline">
/// The encoded polyline as a character array to decode.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{Coordinate}"/> containing the decoded latitude and longitude pairs.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="decoder"/> or <paramref name="polyline"/> is <see langword="null"/>.
/// </exception>
public static IEnumerable<Coordinate> Decode(this IPolylineDecoder<Polyline, Coordinate> decoder, char[] polyline) {
if (decoder is null) {
ExceptionGuard.ThrowArgumentNull(nameof(decoder));
}
return decoder.Decode(Polyline.FromCharArray(polyline));
}
/// <summary>
/// Decodes an encoded polyline represented as a read-only memory of characters into a sequence of geographic coordinates.
/// </summary>
/// <param name="decoder">
/// The <see cref="IPolylineDecoder{TPolyline, TCoordinate}"/> instance used to perform the decoding operation.
/// </param>
/// <param name="polyline">
/// The encoded polyline as a read-only memory of characters to decode.
/// </param>
/// <returns>
/// An <see cref="IEnumerable{Coordinate}"/> containing the decoded latitude and longitude pairs.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown when <paramref name="decoder"/> is <see langword="null"/>.
/// </exception>
public static IEnumerable<Coordinate> Decode(this IPolylineDecoder<Polyline, Coordinate> decoder, ReadOnlyMemory<char> polyline) {
if (decoder is null) {
ExceptionGuard.ThrowArgumentNull(nameof(decoder));
}
return decoder.Decode(Polyline.FromMemory(polyline));
}
}