Skip to content

Commit b895ea5

Browse files
committed
updates
1 parent 7499169 commit b895ea5

31 files changed

Lines changed: 211 additions & 1199 deletions

benchmarks/PolylineAlgorithm.Benchmarks/PolylineDecoderBenchmark.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace PolylineAlgorithm.Benchmarks;
1111
using PolylineAlgorithm.Utility;
1212

1313
/// <summary>
14-
/// Benchmarks for <see cref="PolylineDecoder{TPolyline, TCoordinate}"/>.
14+
/// Benchmarks for <see cref="PolylineDecoder{TPolyline, TValue}"/>.
1515
/// </summary>
1616
public class PolylineDecoderBenchmark {
1717
private readonly Consumer _consumer = new();
@@ -57,8 +57,8 @@ public class PolylineDecoderBenchmark {
5757
FormatterBuilder<(double Latitude, double Longitude), T>.Create()
5858
.AddValue("lat", static c => c.Latitude)
5959
.AddValue("lon", static c => c.Longitude)
60-
.WithCreate(static v => (v[0], v[1]))
61-
.ForPolyline(write, read)
60+
.WithValueFactory(static v => (v[0], v[1]))
61+
.WithReaderWriter(write, read)
6262
.Build();
6363

6464
private static PolylineDecoder<string, (double Latitude, double Longitude)> CreateStringDecoder() {

benchmarks/PolylineAlgorithm.Benchmarks/PolylineEncoderBenchmark.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ namespace PolylineAlgorithm.Benchmarks;
33
using BenchmarkDotNet.Attributes;
44
using BenchmarkDotNet.Engines;
55
using PolylineAlgorithm;
6-
using PolylineAlgorithm.Extensions;
76
using PolylineAlgorithm.Utility;
8-
using System.Collections.Generic;
97

108
/// <summary>
11-
/// Benchmarks for <see cref="PolylineEncoder{TCoordinate, TPolyline}"/>.
9+
/// Benchmarks for <see cref="PolylineEncoder{TValue, TPolyline}"/>.
1210
/// </summary>
1311
public class PolylineEncoderBenchmark {
1412
private readonly Consumer _consumer = new();
@@ -20,11 +18,6 @@ public class PolylineEncoderBenchmark {
2018
public int CoordinatesCount { get; set; }
2119

2220
#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.
23-
/// <summary>
24-
/// Coordinates as list.
25-
/// </summary>
26-
public List<(double Latitude, double Longitude)> List { get; private set; }
27-
2821
/// <summary>
2922
/// Coordinates as array.
3023
/// </summary>
@@ -47,7 +40,7 @@ public class PolylineEncoderBenchmark {
4740
FormatterBuilder<(double Latitude, double Longitude), string>.Create()
4841
.AddValue("lat", static c => c.Latitude)
4942
.AddValue("lon", static c => c.Longitude)
50-
.ForPolyline(static m => new string(m.Span), static s => s.AsMemory())
43+
.WithReaderWriter(static m => new string(m.Span), static s => s.AsMemory())
5144
.Build();
5245

5346
return new PolylineEncoder<(double Latitude, double Longitude), string>(
@@ -59,8 +52,7 @@ public class PolylineEncoderBenchmark {
5952
/// </summary>
6053
[GlobalSetup]
6154
public void SetupData() {
62-
List = [.. RandomValueProvider.GetCoordinates(CoordinatesCount)];
63-
Array = [.. List];
55+
Array = [.. RandomValueProvider.GetCoordinates(CoordinatesCount)];
6456
Memory = Array.AsMemory();
6557
}
6658

@@ -81,13 +73,4 @@ public void PolylineEncoder_Encode_Array() {
8173
var polyline = _encoder.Encode(Array);
8274
_consumer.Consume(polyline);
8375
}
84-
85-
/// <summary>
86-
/// Benchmark: encode coordinates from list.
87-
/// </summary>
88-
[Benchmark]
89-
public void PolylineEncoder_Encode_List() {
90-
var polyline = _encoder.Encode(List);
91-
_consumer.Consume(polyline);
92-
}
9376
}

samples/PolylineAlgorithm.NetTopologySuite.Sample/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public static void Main(string[] args) {
1515
.AddValue("lat", static p => p.Y)
1616
.AddValue("lon", static p => p.X)
1717
// The formatter automatically denormalizes scaled values, so v[0] = latitude, v[1] = longitude.
18-
.WithCreate(static v => new Point(x: v[1], y: v[0]))
19-
.ForPolyline(
18+
.WithValueFactory(static v => new Point(x: v[1], y: v[0]))
19+
.WithReaderWriter(
2020
static m => m.IsEmpty ? string.Empty : new string(m.Span),
2121
static s => s.AsMemory())
2222
.Build();

samples/PolylineAlgorithm.SensorData.Sample/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ public static void Main(string[] args) {
2121
.SetBaseline(TimestampBaseEpoch)
2222
.AddValue("temperature", static r => r.Temperature, precision: 5)
2323
// The formatter automatically denormalizes: v[0] = Unix seconds, v[1] = temperature.
24-
.WithCreate(static v => new SensorReading(
24+
.WithValueFactory(static v => new SensorReading(
2525
DateTimeOffset.FromUnixTimeSeconds((long)v[0]),
2626
v[1]))
27-
.ForPolyline(static m => new string(m.Span), static s => s.AsMemory())
27+
.WithReaderWriter(static m => new string(m.Span), static s => s.AsMemory())
2828
.Build();
2929

3030
PolylineOptions<SensorReading, string> options = new(formatter);

src/PolylineAlgorithm/Abstraction/IChunkedPolylineDecoder.cs

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

src/PolylineAlgorithm/Abstraction/IChunkedPolylineEncoder.cs

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

src/PolylineAlgorithm/Abstraction/IPolylineDecoder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace PolylineAlgorithm.Abstraction;
1919
/// The coordinate type returned by the decoder. Typical implementations return a struct or class that
2020
/// contains latitude and longitude (for example a <c>LatLng</c> type or a <c>ValueTuple&lt;double,double&gt;</c>).
2121
/// </typeparam>
22-
public interface IPolylineDecoder<TPolyline, out TValue> {
22+
public interface IPolylineDecoder<TPolyline, TValue> {
2323
/// <summary>
2424
/// Decodes the specified encoded polyline into an ordered sequence of geographic coordinates.
2525
/// The sequence preserves the original vertex order encoded by the <paramref name="polyline"/>.
@@ -45,5 +45,5 @@ public interface IPolylineDecoder<TPolyline, out TValue> {
4545
/// <exception cref="OperationCanceledException">
4646
/// Thrown when the provided <paramref name="cancellationToken"/> requests cancellation.
4747
/// </exception>
48-
IEnumerable<TValue> Decode(TPolyline polyline, CancellationToken cancellationToken = default);
48+
IEnumerable<TValue> Decode(TPolyline polyline, PolylineDecodingOptions<TValue>? options = null, CancellationToken cancellationToken = default);
4949
}

src/PolylineAlgorithm/Abstraction/IPolylineEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ public interface IPolylineEncoder<TValue, TPolyline> {
7373
/// <exception cref="System.OperationCanceledException">
7474
/// Thrown if the operation is canceled via <paramref name="cancellationToken"/>.
7575
/// </exception>
76-
TPolyline Encode(ReadOnlySpan<TValue> coordinates, CancellationToken cancellationToken = default);
76+
TPolyline Encode(ReadOnlySpan<TValue> coordinates, PolylineEncodingOptions<TValue>? options = null, CancellationToken cancellationToken = default);
7777
}

src/PolylineAlgorithm/Abstraction/IPolylineFormatter.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ namespace PolylineAlgorithm.Abstraction;
88
using System;
99

1010
/// <summary>
11-
/// Defines how to extract and scale values from a <typeparamref name="TCoordinate"/> for encoding,
12-
/// reconstruct a <typeparamref name="TCoordinate"/> from scaled values for decoding,
11+
/// Defines how to extract and scale values from a <typeparamref name="TValue"/> for encoding,
12+
/// reconstruct a <typeparamref name="TValue"/> from scaled values for decoding,
1313
/// produce a <typeparamref name="TPolyline"/> from an encoded character buffer, and extract that buffer
1414
/// back from a <typeparamref name="TPolyline"/>.
1515
/// </summary>
16-
/// <typeparam name="TCoordinate">The coordinate or item type. For example a struct with Latitude/Longitude.</typeparam>
16+
/// <typeparam name="TValue">The coordinate or item type. For example a struct with Latitude/Longitude.</typeparam>
1717
/// <typeparam name="TPolyline">The polyline surface type. For example <see cref="string"/> or
1818
/// <see cref="ReadOnlyMemory{T}"/> of <see cref="char"/>.</typeparam>
1919
/// <remarks>
20-
/// Use <see cref="FormatterBuilder{TCoordinate, TPolyline}"/> to build a
21-
/// <see cref="PolylineFormatter{TCoordinate, TPolyline}"/> that implements this interface.
20+
/// Use <see cref="FormatterBuilder{TValue, TPolyline}"/> to build a
21+
/// <see cref="PolylineFormatter{TValue, TPolyline}"/> that implements this interface.
2222
/// </remarks>
23-
public interface IPolylineFormatter<TCoordinate, TPolyline> {
23+
public interface IPolylineFormatter<TValue, TPolyline> {
2424
/// <summary>
2525
/// Gets the number of values (columns) per encoded item.
2626
/// This is the required length of the <see cref="Span{T}"/> passed to <see cref="GetValues"/>
@@ -45,7 +45,7 @@ public interface IPolylineFormatter<TCoordinate, TPolyline> {
4545
/// <param name="values">
4646
/// Output buffer that receives the scaled integer values. Its length must equal <see cref="Width"/>.
4747
/// </param>
48-
void GetValues(TCoordinate item, Span<long> values);
48+
void GetValues(TValue item, Span<long> values);
4949

5050
/// <summary>
5151
/// Creates a <typeparamref name="TPolyline"/> from the encoded character buffer produced by the encoder.
@@ -62,7 +62,7 @@ public interface IPolylineFormatter<TCoordinate, TPolyline> {
6262
ReadOnlyMemory<char> Read(TPolyline polyline);
6363

6464
/// <summary>
65-
/// Reconstructs a <typeparamref name="TCoordinate"/> from the given accumulated scaled integer values.
65+
/// Reconstructs a <typeparamref name="TValue"/> from the given accumulated scaled integer values.
6666
/// Called once per decoded item in the decoding loop. Implementations are responsible for
6767
/// denormalizing the raw scaled integers (e.g. dividing by the precision factor and adding back
6868
/// any baseline) before constructing the item.
@@ -72,6 +72,6 @@ public interface IPolylineFormatter<TCoordinate, TPolyline> {
7272
/// the same column position as in <see cref="GetValues"/>. These are the direct output of the
7373
/// delta-accumulation loop in the decoder before any denormalization is applied.
7474
/// </param>
75-
/// <returns>A <typeparamref name="TCoordinate"/> reconstructed from <paramref name="values"/>.</returns>
76-
TCoordinate CreateItem(ReadOnlySpan<long> values);
75+
/// <returns>A <typeparamref name="TValue"/> reconstructed from <paramref name="values"/>.</returns>
76+
TValue CreateItem(ReadOnlySpan<long> values);
7777
}

0 commit comments

Comments
 (0)