Skip to content

Commit cf2c7b7

Browse files
author
Pete Sramek
committed
changes
1 parent f27c6c0 commit cf2c7b7

File tree

11 files changed

+29
-33
lines changed

11 files changed

+29
-33
lines changed

PolylineAlgorithm.slnx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<Project Path="benchmarks/PolylineAlgorithm.Benchmarks/PolylineAlgorithm.Benchmarks.csproj" />
44
<Project Path="benchmarks/PolylineAlgorithm.Comparison.Benchmarks/PolylineAlgorithm.Comparison.Benchmarks.csproj" />
55
</Folder>
6-
<Folder Name="/samples/" />
76
<Folder Name="/src/">
87
<Project Path="src/PolylineAlgorithm/PolylineAlgorithm.csproj" />
98
</Folder>

src/PolylineAlgorithm/Coordinate.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ namespace PolylineAlgorithm;
1717
[DebuggerDisplay("{ToString()}")]
1818
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 16)]
1919
public readonly struct Coordinate : IEquatable<Coordinate> {
20-
public static readonly Coordinate Default;
21-
internal static long Size { get; } = Marshal.SizeOf<Coordinate>();
22-
2320
/// <summary>
2421
/// Initializes a new instance of the <see cref="Coordinate"/> struct with default values for <see cref="Latitude"/> and <see cref="Longitude"/>.
2522
/// </summary>
@@ -60,9 +57,7 @@ public bool IsDefault()
6057
/// Determines whether the coordinate is valid by checking if both <see cref="Latitude"/> and <see cref="Longitude"/> are within their respective valid ranges.
6158
/// </summary>
6259
/// <returns><see langword="true"/> if the coordinate is valid; otherwise, <see langword="false"/>.</returns>
63-
public bool IsValid()
64-
=> ICoordinateValidator.Default.Latitude.IsInRange(Latitude)
65-
&& ICoordinateValidator.Default.Longitude.IsInRange(Longitude);
60+
public bool IsValid() => ICoordinateValidator.Default.IsValid(this);
6661

6762
#region Overrides
6863

src/PolylineAlgorithm/Validation/CoordinateRange.cs renamed to src/PolylineAlgorithm/Internal/CoordinateRange.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
44
//
55

6-
namespace PolylineAlgorithm.Validation;
6+
namespace PolylineAlgorithm.Internal;
77

88
using PolylineAlgorithm.Properties;
99
using System;
@@ -17,7 +17,7 @@ namespace PolylineAlgorithm.Validation;
1717
/// </summary>
1818
[DebuggerDisplay("{ToString()}")]
1919
[StructLayout(LayoutKind.Sequential, Pack = 8, Size = 16)]
20-
public readonly struct CoordinateRange : IEquatable<CoordinateRange> {
20+
internal readonly struct CoordinateRange : IEquatable<CoordinateRange> {
2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="CoordinateRange"/> struct with <see cref="Min"/>
2323
/// set to <see cref="double.MinValue"/> and <see cref="Max"/> set to <see cref="double.MaxValue"/>.

src/PolylineAlgorithm/Validation/CoordinateValidator.cs renamed to src/PolylineAlgorithm/Internal/CoordinateValidator.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
44
//
55

6-
namespace PolylineAlgorithm.Validation;
6+
namespace PolylineAlgorithm.Internal;
7+
8+
using PolylineAlgorithm;
9+
using PolylineAlgorithm.Validation;
710

811
/// <summary>
912
/// Provides functionality to validate geographic coordinates based on specified latitude and longitude ranges.
1013
/// Implements the <see cref="ICoordinateValidator"/> interface.
1114
/// </summary>
12-
public sealed class CoordinateValidator : ICoordinateValidator {
15+
internal sealed class CoordinateValidator : ICoordinateValidator {
1316
/// <summary>
1417
/// Initializes a new instance of the <see cref="CoordinateValidator"/> class with the specified latitude and longitude ranges.
1518
/// </summary>
@@ -38,9 +41,7 @@ public CoordinateValidator(CoordinateRange latitudeRange, CoordinateRange longit
3841
/// <see langword="true"/> if the <paramref name="coordinate"/> is within the valid latitude and longitude ranges;
3942
/// otherwise, <see langword="false"/>.
4043
/// </returns>
41-
public bool IsValid(Coordinate coordinate) {
42-
return
43-
Latitude.IsInRange(coordinate.Latitude)
44+
public bool IsValid(Coordinate coordinate) =>
45+
Latitude.IsInRange(coordinate.Latitude)
4446
&& Longitude.IsInRange(coordinate.Longitude);
45-
}
4647
}

src/PolylineAlgorithm/Internal/CoordinateVariance.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// This struct is used to calculate and store the differences between coordinate values.
1111
/// </summary>
1212
[DebuggerDisplay($"{{{nameof(ToString)}(),nq}}")]
13-
[StructLayout(LayoutKind.Auto)]
13+
[StructLayout(LayoutKind.Sequential, Pack = 4, Size = 8)]
1414
internal struct CoordinateVariance {
1515
private (int Latitude, int Longitude) _current = (0, 0);
1616

src/PolylineAlgorithm/Internal/Defaults.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
//
55

66
namespace PolylineAlgorithm.Internal;
7-
8-
using PolylineAlgorithm.Validation;
97
using System.Diagnostics.CodeAnalysis;
108

119
/// <summary>
@@ -53,7 +51,7 @@ public static class Polyline {
5351
/// An array of delimiters used in the polyline encoding process.
5452
/// Each delimiter is derived by adding the ASCII value of the question mark ('?') to a range of integers.
5553
/// </summary>
56-
public static readonly byte[] Delimiters = [.. Enumerable.Range(0, 32).Select(n => (byte)(n + Defaults.Algorithm.QuestionMark))];
54+
public static readonly byte[] Delimiters = [.. Enumerable.Range(0, 32).Select(n => (byte)(n + Algorithm.QuestionMark))];
5755

5856
/// <summary>
5957
/// The minimum length of an encoded coordinate in the polyline format.

src/PolylineAlgorithm/Polyline.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public override string ToString() {
8989
return Value.FirstSpan.ToString();
9090
}
9191

92-
var sb = Value.Length <= int.MaxValue ? new StringBuilder((int)(Value.Length)) : new StringBuilder();
92+
var sb = Value.Length <= int.MaxValue ? new StringBuilder((int)Value.Length) : new StringBuilder();
9393
var enumerator = Value.GetEnumerator();
9494

9595
while (true) {

src/PolylineAlgorithm/PolylineEncoder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace PolylineAlgorithm;
77

88
using PolylineAlgorithm.Abstraction;
99
using PolylineAlgorithm.Internal;
10+
using PolylineAlgorithm.Properties;
1011
using System;
1112
using System.Collections.Generic;
1213
using System.Runtime.CompilerServices;
@@ -42,7 +43,7 @@ public Polyline Encode(IEnumerable<Coordinate> coordinates) {
4243
int count = GetCount(coordinates);
4344

4445
if (count == 0) {
45-
throw new ArgumentException(nameof(coordinates));
46+
throw new ArgumentException(ExceptionMessageResource.ArgumentCannotBeEmptyEnumerationMessage, nameof(coordinates));
4647
}
4748

4849
CoordinateVariance variance = new();
@@ -82,7 +83,7 @@ public Polyline Encode(IEnumerable<Coordinate> coordinates) {
8283
}
8384

8485
builder
85-
.Append(buffer[..position].ToString().AsMemory());
86+
.Append(buffer[..position].ToArray().AsMemory());
8687

8788
return builder.Build();
8889

src/PolylineAlgorithm/Validation/ICoordinateValidator.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace PolylineAlgorithm.Validation;
1212
/// against predefined valid ranges.
1313
/// </summary>
1414
public interface ICoordinateValidator {
15-
/// <summary>
16-
/// Gets the range within which the latitude value is considered valid.
17-
/// </summary>
18-
CoordinateRange Latitude { get; }
15+
///// <summary>
16+
///// Gets the range within which the latitude value is considered valid.
17+
///// </summary>
18+
//CoordinateRange Latitude { get; }
1919

20-
/// <summary>
21-
/// Gets the range within which the longitude value is considered valid.
22-
/// </summary>
23-
CoordinateRange Longitude { get; }
20+
///// <summary>
21+
///// Gets the range within which the longitude value is considered valid.
22+
///// </summary>
23+
//CoordinateRange Longitude { get; }
2424

2525
/// <summary>
2626
/// Determines whether the specified coordinate is valid based on the latitude and longitude ranges.
@@ -32,8 +32,10 @@ public interface ICoordinateValidator {
3232
/// </returns>
3333
bool IsValid(Coordinate coordinate);
3434

35+
static void SetDefault(ICoordinateValidator validator) => Default = validator ?? throw new ArgumentNullException(nameof(validator));
36+
3537
/// <summary>
3638
/// Gets the default coordinate validator instance.
3739
/// </summary>
38-
internal static ICoordinateValidator Default { get; } = new CoordinateValidator(Defaults.Coordinate.Range.Latitude, Defaults.Coordinate.Range.Longitude);
40+
internal static ICoordinateValidator Default { get; private set; } = new CoordinateValidator(Defaults.Coordinate.Range.Latitude, Defaults.Coordinate.Range.Longitude);
3941
}

tests/PolylineAlgorithm.Tests/Validation/CoordinateRangeTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace PolylineAlgorithm.Tests.Validation;
77

8-
using PolylineAlgorithm.Validation;
8+
using PolylineAlgorithm.Internal;
99

1010
/// <summary>
1111
/// Tests for the <see cref="CoordinateRange"/> type.

tests/PolylineAlgorithm.Tests/Validation/CoordinateValidatorTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace PolylineAlgorithm.Tests.Validation;
77

8-
using PolylineAlgorithm.Validation;
8+
using PolylineAlgorithm.Internal;
99

1010
/// <summary>
1111
/// Tests for the <see cref="CoordinateValidator"/> type.

0 commit comments

Comments
 (0)