Skip to content

Commit c1791eb

Browse files
committed
refactoring, simplification
1 parent 86d966f commit c1791eb

44 files changed

Lines changed: 320 additions & 1721 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/PolylineAlgorithm.Benchmarks/PolylineBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public class PolylineBenchmark {
5656
/// </summary>
5757
[GlobalSetup]
5858
public void SetupData() {
59-
PolylineValue = RandomValueProvider.GetPolyline(Count);
60-
PolylineNotEqualValue = RandomValueProvider.GetPolyline(Count + Random.Shared.Next(1, 101));
59+
PolylineValue = Polyline.FromString(RandomValueProvider.GetPolyline(Count));
60+
PolylineNotEqualValue = Polyline.FromString(RandomValueProvider.GetPolyline(Count + Random.Shared.Next(1, 101)));
6161
StringValue = PolylineValue.ToString();
6262
CharArrayValue = [.. StringValue];
6363
MemoryValue = CharArrayValue.AsMemory();

benchmarks/PolylineAlgorithm.Benchmarks/PolylineBuilderBenchmark.cs

Lines changed: 0 additions & 57 deletions
This file was deleted.

benchmarks/PolylineAlgorithm.Benchmarks/PolylineDecoderBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public class PolylineDecoderBenchmark {
3131
/// <summary>
3232
/// The polyline decoder instance.
3333
/// </summary>
34-
public PolylineDecoder Decoder = new();
34+
public CoordinateDecoder Decoder = new();
3535

3636
/// <summary>
3737
/// Sets up the data for the benchmarks.
3838
/// </summary>
3939
[GlobalSetup]
4040
public void SetupData() {
41-
Polyline = RandomValueProvider.GetPolyline(Count);
41+
Polyline = Polyline.FromString(RandomValueProvider.GetPolyline(Count));
4242
}
4343

4444
/// <summary>

benchmarks/PolylineAlgorithm.Benchmarks/PolylineEncoderBenchmark.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public class PolylineEncoderBenchmark {
3333
/// <summary>
3434
/// The polyline encoder instance.
3535
/// </summary>
36-
public PolylineEncoder Encoder = new();
36+
public CoordinateEncoder Encoder = new();
3737

3838
/// <summary>
3939
/// Sets up the data for the benchmarks.
4040
/// </summary>
4141
[GlobalSetup]
4242
public void SetupData() {
43-
Enumeration = RandomValueProvider.GetCoordinates(Count);
43+
Enumeration = RandomValueProvider.GetCoordinates(Count).Select(c => new Coordinate(c.Latitude, c.Longitude));
4444
List = [.. Enumeration];
4545
}
4646

benchmarks/PolylineAlgorithm.Benchmarks/Program.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
namespace PolylineAlgorithm.Benchmarks;
77

88
using BenchmarkDotNet.Configs;
9-
using BenchmarkDotNet.Engines;
109
using BenchmarkDotNet.Running;
11-
using Microsoft.CodeAnalysis;
1210

1311
/// <summary>
1412
/// The main entry point for the benchmark application.

samples/PolylineAlgorithm.NetTopologySuite.Sample/NetTopologyPolylineDecoder.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@
33
using global::NetTopologySuite.Geometries;
44
using PolylineAlgorithm.Abstraction;
55
using System;
6-
using System.Buffers;
7-
8-
internal class NetTopologyPolylineDecoder : PolylineDecoder<Point, string> {
9-
public override PolylineEncodingOptions<Point> Options { get; } = new PolylineEncodingOptions<Point>();
106

7+
internal class NetTopologyPolylineDecoder : PolylineDecoder<string, Point> {
118
protected override Point CreateCoordinate(double latitude, double longitude) {
129
return new Point(latitude, longitude);
1310
}
1411

15-
protected override ReadOnlySequence<char> GetReadOnlySequence(string? polyline) {
12+
protected override ReadOnlyMemory<char> GetReadOnlyMemory(string? polyline) {
1613
if (string.IsNullOrWhiteSpace(polyline)) {
1714
throw new ArgumentException("Value cannot be null, empty or whitespace.", nameof(polyline));
1815
}
1916

20-
return new(polyline.AsMemory());
17+
return polyline.AsMemory();
2118
}
2219
}

samples/PolylineAlgorithm.NetTopologySuite.Sample/NetTopologyPolylineEncoder.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@
66
using System.Text;
77

88
internal class NetTopologyPolylineEncoder : PolylineEncoder<Point, string> {
9-
public override PolylineEncodingOptions<Point> Options { get; } = new PolylineEncodingOptions<Point>();
109

11-
protected override string CreatePolyline(ReadOnlySequence<char> sequence) {
12-
if (sequence.IsEmpty) {
10+
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) {
11+
if (polyline.IsEmpty) {
1312
return string.Empty;
1413
}
1514

16-
if (sequence.IsSingleSegment) {
17-
return sequence.FirstSpan.ToString();
18-
}
19-
20-
var enumerator = sequence.GetEnumerator();
21-
var sb = new StringBuilder();
22-
23-
while (enumerator.MoveNext()) {
24-
sb.Append(enumerator.Current);
25-
}
26-
27-
return sb.ToString();
15+
return polyline.ToString();
2816
}
2917

3018
protected override double GetLatitude(Point? current) {

src/PolylineAlgorithm.Abstraction/IPolylineDecoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace PolylineAlgorithm.Abstraction;
1010
/// <summary>
1111
/// Defines a contract for decoding an encoded polyline into a collection of geographic coordinates.
1212
/// </summary>
13-
public interface IPolylineDecoder<TCoordinate, TPolyline> {
13+
public interface IPolylineDecoder<TPolyline, TCoordinate> {
1414
/// <summary>
1515
/// Decodes the specified encoded polyline into a sequence of geographic coordinates.
1616
/// </summary>
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
namespace PolylineAlgorithm.Abstraction;
22

3-
using PolylineAlgorithm.Abstraction.Validation.Abstraction;
4-
5-
public interface IPolylineEncodingOptionsBuilder<TCoordinate> {
6-
IPolylineEncodingOptionsBuilder<TCoordinate> WithBufferSize(int maxBufferSize);
7-
IPolylineEncodingOptionsBuilder<TCoordinate> WithValidator(Validator<TCoordinate> validator);
8-
PolylineEncodingOptions<TCoordinate> Build();
3+
public interface IPolylineEncodingOptionsBuilder {
4+
IPolylineEncodingOptionsBuilder WithBufferSize(int maxBufferSize);
5+
PolylineEncodingOptions Build();
96
}

src/PolylineAlgorithm.Abstraction/Internal/PolylineBuilder.cs

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)