Skip to content

Commit 730c70b

Browse files
authored
docs: improve README user-friendliness for repo and NuGet package (#220)
- [x] Understand existing NTS sample pattern and abstract encoder/decoder structure - [x] Create `samples/PolylineAlgorithm.SensorData.Sample/` project with `SensorDataEncoder`, `SensorDataDecoder`, `SensorReading`, `Program.cs` - [x] Make both sample projects console apps (`OutputType=Exe`, `net10.0`) - [x] Register sensor data project in `PolylineAlgorithm.slnx` - [x] Inline `DecodeIterator` body directly into `Decode`, remove the separate method (suppress S4456) - [x] Encode/decode `Timestamp` as Unix epoch seconds (precision 0) — each reading encodes a [timestamp_delta, temperature_delta] pair - Base epoch 2020-01-01 UTC (1,577,836,800 s) used to keep first delta within int32 safe range of the polyline algorithm - `SensorDataEncoder.TimestampBaseEpochSeconds` constant shared by both encoder and decoder - [x] Update `Program.cs` to display recovered timestamps in decoded output - [x] Build verified — 0 errors, 0 warnings
1 parent 31a7240 commit 730c70b

27 files changed

Lines changed: 450 additions & 2096 deletions

PolylineAlgorithm.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</Folder>
88
<Folder Name="/samples/">
99
<Project Path="samples/PolylineAlgorithm.NetTopologySuite.Sample/PolylineAlgorithm.NetTopologySuite.Sample.csproj" Id="27a8fc47-0a3c-49c7-af5e-530514827785" />
10+
<Project Path="samples/PolylineAlgorithm.SensorData.Sample/PolylineAlgorithm.SensorData.Sample.csproj" />
1011
</Folder>
1112
<Folder Name="/src/">
1213
<Project Path="src/PolylineAlgorithm/PolylineAlgorithm.csproj" />

README.md

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# PolylineAlgorithm for .NET
22

3-
Lightweight .NET Standard 2.1 library implementing Google-compliant Encoded Polyline Algorithm with strong input validation, modern API patterns, and extensibility for custom coordinate types.
3+
[![NuGet](https://img.shields.io/nuget/v/PolylineAlgorithm)](https://www.nuget.org/packages/PolylineAlgorithm)
4+
[![Build](https://github.com/petesramek/polyline-algorithm-csharp/actions/workflows/build.yml/badge.svg)](https://github.com/petesramek/polyline-algorithm-csharp/actions/workflows/build.yml)
5+
[![License: MIT](https://img.shields.io/github/license/petesramek/polyline-algorithm-csharp)](./LICENSE)
6+
7+
Google's Encoded Polyline Algorithm compresses sequences of geographic coordinates into a compact ASCII string, widely used in mapping APIs. This library provides a fully compliant .NET implementation with extensible, type-safe encoding and decoding APIs.
48

59
## Table of Contents
610

@@ -17,15 +21,16 @@ Lightweight .NET Standard 2.1 library implementing Google-compliant Encoded Poly
1721
## Features
1822

1923
- Fully compliant Google Encoded Polyline Algorithm for .NET Standard 2.1+
20-
- Extensible encoding and decoding APIs for custom coordinate and polyline types (`IPolylineEncoder<TCoordinate, TPolyline>`, `IPolylineDecoder<TPolyline, TCoordinate>`, `AbstractPolylineEncoder<TCoordinate, TPolyline>`, `AbstractPolylineDecoder<TPolyline, TCoordinate>`)
21-
- Extension methods for encoding from `List<T>` and arrays (`PolylineEncoderExtensions`)
22-
- Robust input validation with descriptive exceptions for malformed/invalid data
24+
- Extensible APIs — implement your own encoder/decoder for any coordinate or polyline type
25+
- Robust input validation with descriptive exceptions for malformed or out-of-range data
2326
- Advanced configuration via `PolylineEncodingOptions` (precision, buffer size, logging)
24-
- Logging and diagnostic support for CI/CD and developer diagnostics via `Microsoft.Extensions.Logging`
25-
- Low-level utilities for normalization, validation, encoding and decoding via static `PolylineEncoding` class
27+
- Extension methods for encoding directly from `List<T>` and arrays
28+
- Logging and diagnostic support via `Microsoft.Extensions.Logging`
29+
- Low-level utilities for normalization, validation, and bit-level operations via static `PolylineEncoding` class
30+
- Thread-safe, stateless APIs
2631
- Thorough unit tests and benchmarks for correctness and performance
2732
- Auto-generated API documentation ([API Reference](https://petesramek.github.io/polyline-algorithm-csharp/))
28-
- Support for .NET Core, .NET 5+, Xamarin, Unity, Blazor, and other platforms supporting `netstandard2.1`
33+
- Supports .NET Core, .NET 5+, Xamarin, Unity, Blazor, and any platform targeting `netstandard2.1`
2934

3035
## Installation
3136

@@ -43,7 +48,19 @@ Install-Package PolylineAlgorithm
4348

4449
## Usage
4550

46-
The library provides abstract base classes to implement your own encoder and decoder for any coordinate and polyline type.
51+
The library provides abstract base classes to implement your own encoder and decoder for any coordinate and polyline type. Inherit from `AbstractPolylineEncoder` or `AbstractPolylineDecoder`, override the coordinate accessors, then call `Encode` or `Decode`.
52+
53+
### Quick Start
54+
55+
```csharp
56+
// 1. Implement a minimal encoder (see full example below)
57+
var encoder = new MyPolylineEncoder();
58+
string encoded = encoder.Encode(coordinates); // e.g. "yseiHoc_MwacOjnwM"
59+
60+
// 2. Implement a minimal decoder (see full example below)
61+
var decoder = new MyPolylineDecoder();
62+
IEnumerable<(double Latitude, double Longitude)> decoded = decoder.Decode(encoded);
63+
```
4764

4865
### Custom encoder and decoder
4966

@@ -56,23 +73,9 @@ using PolylineAlgorithm;
5673
using PolylineAlgorithm.Abstraction;
5774

5875
public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string> {
59-
public MyPolylineEncoder()
60-
: base() { }
61-
62-
public MyPolylineEncoder(PolylineEncodingOptions options)
63-
: base(options) { }
64-
65-
protected override double GetLatitude((double Latitude, double Longitude) coordinate) {
66-
return coordinate.Latitude;
67-
}
68-
69-
protected override double GetLongitude((double Latitude, double Longitude) coordinate) {
70-
return coordinate.Longitude;
71-
}
72-
73-
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) {
74-
return polyline.ToString();
75-
}
76+
protected override double GetLatitude((double Latitude, double Longitude) coordinate) => coordinate.Latitude;
77+
protected override double GetLongitude((double Latitude, double Longitude) coordinate) => coordinate.Longitude;
78+
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) => polyline.ToString();
7679
}
7780
```
7881

@@ -102,19 +105,8 @@ using PolylineAlgorithm;
102105
using PolylineAlgorithm.Abstraction;
103106

104107
public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double Latitude, double Longitude)> {
105-
public MyPolylineDecoder()
106-
: base() { }
107-
108-
public MyPolylineDecoder(PolylineEncodingOptions options)
109-
: base(options) { }
110-
111-
protected override (double Latitude, double Longitude) CreateCoordinate(double latitude, double longitude) {
112-
return (latitude, longitude);
113-
}
114-
115-
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline) {
116-
return polyline.AsMemory();
117-
}
108+
protected override (double Latitude, double Longitude) CreateCoordinate(double latitude, double longitude) => (latitude, longitude);
109+
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline) => polyline.AsMemory();
118110
}
119111
```
120112

@@ -136,8 +128,13 @@ Full API docs and guides (auto-generated from source) are available at [API Refe
136128

137129
## Benchmarks
138130

139-
- See `/benchmarks` in the repo for performance evaluation.
140-
- Contributors: Update benchmarks and document results for performance-impacting PRs.
131+
- See [`/benchmarks`](./benchmarks) in the repo for benchmark projects.
132+
- Run benchmarks with:
133+
```shell
134+
dotnet run --project benchmarks/PolylineAlgorithm.Benchmarks --configuration Release
135+
```
136+
- For guidance on writing and interpreting benchmarks, see [docs/benchmarks.md](./docs/benchmarks.md).
137+
- Contributors: update benchmarks and document results for performance-impacting PRs.
141138

142139
## FAQ
143140

@@ -173,13 +170,13 @@ A: Currently, only batch encode/decode is supported. For streaming scenarios, im
173170

174171
## Contributing
175172

176-
- Follow code style and PR instructions in [AGENTS.md](./AGENTS.md).
173+
- Follow code style and PR instructions in [CONTRIBUTING.md](./CONTRIBUTING.md).
177174
- Ensure all features are covered by tests and XML doc comments.
178175
- For questions or suggestions, open an issue and use the provided templates.
179176

180177
## Support
181178

182-
Have a question, bug, or feature request? [Open an issue!](https://github.com/petesramek/polyline-algorithm-csharp/issues)
179+
Have a question, bug, or feature request? [Open an issue](https://github.com/petesramek/polyline-algorithm-csharp/issues/new/choose) — bug report and feature request templates are available to guide you.
183180

184181
---
185182

0 commit comments

Comments
 (0)