@@ -9,7 +9,6 @@ namespace PolylineAlgorithm;
9
9
using PolylineAlgorithm . Internal ;
10
10
using System ;
11
11
using System . Collections . Generic ;
12
- using System . Diagnostics . CodeAnalysis ;
13
12
using System . Runtime . CompilerServices ;
14
13
15
14
/// <summary>
@@ -43,18 +42,18 @@ public Polyline Encode(IEnumerable<Coordinate> coordinates) {
43
42
int position = 0 ;
44
43
int consumed = 0 ;
45
44
int length = GetMaxLength ( count ) ;
46
- bool isMultiSegment = count == - 1 || count > MaxCount ;
45
+ bool asMultiSegment = count == - 1 || count > MaxCount ;
47
46
PolylineBuilder builder = new ( ) ;
48
47
Span < char > buffer = stackalloc char [ length ] ;
49
48
50
49
using var enumerator = coordinates . GetEnumerator ( ) ;
51
50
52
51
while ( enumerator . MoveNext ( ) ) {
53
52
variance
54
- . Next ( Normalize ( enumerator . Current ) ) ;
55
-
56
- if ( isMultiSegment
57
- && buffer . Length - position < 12 ) {
53
+ . Next ( ( PolylineEncoding . Default . Normalize ( enumerator . Current . Latitude ) , PolylineEncoding . Default . Normalize ( enumerator . Current . Longitude ) ) ) ;
54
+
55
+ if ( asMultiSegment
56
+ && buffer . Length - position < PolylineEncoding . Default . GetCharCount ( variance . Latitude ) + PolylineEncoding . Default . GetCharCount ( variance . Longitude ) ) {
58
57
builder
59
58
. Append ( buffer [ ..position ] . ToString ( ) . AsMemory ( ) ) ;
60
59
@@ -68,18 +67,11 @@ public Polyline Encode(IEnumerable<Coordinate> coordinates) {
68
67
}
69
68
70
69
consumed ++ ;
71
-
72
- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
73
- static ( int Latitude , int Longitude ) Normalize ( Coordinate coordinate ) {
74
- return ( PolylineEncoding . Default . Normalize ( coordinate . Latitude ) , PolylineEncoding . Default . Normalize ( coordinate . Longitude ) ) ;
75
- }
76
70
}
77
71
78
- #pragma warning disable CA1508 // Avoid dead conditional code
79
72
if ( consumed == 0 ) {
80
73
return default ;
81
74
}
82
- #pragma warning restore CA1508 // Avoid dead conditional code
83
75
84
76
builder
85
77
. Append ( buffer [ ..position ] . ToString ( ) . AsMemory ( ) ) ;
@@ -92,18 +84,17 @@ public Polyline Encode(IEnumerable<Coordinate> coordinates) {
92
84
> 1 and < MaxCount => count * Defaults . Polyline . MaxEncodedCoordinateLength ,
93
85
_ => MaxChars
94
86
} ;
95
- }
96
87
97
- /// <summary>
98
- /// Gets the count of coordinates in the enumerable.
99
- /// </summary>
100
- /// <param name="coordinates">The enumerable of coordinates.</param>
101
- /// <returns>The count of coordinates.</returns>
102
- [ ExcludeFromCodeCoverage ]
103
- [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
104
- static int GetCount ( IEnumerable < Coordinate > coordinates ) => coordinates switch {
105
- ICollection < Coordinate > collection => collection . Count ,
106
- IEnumerable < Coordinate > enumerable => enumerable . Count ( ) ,
107
- _ => - 1 ,
108
- } ;
88
+ /// <summary>
89
+ /// Gets the count of coordinates in the enumerable.
90
+ /// </summary>
91
+ /// <param name="coordinates">The enumerable of coordinates.</param>
92
+ /// <returns>The count of coordinates.</returns>
93
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
94
+ static int GetCount ( IEnumerable < Coordinate > coordinates ) => coordinates switch {
95
+ ICollection < Coordinate > collection => collection . Count ,
96
+ IEnumerable < Coordinate > enumerable => enumerable . Count ( ) ,
97
+ _ => - 1 ,
98
+ } ;
99
+ }
109
100
}
0 commit comments