Skip to content

Commit 5aa0c2a

Browse files
committed
cleanup, refact
1 parent 6ba2d81 commit 5aa0c2a

7 files changed

Lines changed: 160 additions & 165 deletions

File tree

samples/PolylineAlgorithm.NetTopologySuite.Sample/NetTopologyPolylineDecoder.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@ namespace PolylineAlgorithm.NetTopologySuite.Sample;
1212
/// <summary>
1313
/// Polyline decoder using NetTopologySuite.
1414
/// </summary>
15-
public sealed class NetTopologyPolylineDecoder : AbstractPolylineDecoder<string, Point>
16-
{
15+
public sealed class NetTopologyPolylineDecoder : AbstractPolylineDecoder<string, Point> {
1716
/// <summary>
1817
/// Creates a NetTopologySuite point from latitude and longitude.
1918
/// </summary>
2019
/// <param name="latitude">Latitude value.</param>
2120
/// <param name="longitude">Longitude value.</param>
2221
/// <returns>Point instance.</returns>
23-
protected override Point CreateCoordinate(double latitude, double longitude)
24-
{
22+
protected override Point CreateCoordinate(double latitude, double longitude) {
2523
// NetTopologySuite Point: x = longitude, y = latitude
2624
return new Point(longitude, latitude);
2725
}
@@ -31,8 +29,7 @@ protected override Point CreateCoordinate(double latitude, double longitude)
3129
/// </summary>
3230
/// <param name="polyline">Encoded polyline string.</param>
3331
/// <returns>ReadOnlyMemory of characters.</returns>
34-
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline)
35-
{
32+
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline) {
3633
return polyline.AsMemory();
3734
}
3835
}

src/PolylineAlgorithm/Abstraction/AbstractPolylineDecoder.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
//
55

66
using Microsoft.Extensions.Logging;
7-
using PolylineAlgorithm;
87
using PolylineAlgorithm.Diagnostics;
98
using PolylineAlgorithm.Internal;
109
using PolylineAlgorithm.Internal.Diagnostics;
1110
using PolylineAlgorithm.Internal.Logging;
12-
using System;
1311
using System.Runtime.CompilerServices;
14-
using System.Threading;
1512

1613
namespace PolylineAlgorithm.Abstraction {
1714
/// <summary>
@@ -33,14 +30,14 @@ protected AbstractPolylineDecoder()
3330
/// <summary>
3431
/// Initializes a new instance of the <see cref="AbstractPolylineDecoder{TPolyline, TCoordinate}"/> class with the specified encoding options.
3532
/// </summary>
36-
/// <param name="encodingOptions">
33+
/// <param name="options">
3734
/// The <see cref="PolylineEncodingOptions"/> to use for encoding operations.
3835
/// </param>
3936
/// <exception cref="ArgumentNullException">
40-
/// Thrown when <paramref name="encodingOptions"/> is <see langword="null" />
37+
/// Thrown when <paramref name="options"/> is <see langword="null" />
4138
/// </exception>
4239
protected AbstractPolylineDecoder(PolylineEncodingOptions options) {
43-
if(options is null) {
40+
if (options is null) {
4441
ExceptionGuard.ThrowArgumentNull(nameof(options));
4542
}
4643

@@ -110,7 +107,6 @@ public IEnumerable<TCoordinate> Decode(TPolyline polyline, CancellationToken can
110107
_logger?.LogOperationFailedDebug(OperationName);
111108
_logger?.LogInvalidPolylineWarning(position);
112109

113-
OnInvalidPolyline(position, sequence);
114110
ExceptionGuard.ThrowInvalidPolylineFormat(position);
115111
}
116112

@@ -126,6 +122,16 @@ public IEnumerable<TCoordinate> Decode(TPolyline polyline, CancellationToken can
126122
}
127123
}
128124

125+
/// <summary>
126+
/// Validates that the provided polyline is not <see langword="null"/>.
127+
/// Throws an <see cref="ArgumentNullException"/> if the polyline is <see langword="null"/>.
128+
/// Optionally logs a warning if a logger is provided.
129+
/// </summary>
130+
/// <param name="polyline">The polyline instance to validate.</param>
131+
/// <param name="logger">Optional logger for diagnostic messages.</param>
132+
/// <exception cref="ArgumentNullException">
133+
/// Thrown when <paramref name="polyline"/> is <see langword="null"/>.
134+
/// </exception>
129135
[MethodImpl(MethodImplOptions.AggressiveInlining)]
130136
private static void ValidateNullPolyline(TPolyline polyline, ILogger? logger) {
131137
if (polyline is null) {
@@ -134,6 +140,16 @@ private static void ValidateNullPolyline(TPolyline polyline, ILogger? logger) {
134140
}
135141
}
136142

143+
/// <summary>
144+
/// Validates that the polyline sequence meets the minimum required length.
145+
/// Throws an <see cref="InvalidPolylineException"/> if the sequence is too short.
146+
/// Optionally logs diagnostic messages if a logger is provided.
147+
/// </summary>
148+
/// <param name="polylineSequence">The polyline character sequence to validate.</param>
149+
/// <param name="logger">Optional logger for diagnostic messages.</param>
150+
/// <exception cref="InvalidPolylineException">
151+
/// Thrown when <paramref name="polylineSequence"/> is shorter than the minimum allowed length.
152+
/// </exception>
137153
[MethodImpl(MethodImplOptions.AggressiveInlining)]
138154
private static void ValidateSequence(ReadOnlyMemory<char> polylineSequence, ILogger? logger) {
139155
if (polylineSequence.Length < Defaults.Polyline.Block.Length.Min) {
@@ -158,13 +174,6 @@ protected virtual void ValidateFormat(ReadOnlyMemory<char> sequence, ILogger? lo
158174
}
159175
}
160176

161-
/// <summary>
162-
/// Hook for subclasses to handle invalid polyline cases.
163-
/// </summary>
164-
protected virtual void OnInvalidPolyline(int position, ReadOnlyMemory<char> polylineSequence) {
165-
// Subclasses can override for custom error handling/logging.
166-
}
167-
168177
[MethodImpl(MethodImplOptions.AggressiveInlining)]
169178
protected abstract ReadOnlyMemory<char> GetReadOnlyMemory(in TPolyline polyline);
170179

src/PolylineAlgorithm/Abstraction/AbstractPolylineEncoder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace PolylineAlgorithm.Abstraction;
1010
using PolylineAlgorithm.Internal;
1111
using PolylineAlgorithm.Internal.Diagnostics;
1212
using PolylineAlgorithm.Internal.Logging;
13-
using PolylineAlgorithm.Properties;
1413
using System;
1514
using System.Buffers;
1615
using System.Diagnostics;
@@ -113,7 +112,7 @@ public TPolyline Encode(ReadOnlySpan<TCoordinate> coordinates) {
113112
.LogCannotWriteValueToBufferWarning(position, consumed);
114113

115114
ExceptionGuard.ThrowCouldNotWriteEncodedValueToBuffer();
116-
115+
117116
}
118117

119118
consumed++;

src/PolylineAlgorithm/Diagnostics/InvalidPolylineException.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55

66
namespace PolylineAlgorithm.Diagnostics;
77

8-
using PolylineAlgorithm.Internal.Diagnostics;
98
using System;
109
using System.Diagnostics;
11-
using System.Diagnostics.CodeAnalysis;
1210

1311
/// <summary>
1412
/// Exception thrown when a polyline is determined to be malformed or invalid during processing.
@@ -17,8 +15,7 @@ namespace PolylineAlgorithm.Diagnostics;
1715
/// This exception is used internally to indicate that a polyline string does not conform to the expected format or contains errors.
1816
/// </remarks>
1917
[DebuggerDisplay($"{nameof(InvalidPolylineException)}: {{ToString()}}")]
20-
public sealed class InvalidPolylineException : Exception
21-
{
18+
public sealed class InvalidPolylineException : Exception {
2219
/// <summary>
2320
/// Initializes a new instance of the <see cref="InvalidPolylineException"/> class.
2421
/// </summary>

src/PolylineAlgorithm/Polyline.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace PolylineAlgorithm;
77

88
using PolylineAlgorithm.Internal.Diagnostics;
9-
using PolylineAlgorithm.Properties;
109
using System;
1110
using System.Diagnostics;
1211
using System.Diagnostics.CodeAnalysis;

0 commit comments

Comments
 (0)