Skip to content

Commit ad2fd94

Browse files
committed
refaxctored
1 parent c6aff1d commit ad2fd94

File tree

10 files changed

+32
-31
lines changed

10 files changed

+32
-31
lines changed

.editorconfig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ root = true
44
# C# files
55
[*.cs]
66

7-
# File header
8-
9-
file_header_template = \nCopyright © Pete Sramek. All rights reserved.\nLicensed under the MIT License. See LICENSE file in the project root for full license information.\n
10-
dotnet_diagnostic.IDE0073.severity = warning
11-
127
#### Core EditorConfig Options ####
138

149
# Indentation and spacing
@@ -139,6 +134,7 @@ csharp_prefer_simple_default_expression = true
139134
csharp_style_deconstructed_variable_declaration = true
140135
csharp_style_implicit_object_creation_when_type_is_apparent = true
141136
csharp_style_inlined_variable_declaration = true
137+
csharp_style_prefer_implicitly_typed_lambda_expression = true
142138
csharp_style_prefer_index_operator = true
143139
csharp_style_prefer_local_over_anonymous_function = false
144140
csharp_style_prefer_null_check_over_type_check = true
@@ -219,6 +215,10 @@ dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
219215
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
220216
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
221217

218+
dotnet_naming_rule.private_or_internal_const_field_should_be_pascal_case.severity = suggestion
219+
dotnet_naming_rule.private_or_internal_const_field_should_be_pascal_case.symbols = private_or_internal_const_field
220+
dotnet_naming_rule.private_or_internal_const_field_should_be_pascal_case.style = pascal_case
221+
222222
dotnet_naming_rule.private_or_internal_field_should_be_underscore_camel_case.severity = suggestion
223223
dotnet_naming_rule.private_or_internal_field_should_be_underscore_camel_case.symbols = private_or_internal_field
224224
dotnet_naming_rule.private_or_internal_field_should_be_underscore_camel_case.style = underscore_camel_case
@@ -241,10 +241,14 @@ dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
241241
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
242242
dotnet_naming_symbols.types.required_modifiers =
243243

244-
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
244+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, method, event
245245
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
246246
dotnet_naming_symbols.non_field_members.required_modifiers =
247247

248+
dotnet_naming_symbols.private_or_internal_const_field.applicable_kinds = field
249+
dotnet_naming_symbols.private_or_internal_const_field.applicable_accessibilities = internal, private, protected_internal, private_protected
250+
dotnet_naming_symbols.private_or_internal_const_field.required_modifiers = const
251+
248252
# Naming styles
249253

250254
dotnet_naming_style.pascal_case.required_prefix =

src/PolylineAlgorithm/Abstraction/AbstractPolylineDecoder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace PolylineAlgorithm.Abstraction;
1111
using PolylineAlgorithm.Internal.Logging;
1212
using PolylineAlgorithm.Properties;
1313
using System;
14+
using System.Diagnostics.CodeAnalysis;
1415

1516
/// <summary>
1617
/// Decodes encoded polyline strings into sequences of geographic coordinates.
@@ -134,7 +135,7 @@ static void ValidatePolyline(TPolyline polyline, ILogger<AbstractPolylineDecoder
134135
/// <returns>
135136
/// A <see cref="ReadOnlyMemory{T}"/> representing the encoded polyline data.
136137
/// </returns>
137-
protected abstract ReadOnlyMemory<char> GetReadOnlyMemory(TPolyline? polyline);
138+
protected abstract ReadOnlyMemory<char> GetReadOnlyMemory(TPolyline polyline);
138139

139140
/// <summary>
140141
/// Creates a coordinate instance from the given latitude and longitude values.

src/PolylineAlgorithm/Abstraction/AbstractPolylineEncoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static void ValidateBuffer(ILogger<AbstractPolylineDecoder<TPolyline, TCoordinat
207207
/// The longitude value as a <see cref="double"/>.
208208
/// </returns>
209209

210-
protected abstract double GetLongitude(TCoordinate? current);
210+
protected abstract double GetLongitude(TCoordinate current);
211211

212212
/// <summary>
213213
/// Extracts the latitude value from the specified coordinate.
@@ -217,6 +217,6 @@ static void ValidateBuffer(ILogger<AbstractPolylineDecoder<TPolyline, TCoordinat
217217
/// The latitude value as a <see cref="double"/>.
218218
/// </returns>
219219

220-
protected abstract double GetLatitude(TCoordinate? current);
220+
protected abstract double GetLatitude(TCoordinate current);
221221
}
222222

src/PolylineAlgorithm/PolylineDecoder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public PolylineDecoder(PolylineEncodingOptions options)
1919
: base(options) { }
2020

2121
/// <inheritdoc />
22-
2322
protected override Coordinate CreateCoordinate(double latitude, double longitude) {
2423
return new(latitude, longitude);
2524
}

src/PolylineAlgorithm/PolylineEncoder.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,16 @@ public PolylineEncoder(PolylineEncodingOptions options)
1919
: base(options) { }
2020

2121
/// <inheritdoc />
22-
2322
protected override double GetLatitude(Coordinate coordinate) {
2423
return coordinate.Latitude;
2524
}
2625

2726
/// <inheritdoc />
28-
2927
protected override double GetLongitude(Coordinate coordinate) {
3028
return coordinate.Longitude;
3129
}
3230

3331
/// <inheritdoc />
34-
3532
protected override Polyline CreatePolyline(ReadOnlyMemory<char> polyline) {
3633
return Polyline.FromMemory(polyline);
3734
}

src/PolylineAlgorithm/PolylineEncodingOptions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ namespace PolylineAlgorithm;
1515
/// <remarks>
1616
/// This class allows you to set options such as buffer size and logger factory for encoding operations.
1717
/// </remarks>
18-
[DebuggerDisplay("BufferSizeInBytes: {BufferSizeInBytes}, MaxBufferLength: {MaxBufferLength}, LoggerFactoryType: {LoggerFactory.GetType().Name}")]
18+
[DebuggerDisplay("MaxBufferSize: {MaxBufferSize}, MaxBufferLength: {MaxBufferLength}, LoggerFactoryType: {LoggerFactory.GetType().Name}")]
1919
public sealed class PolylineEncodingOptions {
2020
/// <summary>
2121
/// Gets the maximum buffer size for encoding operations.
2222
/// </summary>
2323
/// <remarks>
2424
/// The default buffer size is 64,000 bytes (64 KB). This can be adjusted based on the expected size of the polyline data.
2525
/// </remarks>
26-
public int BufferSizeInBytes { get; internal set; } = 64_000;
26+
public int MaxBufferSize { get; internal set; } = 64_000;
2727

2828
/// <summary>
2929
/// Gets or sets the precision for encoding coordinates.
@@ -40,5 +40,5 @@ public sealed class PolylineEncodingOptions {
4040
/// <remarks>
4141
/// The maximum length is calculated based on the buffer size divided by the size of a character.
4242
/// </remarks>
43-
internal int MaxBufferLength => BufferSizeInBytes / sizeof(char);
43+
internal int MaxBufferLength => MaxBufferSize / sizeof(char);
4444
}

src/PolylineAlgorithm/PolylineEncodingOptionsBuilder.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ public static PolylineEncodingOptionsBuilder Create() {
3636
/// </returns>
3737
public PolylineEncodingOptions Build() {
3838
return new PolylineEncodingOptions {
39-
BufferSizeInBytes = _bufferSize,
39+
MaxBufferSize = _bufferSize,
4040
LoggerFactory = _loggerFactory
4141
};
4242
}
4343

4444
/// <summary>
4545
/// Sets the buffer size for encoding operations.
4646
/// </summary>
47-
/// <param name="maxBufferSize">
47+
/// <param name="bufferSize">
4848
/// The maximum buffer size. Must be greater than 11.
4949
/// </param>
5050
/// <returns>
5151
/// The current builder instance.
5252
/// </returns>
53-
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="maxBufferSize"/> is less than or equal to 11.</exception>
54-
public PolylineEncodingOptionsBuilder WithBufferSize(int maxBufferSize) {
55-
_bufferSize = maxBufferSize > 11 ? maxBufferSize : throw new ArgumentOutOfRangeException(nameof(maxBufferSize), string.Format(ExceptionMessageResource.BufferSizeMustBeGreaterThanMessageFormat, 11));
53+
/// <exception cref="ArgumentOutOfRangeException">Thrown when <paramref name="bufferSize"/> is less than or equal to 11.</exception>
54+
public PolylineEncodingOptionsBuilder WithMaxBufferSize(int bufferSize) {
55+
_bufferSize = bufferSize > 11 ? bufferSize : throw new ArgumentOutOfRangeException(nameof(bufferSize), string.Format(ExceptionMessageResource.BufferSizeMustBeGreaterThanMessageFormat, 11));
5656

5757
return this;
5858
}

tests/PolylineAlgorithm.Tests/AbstractPolylineEncoderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void Encode_EmptyCoordinates_Throws_ArgumentException() {
8888
[TestMethod]
8989
public void Encode_BufferTooSmall_Throws_InternalBufferOverflowException() {
9090
// Arrange
91-
PolylineEncoder _encoder = new PolylineEncoder(new PolylineEncodingOptions { BufferSizeInBytes = 12 });
91+
PolylineEncoder _encoder = new PolylineEncoder(new PolylineEncodingOptions { MaxBufferSize = 12 });
9292
IEnumerable<(double Latitude, double Longitude)> coordinates = RandomValueProvider.GetCoordinates(2);
9393

9494
// Act

tests/PolylineAlgorithm.Tests/PolylineEncodingOptionsTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void Constructor_Parameterless_Ok() {
1616
var options = new PolylineEncodingOptions();
1717

1818
// Assert
19-
Assert.AreEqual(64_000, options.BufferSizeInBytes);
19+
Assert.AreEqual(64_000, options.MaxBufferSize);
2020
Assert.AreEqual(64_000 / sizeof(char), options.MaxBufferLength);
2121
Assert.IsInstanceOfType<NullLoggerFactory>(options.LoggerFactory);
2222
}
@@ -29,12 +29,12 @@ public void Constructor_ValidOptions_Ok() {
2929

3030
// Act
3131
var options = new PolylineEncodingOptions() {
32-
BufferSizeInBytes = bufferSize,
32+
MaxBufferSize = bufferSize,
3333
LoggerFactory = loggerFactory
3434
};
3535

3636
// Assert
37-
Assert.AreEqual(bufferSize, options.BufferSizeInBytes);
37+
Assert.AreEqual(bufferSize, options.MaxBufferSize);
3838
Assert.AreEqual(bufferSize / sizeof(char), options.MaxBufferLength);
3939
Assert.IsInstanceOfType<FakeLoggerFactory>(options.LoggerFactory);
4040
}

tests/PolylineAlgorithm.Tests/PolylineOptionsBuilderTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Build_Returns_Instance_With_Default_Values() {
3333

3434
// Assert
3535
Assert.IsNotNull(options);
36-
Assert.AreEqual(bufferSize, options.BufferSizeInBytes);
36+
Assert.AreEqual(bufferSize, options.MaxBufferSize);
3737
Assert.AreEqual(bufferSize / sizeof(char), options.MaxBufferLength);
3838
Assert.AreEqual(loggerFactory, options.LoggerFactory);
3939
}
@@ -42,10 +42,10 @@ public void Build_Returns_Instance_With_Default_Values() {
4242
public void WithBufferSize_Small_BufferSize_Parameter_Returns_Throws_ArgumentOutOfRangeException() {
4343
// Arrange
4444
void WithSmallBufferSize() => PolylineEncodingOptionsBuilder.Create()
45-
.WithBufferSize(11);
45+
.WithMaxBufferSize(11);
4646

4747
// Act
48-
var exception = Assert.ThrowsException<ArgumentOutOfRangeException>(WithSmallBufferSize);
48+
var exception = Assert.ThrowsExactly<ArgumentOutOfRangeException>(WithSmallBufferSize);
4949

5050
// Assert
5151
Assert.IsNotNull(exception);
@@ -61,12 +61,12 @@ public void Build_Returns_Instance_With_Expected_Buffer_Size() {
6161

6262
// Act
6363
var options = builder
64-
.WithBufferSize(expected)
64+
.WithMaxBufferSize(expected)
6565
.Build();
6666

6767
// Assert
6868
Assert.IsNotNull(options);
69-
Assert.AreEqual(expected, options.BufferSizeInBytes);
69+
Assert.AreEqual(expected, options.MaxBufferSize);
7070
Assert.AreEqual(expected / sizeof(char), options.MaxBufferLength);
7171
}
7272

@@ -93,7 +93,7 @@ void WithNullLoggerFactory() => PolylineEncodingOptionsBuilder.Create()
9393
.WithLoggerFactory(null!);
9494

9595
// Act
96-
var exception = Assert.ThrowsException<ArgumentNullException>(WithNullLoggerFactory);
96+
var exception = Assert.ThrowsExactly<ArgumentNullException>(WithNullLoggerFactory);
9797

9898
// Assert
9999
Assert.IsNotNull(exception);

0 commit comments

Comments
 (0)