Skip to content

Commit 54477f3

Browse files
Copilotpetesramek
andauthored
fix: update stale XML comments and restore PolylineEncoderBenchmark
- Replace <see cref="Coordinate"/> and <see cref="Polyline"/> references in RandomValueProvider.cs and StaticValueProvider.cs with plain descriptions (those types no longer exist) - Add missing <param name="cancellationToken"> tag in AbstractPolylineEncoder.Encode (fixes CS1573 warning) - Uncomment and rewrite PolylineEncoderBenchmark.cs: add StringPolylineEncoder inner class, fix broken _encoder references in Span/Array/List benchmarks, align with IPolylineEncoder<TCoordinate, TPolyline> generic API Agent-Logs-Url: https://github.com/petesramek/polyline-algorithm-csharp/sessions/cd24bd09-954c-4853-95b0-1d634853b58a Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com>
1 parent ed35442 commit 54477f3

4 files changed

Lines changed: 104 additions & 112 deletions

File tree

Lines changed: 92 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,92 @@
1-
////
2-
//// Copyright © Pete Sramek. All rights reserved.
3-
//// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4-
////
5-
6-
//namespace PolylineAlgorithm.Benchmarks;
7-
8-
//using BenchmarkDotNet.Attributes;
9-
//using BenchmarkDotNet.Engines;
10-
//using PolylineAlgorithm.Utility;
11-
//using System.Collections.Generic;
12-
13-
///// <summary>
14-
///// Benchmarks for <see cref="PolylineEncoder"/>.
15-
///// </summary>
16-
//public class PolylineEncoderBenchmark {
17-
// private readonly Consumer _consumer = new();
18-
19-
// /// <summary>
20-
// /// Number of coordinates for benchmarks.
21-
// /// </summary>
22-
// [Params(1, 100, 1_000)]
23-
// public int CoordinatesCount { get; set; }
24-
25-
//#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
26-
// /// <summary>
27-
// /// Coordinates as list.
28-
// /// </summary>
29-
// public List<(double Latitude, double Longitude)> List { get; private set; }
30-
31-
// /// <summary>
32-
// /// Coordinates as array.
33-
// /// </summary>
34-
// public (double Latitude, double Longitude)[] Array { get; private set; }
35-
36-
// /// <summary>
37-
// /// Coordinates as read-only memory.
38-
// /// </summary>
39-
// public ReadOnlyMemory<(double Latitude, double Longitude)> Memory { get; private set; }
40-
41-
//#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
42-
43-
// /// <summary>
44-
// /// Polyline encoder instance.
45-
// /// </summary>
46-
// private readonly StringPolylineEncoder _stringEncoder = new();
47-
48-
// /// <summary>
49-
// /// Polyline encoder instance.
50-
// /// </summary>
51-
// private readonly CharArrayPolylineEncoder _charArrayEncoder = new();
52-
53-
// /// <summary>
54-
// /// Polyline encoder instance.
55-
// /// </summary>
56-
// private readonly MemoryPolylineEncoder _memoryEncoder = new();
57-
58-
// /// <summary>
59-
// /// Sets up benchmark data.
60-
// /// </summary>
61-
// [GlobalSetup]
62-
// public void SetupData() {
63-
// List = [.. RandomValueProvider.GetCoordinates(CoordinatesCount).Select(c => (c.Latitude, c.Longitude))];
64-
// Array = [.. List];
65-
// Memory = Array.AsMemory();
66-
// }
67-
68-
// /// <summary>
69-
// /// Benchmark: encode coordinates from span.
70-
// /// </summary>
71-
// /// <returns>Encoded polyline.</returns>
72-
// [Benchmark]
73-
// public void PolylineEncoder_Encode_Span() {
74-
// var polyline = _encoder
75-
// .Encode(Memory.Span!);
76-
77-
// _consumer.Consume(polyline);
78-
// }
79-
80-
// /// <summary>
81-
// /// Benchmark: encode coordinates from array.
82-
// /// </summary>
83-
// /// <returns>Encoded polyline.</returns>
84-
// [Benchmark]
85-
// public void PolylineEncoder_Encode_Array() {
86-
// var polyline = _encoder
87-
// .Encode(Array!);
88-
89-
// _consumer.Consume(polyline);
90-
// }
91-
92-
// /// <summary>
93-
// /// Benchmark: encode coordinates from list.
94-
// /// </summary>
95-
// /// <returns>Encoded polyline.</returns>
96-
// [Benchmark]
97-
// public void PolylineEncoder_Encode_List() {
98-
// var polyline = _encoder
99-
// .Encode(List!);
100-
101-
// _consumer.Consume(polyline);
102-
// }
103-
//}
1+
//
2+
// Copyright © Pete Sramek. All rights reserved.
3+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace PolylineAlgorithm.Benchmarks;
7+
8+
using BenchmarkDotNet.Attributes;
9+
using BenchmarkDotNet.Engines;
10+
using PolylineAlgorithm.Abstraction;
11+
using PolylineAlgorithm.Extensions;
12+
using PolylineAlgorithm.Utility;
13+
using System.Collections.Generic;
14+
15+
/// <summary>
16+
/// Benchmarks for <see cref="AbstractPolylineEncoder{TCoordinate, TPolyline}"/>.
17+
/// </summary>
18+
public class PolylineEncoderBenchmark {
19+
private readonly Consumer _consumer = new();
20+
21+
/// <summary>
22+
/// Number of coordinates for benchmarks.
23+
/// </summary>
24+
[Params(1, 100, 1_000)]
25+
public int CoordinatesCount { get; set; }
26+
27+
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
28+
/// <summary>
29+
/// Coordinates as list.
30+
/// </summary>
31+
public List<(double Latitude, double Longitude)> List { get; private set; }
32+
33+
/// <summary>
34+
/// Coordinates as array.
35+
/// </summary>
36+
public (double Latitude, double Longitude)[] Array { get; private set; }
37+
38+
/// <summary>
39+
/// Coordinates as read-only memory.
40+
/// </summary>
41+
public ReadOnlyMemory<(double Latitude, double Longitude)> Memory { get; private set; }
42+
43+
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
44+
45+
/// <summary>
46+
/// Polyline encoder instance.
47+
/// </summary>
48+
private readonly StringPolylineEncoder _encoder = new();
49+
50+
/// <summary>
51+
/// Sets up benchmark data.
52+
/// </summary>
53+
[GlobalSetup]
54+
public void SetupData() {
55+
List = [.. RandomValueProvider.GetCoordinates(CoordinatesCount)];
56+
Array = [.. List];
57+
Memory = Array.AsMemory();
58+
}
59+
60+
/// <summary>
61+
/// Benchmark: encode coordinates from span.
62+
/// </summary>
63+
[Benchmark]
64+
public void PolylineEncoder_Encode_Span() {
65+
var polyline = _encoder.Encode(Memory.Span);
66+
_consumer.Consume(polyline);
67+
}
68+
69+
/// <summary>
70+
/// Benchmark: encode coordinates from array.
71+
/// </summary>
72+
[Benchmark]
73+
public void PolylineEncoder_Encode_Array() {
74+
var polyline = _encoder.Encode(Array);
75+
_consumer.Consume(polyline);
76+
}
77+
78+
/// <summary>
79+
/// Benchmark: encode coordinates from list.
80+
/// </summary>
81+
[Benchmark]
82+
public void PolylineEncoder_Encode_List() {
83+
var polyline = _encoder.Encode(List);
84+
_consumer.Consume(polyline);
85+
}
86+
87+
private sealed class StringPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string> {
88+
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) => polyline.ToString();
89+
protected override double GetLatitude((double Latitude, double Longitude) current) => current.Latitude;
90+
protected override double GetLongitude((double Latitude, double Longitude) current) => current.Longitude;
91+
}
92+
}

src/PolylineAlgorithm/Abstraction/AbstractPolylineEncoder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ protected AbstractPolylineEncoder(PolylineEncodingOptions options) {
6161
/// <param name="coordinates">
6262
/// The collection of <typeparamref name="TCoordinate"/> objects to encode.
6363
/// </param>
64+
/// <param name="cancellationToken">
65+
/// A <see cref="CancellationToken"/> that can be used to cancel the encoding operation.
66+
/// </param>
6467
/// <returns>
6568
/// An instance of <typeparamref name="TPolyline"/> representing the encoded coordinates.
6669
/// </returns>

utilities/PolylineAlgorithm.Utility/RandomValueProvider.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ internal static class RandomValueProvider {
2323
private static readonly PolylineEncoder _encoder = new();
2424

2525
/// <summary>
26-
/// Gets a collection of random <see cref="Coordinate"/> instances of the specified count.
26+
/// Gets a collection of random latitude/longitude tuples of the specified count.
2727
/// The same collection is cached and reused for the same count value.
2828
/// </summary>
2929
/// <param name="count">The number of coordinates to generate.</param>
30-
/// <returns>An enumerable collection of random <see cref="Coordinate"/> objects.</returns>
30+
/// <returns>An enumerable collection of random latitude/longitude tuples.</returns>
3131
public static IEnumerable<(double Latitude, double Longitude)> GetCoordinates(int count) {
3232
var entry = GetCaheEntry(count);
3333

@@ -39,11 +39,11 @@ internal static class RandomValueProvider {
3939
}
4040

4141
/// <summary>
42-
/// Gets a <see cref="Polyline"/> representing the encoded polyline for a random collection of coordinates of the specified count.
42+
/// Gets the encoded polyline string for a random collection of coordinates of the specified count.
4343
/// The same polyline is cached and reused for the same count value.
4444
/// </summary>
4545
/// <param name="count">The number of coordinates to generate and encode.</param>
46-
/// <returns>A <see cref="Polyline"/> representing the encoded polyline.</returns>
46+
/// <returns>A <see cref="string"/> representing the encoded polyline.</returns>
4747
public static string GetPolyline(int count) {
4848
var entry = GetCaheEntry(count);
4949

utilities/PolylineAlgorithm.Utility/StaticValueProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal static class Valid {
1818
private const string Polyline = "???_gsia@_cidP??~fsia@?~fsia@~bidP?~bidP??_gsia@";
1919

2020
/// <summary>
21-
/// A predefined collection of <see cref="Coordinate"/> instances representing a closed path around the globe.
21+
/// A predefined collection of latitude/longitude tuples representing a closed path around the globe.
2222
/// </summary>
2323
private static readonly IEnumerable<(double Latitude, double Longitude)> _coordinates = [
2424
new (0, 0),
@@ -32,17 +32,17 @@ internal static class Valid {
3232
];
3333

3434
/// <summary>
35-
/// Gets the predefined collection of <see cref="Coordinate"/> instances.
35+
/// Gets the predefined collection of latitude/longitude tuples.
3636
/// </summary>
37-
/// <returns>An <see cref="IEnumerable{Coordinate}"/> containing the static coordinates.</returns>
37+
/// <returns>An <see cref="IEnumerable{T}"/> of latitude/longitude tuples containing the static coordinates.</returns>
3838
public static IEnumerable<(double Latitude, double Longitude)> GetCoordinates() {
3939
return _coordinates;
4040
}
4141

4242
/// <summary>
43-
/// Gets the predefined <see cref="PolylineAlgorithm.Polyline"/> instance.
43+
/// Gets the predefined encoded polyline string.
4444
/// </summary>
45-
/// <returns>The static <see cref="PolylineAlgorithm.Polyline"/> value.</returns>
45+
/// <returns>The static encoded polyline string.</returns>
4646
public static string GetPolyline() {
4747
return Polyline;
4848
}

0 commit comments

Comments
 (0)