Skip to content

Commit 2e30ba2

Browse files
committed
minor changes
1 parent 2036823 commit 2e30ba2

3 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/PolylineAlgorithm/Abstraction/AbstractPolylineDecoder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,13 @@ public IEnumerable<TCoordinate> Decode(TPolyline polyline) {
8383

8484
while (true) {
8585
// Check if we have reached the end of the sequence
86-
if (sequence.Length == position) {
86+
if (position < sequence.Length) {
8787
break;
8888
}
8989

9090
// Read the next value from the polyline encoding
91-
if (!PolylineEncoding.TryReadValue(ref latitude, ref sequence, ref position)
92-
|| !PolylineEncoding.TryReadValue(ref longitude, ref sequence, ref position)
91+
if (!PolylineEncoding.TryReadValue(ref latitude, sequence, ref position)
92+
|| !PolylineEncoding.TryReadValue(ref longitude, sequence, ref position)
9393
) {
9494
logger
9595
.LogInvalidPolylineWarning(position);
@@ -106,7 +106,7 @@ public IEnumerable<TCoordinate> Decode(TPolyline polyline) {
106106
.LogOperationFinishedInfo(nameof(Decode));
107107

108108

109-
static void ValidateNullPolyline(TPolyline polyline, ILogger<AbstractPolylineDecoder<TPolyline, TCoordinate>> logger) {
109+
static void ValidateNullPolyline(TPolyline polyline, ILogger logger) {
110110
if (polyline is null) {
111111
logger
112112
.LogNullArgumentWarning(nameof(polyline));
@@ -115,14 +115,14 @@ static void ValidateNullPolyline(TPolyline polyline, ILogger<AbstractPolylineDec
115115
}
116116
}
117117

118-
static void ValidateEmptySequence(ILogger<AbstractPolylineDecoder<TPolyline, TCoordinate>> logger, ReadOnlyMemory<char> sequence) {
118+
static void ValidateEmptySequence(ILogger logger, ReadOnlyMemory<char> sequence) {
119119
if (sequence.Length < Defaults.Polyline.Block.Length.Min) {
120120
logger
121121
.LogPolylineCannotBeShorterThanWarning(nameof(sequence), sequence.Length, Defaults.Polyline.Block.Length.Min);
122122
logger.
123123
LogOperationFailedInfo(nameof(Decode));
124124

125-
throw new ArgumentException(string.Format(ExceptionMessageResource.PolylineCannotBeShorterThanExceptionMessage, sequence.Length), nameof(polyline));
125+
throw new ArgumentException(string.Format(ExceptionMessageResource.PolylineCannotBeShorterThanExceptionMessage, sequence.Length), nameof(sequence));
126126
}
127127
}
128128
}

src/PolylineAlgorithm/Abstraction/AbstractPolylineEncoder.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected AbstractPolylineEncoder(PolylineEncodingOptions options) {
6464
public TPolyline Encode(IEnumerable<TCoordinate> coordinates) {
6565
var logger = Options
6666
.LoggerFactory
67-
.CreateLogger<AbstractPolylineDecoder<TPolyline, TCoordinate>>();
67+
.CreateLogger<AbstractPolylineEncoder<TCoordinate, TPolyline>>();
6868

6969
logger
7070
.LogOperationStartedInfo(nameof(Encode));
@@ -98,8 +98,8 @@ public TPolyline Encode(IEnumerable<TCoordinate> coordinates) {
9898

9999
ValidateBuffer(logger, variance, position, buffer);
100100

101-
if (!PolylineEncoding.TryWriteValue(variance.Latitude, ref buffer, ref position)
102-
|| !PolylineEncoding.TryWriteValue(variance.Longitude, ref buffer, ref position)
101+
if (!PolylineEncoding.TryWriteValue(variance.Latitude, buffer, ref position)
102+
|| !PolylineEncoding.TryWriteValue(variance.Longitude, buffer, ref position)
103103
) {
104104
// This shouldn't happen, but if it does, log the error and throw an exception.
105105
logger
@@ -153,7 +153,7 @@ int GetMaxBufferLength(int count) {
153153
return requestedBufferLength;
154154
}
155155

156-
static void ValidateNullCoordinates(IEnumerable<TCoordinate> coordinates, ILogger<AbstractPolylineDecoder<TPolyline, TCoordinate>> logger) {
156+
static void ValidateNullCoordinates(IEnumerable<TCoordinate> coordinates, ILogger logger) {
157157
if (coordinates is null) {
158158
logger
159159
.LogNullArgumentWarning(nameof(coordinates));
@@ -164,7 +164,7 @@ static void ValidateNullCoordinates(IEnumerable<TCoordinate> coordinates, ILogge
164164
}
165165
}
166166

167-
static void ValidateEmptyCoordinates(ILogger<AbstractPolylineDecoder<TPolyline, TCoordinate>> logger, int count) {
167+
static void ValidateEmptyCoordinates(ILogger logger, int count) {
168168
if (count < 1) {
169169
logger
170170
.LogEmptyArgumentWarning(nameof(coordinates));
@@ -175,7 +175,7 @@ static void ValidateEmptyCoordinates(ILogger<AbstractPolylineDecoder<TPolyline,
175175
}
176176
}
177177

178-
static void ValidateBuffer(ILogger<AbstractPolylineDecoder<TPolyline, TCoordinate>> logger, CoordinateVariance variance, int position, Span<char> buffer) {
178+
static void ValidateBuffer(ILogger logger, CoordinateVariance variance, int position, Span<char> buffer) {
179179
if (GetRemainingBufferSize(position, buffer.Length) < GetRequiredLength(variance)) {
180180
logger
181181
.LogInternalBufferOverflowWarning(position, buffer.Length, GetRequiredLength(variance));

tests/PolylineAlgorithm.Tests/PolylineEncodingTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void TryWriteValue_StaticBuffer_Returns_True_Equals_Expected(int variance
136136
Span<char> buffer = stackalloc char[6];
137137

138138
// Act
139-
bool result = PolylineEncoding.TryWriteValue(variance, ref buffer, ref position);
139+
bool result = PolylineEncoding.TryWriteValue(variance, buffer, ref position);
140140

141141
// Assert
142142
Assert.IsTrue(result);
@@ -154,7 +154,7 @@ public void TryWriteValue_DynamicBuffer_Returns_True_Equals_Expected(int varianc
154154
Span<char> buffer = stackalloc char[required];
155155

156156
// Act
157-
bool result = PolylineEncoding.TryWriteValue(variance, ref buffer, ref position);
157+
bool result = PolylineEncoding.TryWriteValue(variance, buffer, ref position);
158158

159159
// Assert
160160
Assert.IsTrue(result);
@@ -172,7 +172,7 @@ public void TryWriteValue_BufferTooSmall_Returns_False(int variance, string _) {
172172
Span<char> buffer = stackalloc char[required - 1];
173173

174174
// Act
175-
bool result = PolylineEncoding.TryWriteValue(variance, ref buffer, ref position);
175+
bool result = PolylineEncoding.TryWriteValue(variance, buffer, ref position);
176176

177177
// Assert
178178
Assert.IsFalse(result);
@@ -187,7 +187,7 @@ public void TryReadValue_Ok(int expected, string polyline) {
187187
var buffer = polyline.AsMemory();
188188

189189
// Act
190-
bool result = PolylineEncoding.TryReadValue(ref variance, ref buffer, ref position);
190+
bool result = PolylineEncoding.TryReadValue(ref variance, buffer, ref position);
191191

192192
// Assert
193193
Assert.IsTrue(result);
@@ -203,7 +203,7 @@ public void TryReadValue_EmptyBuffer_Returns_False() {
203203
ReadOnlyMemory<char> buffer = Memory<char>.Empty;
204204

205205
// Act
206-
bool result = PolylineEncoding.TryReadValue(ref variance, ref buffer, ref position);
206+
bool result = PolylineEncoding.TryReadValue(ref variance, buffer, ref position);
207207

208208
// Assert
209209
Assert.IsFalse(result);
@@ -220,7 +220,7 @@ public void TryReadValue_MalformedBuffer_Returns_False() {
220220
ReadOnlyMemory<char> buffer = chars.AsMemory();
221221

222222
// Act
223-
bool result = PolylineEncoding.TryReadValue(ref variance, ref buffer, ref position);
223+
bool result = PolylineEncoding.TryReadValue(ref variance, buffer, ref position);
224224

225225
// Assert
226226
Assert.IsFalse(result);

0 commit comments

Comments
 (0)