Skip to content

Commit d61bfe2

Browse files
Copilotpetesramek
andauthored
docs: update README files to reflect actual library API
Agent-Logs-Url: https://github.com/petesramek/polyline-algorithm-csharp/sessions/f5cc0ae1-daae-44ab-b12d-484350344272 Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com>
1 parent 1ee3127 commit d61bfe2

2 files changed

Lines changed: 70 additions & 69 deletions

File tree

README.md

Lines changed: 26 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ Lightweight .NET Standard 2.1 library implementing Google-compliant Encoded Poly
1717
## Features
1818

1919
- Fully compliant Google Encoded Polyline Algorithm for .NET Standard 2.1+
20-
- Immutable, strongly-typed coordinate and polyline data structures
21-
- Predefined encoder and decoder types for quick usage, extensibility for custom coordinate types
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`)
2222
- Robust input validation with descriptive exceptions for malformed/invalid data
23-
- Simple, extensible encoding and decoding APIs (`IPolylineEncoder<TCoordinate, TPolyline>`, `IPolylineDecoder<TPolyline, TCoordinate>`, `AbstractPolylineEncoder<TCoordinate, TPolyline>`, `AbstractPolylineDecoder<TPolyline, TCoordinate>`)
24-
- Default encoding and decoding implementations (`PolylineEncoder`, `PolylineDecoder`)
25-
- Advanced configuration via `PolylineEncodingOptions` (buffer size, logging, etc.)
26-
- Internal logging and diagnostic supports logging for CI/CD and developer diagnostics
23+
- 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
2726
- Thorough unit tests and benchmarks for correctness and performance
2827
- Auto-generated API documentation ([API Reference](https://petesramek.github.io/polyline-algorithm-csharp/))
2928
- Support for .NET Core, .NET 5+, Xamarin, Unity, Blazor, and other platforms supporting `netstandard2.1`
@@ -44,48 +43,23 @@ Install-Package PolylineAlgorithm
4443

4544
## Usage
4645

47-
### PolylineEncoder and PolylineDecoder (predefined `Coordinate` and `Polyline` types)
46+
The library provides abstract base classes to implement your own encoder and decoder for any coordinate and polyline type.
4847

49-
#### Encoding
50-
51-
```csharp
52-
using PolylineAlgorithm;
53-
54-
var coordinates = new List<Coordinate>
55-
{
56-
new Coordinate(48.858370, 2.294481),
57-
new Coordinate(51.500729, -0.124625)
58-
};
59-
60-
var encoder = new PolylineEncoder();
61-
Polyline encoded = encoder.Encode(coordinates);
62-
63-
Console.WriteLine(encoded.ToString());
64-
```
65-
66-
#### Decoding
67-
68-
```csharp
69-
using PolylineAlgorithm;
70-
71-
Polyline polyline = Polyline.FromString("yseiHoc_MwacOjnwM");
72-
73-
var decoder = new PolylineDecoder();
74-
IEnumerable<Coordinate> decoded = decoder.Decode(polyline);
75-
```
76-
77-
### Custom encoder and decoder (user-defined coordinate and polyline types)
48+
### Custom encoder and decoder
7849

7950
#### Encoding
8051

8152
Custom encoder implementation.
8253

8354
```csharp
55+
using PolylineAlgorithm;
56+
using PolylineAlgorithm.Abstraction;
57+
8458
public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string> {
85-
public PolylineEncoder()
59+
public MyPolylineEncoder()
8660
: base() { }
8761

88-
public PolylineEncoder(PolylineEncodingOptions options)
62+
public MyPolylineEncoder(PolylineEncodingOptions options)
8963
: base(options) { }
9064

9165
protected override double GetLatitude((double Latitude, double Longitude) coordinate) {
@@ -105,7 +79,7 @@ public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude
10579
Custom encoder usage.
10680

10781
```csharp
108-
using PolylineAlgorithm;
82+
using PolylineAlgorithm.Extensions;
10983

11084
var coordinates = new List<(double Latitude, double Longitude)>
11185
{
@@ -114,28 +88,31 @@ var coordinates = new List<(double Latitude, double Longitude)>
11488
};
11589

11690
var encoder = new MyPolylineEncoder();
117-
string encoded = encoder.Encode(coordinates);
91+
string encoded = encoder.Encode(coordinates); // extension method for List<T>
11892
119-
Console.WriteLine(encoded.ToString());
93+
Console.WriteLine(encoded);
12094
```
12195

12296
#### Decoding
12397

12498
Custom decoder implementation.
12599

126100
```csharp
101+
using PolylineAlgorithm;
102+
using PolylineAlgorithm.Abstraction;
103+
127104
public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double Latitude, double Longitude)> {
128-
public PolylineDecoder()
105+
public MyPolylineDecoder()
129106
: base() { }
130107

131-
public PolylineDecoder(PolylineEncodingOptions options)
108+
public MyPolylineDecoder(PolylineEncodingOptions options)
132109
: base(options) { }
133110

134111
protected override (double Latitude, double Longitude) CreateCoordinate(double latitude, double longitude) {
135112
return (latitude, longitude);
136113
}
137114

138-
protected override ReadOnlyMemory<char> GetReadOnlyMemory(ref string polyline) {
115+
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline) {
139116
return polyline.AsMemory();
140117
}
141118
}
@@ -144,8 +121,6 @@ public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double
144121
Custom decoder usage.
145122

146123
```csharp
147-
using PolylineAlgorithm;
148-
149124
string encoded = "yseiHoc_MwacOjnwM";
150125

151126
var decoder = new MyPolylineDecoder();
@@ -173,16 +148,16 @@ A: Latitude must be -90..90; longitude -180..180. Out-of-range input throws `Arg
173148
A: All platforms supporting `netstandard2.1` (including .NET Core and .NET 5+).
174149

175150
**Q: What happens if I pass invalid or malformed input to the decoder?**
176-
A: The decoder will throw descriptive exceptions for malformed polyline strings. Check exception handling in your application.
151+
A: The decoder will throw descriptive exceptions (`InvalidPolylineException`) for malformed polyline strings. Check exception handling in your application.
177152

178-
**Q: How do I customize encoding options (e.g., buffer size, logging)?**
179-
A: Use the PolylineEncodingOptionsBuilder to set custom options and pass to the PolylineEncoder constructor.
153+
**Q: How do I customize encoding options (e.g., precision, buffer size, logging)?**
154+
A: Use `PolylineEncodingOptionsBuilder` to set custom options and pass the built `PolylineEncodingOptions` to the encoder or decoder constructor.
180155

181156
**Q: Is the library thread-safe?**
182157
A: Yes, the main encoding and decoding APIs are stateless and thread-safe. If using mutable shared resources, manage synchronization in your code.
183158

184159
**Q: Can the library be used in Unity, Xamarin, Blazor, or other .NET-compatible platforms?**
185-
A: Yes! Any environment supporting netstandard2.1 can use this library.
160+
A: Yes! Any environment supporting `netstandard2.1` can use this library.
186161

187162
**Q: Where can I report bugs or request features?**
188163
A: Open a GitHub issue using the provided templates in the repository and tag @petesramek.
@@ -191,7 +166,7 @@ A: Open a GitHub issue using the provided templates in the repository and tag @p
191166
A: Not currently, not planned to be added, but you can extend by implementing your own encoder/decoder using `PolylineEncoding` class methods.
192167

193168
**Q: How do I contribute documentation improvements?**
194-
A: Update XML doc comments in the codebase and submit a PR; all public APIs require XML documentation. In case, you would like to improve guides you have to updage relevant markdown file in `/api-reference/guide` folder.
169+
A: Update XML doc comments in the codebase and submit a PR; all public APIs require XML documentation. To improve guides, update the relevant markdown file in the `/api-reference/guide` folder.
195170

196171
**Q: Does the library support streaming or incremental decoding of polylines?**
197172
A: Currently, only batch encode/decode is supported. For streaming scenarios, implement custom logic using `PolylineEncoding` utility functions.

src/PolylineAlgorithm/README.md

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ A modern, fully compliant Google Encoded Polyline Algorithm library for .NET Sta
55
## Features
66

77
- Google-compliant polyline encoding/decoding for geographic coordinates
8-
- Immutable, strongly-typed data structures: `Coordinate`, `Polyline`
9-
- Predefined encoder/decoder types for easy usage
10-
- Extensible APIs for custom coordinate and polyline types
8+
- Extensible APIs for custom coordinate and polyline types (`AbstractPolylineEncoder<TCoordinate, TPolyline>`, `AbstractPolylineDecoder<TPolyline, TCoordinate>`)
9+
- Extension methods for encoding from `List<T>` and arrays (`PolylineEncoderExtensions`)
1110
- Robust input validation and descriptive exceptions
12-
- Configurable with `PolylineEncodingOptions` (buffer, logging, etc.)
11+
- Configurable with `PolylineEncodingOptions` (precision, buffer size, logging)
1312
- Thread-safe, stateless APIs
13+
- Low-level utilities via static `PolylineEncoding` class (Normalize, Denormalize, TryReadValue, TryWriteValue, ValidateFormat, etc.)
1414
- Benchmarks and unit tests for correctness and performance
1515
- Auto-generated API docs ([API Reference](https://petesramek.github.io/polyline-algorithm-csharp/))
1616
- Supports .NET Core, .NET 5+, Xamarin, Unity, Blazor via `netstandard2.1`
@@ -29,37 +29,63 @@ Install-Package PolylineAlgorithm
2929

3030
## Quick Start
3131

32-
### Encode coordinates
32+
The library provides abstract base classes to build your own encoder and decoder for any coordinate and polyline type.
33+
34+
### Implement a custom encoder
3335

3436
```csharp
3537
using PolylineAlgorithm;
38+
using PolylineAlgorithm.Abstraction;
39+
40+
public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string> {
41+
protected override double GetLatitude((double Latitude, double Longitude) coordinate) => coordinate.Latitude;
42+
protected override double GetLongitude((double Latitude, double Longitude) coordinate) => coordinate.Longitude;
43+
protected override string CreatePolyline(ReadOnlyMemory<char> polyline) => polyline.ToString();
44+
}
45+
```
46+
47+
### Encode coordinates
48+
49+
```csharp
50+
using PolylineAlgorithm.Extensions;
3651

37-
var coordinates = new List<Coordinate>
52+
var coordinates = new List<(double Latitude, double Longitude)>
3853
{
39-
new Coordinate(48.858370, 2.294481),
40-
new Coordinate(51.500729, -0.124625)
54+
(48.858370, 2.294481),
55+
(51.500729, -0.124625)
4156
};
4257

43-
var encoder = new PolylineEncoder();
44-
Polyline encoded = encoder.Encode(coordinates);
58+
var encoder = new MyPolylineEncoder();
59+
string encoded = encoder.Encode(coordinates); // extension method for List<T>
4560
46-
Console.WriteLine(encoded.ToString()); // Print encoded polyline string
61+
Console.WriteLine(encoded);
4762
```
4863

49-
### Decode polyline
64+
### Implement a custom decoder
5065

5166
```csharp
5267
using PolylineAlgorithm;
68+
using PolylineAlgorithm.Abstraction;
69+
70+
public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double Latitude, double Longitude)> {
71+
protected override (double Latitude, double Longitude) CreateCoordinate(double latitude, double longitude) => (latitude, longitude);
72+
protected override ReadOnlyMemory<char> GetReadOnlyMemory(in string polyline) => polyline.AsMemory();
73+
}
74+
```
75+
76+
### Decode polyline
77+
78+
```csharp
79+
string encoded = "yseiHoc_MwacOjnwM";
5380

54-
var decoder = new PolylineDecoder();
55-
Polyline polyline = Polyline.FromString("yseiHoc_MwacOjnwM");
56-
IEnumerable<Coordinate> decoded = decoder.Decode(polyline);
81+
var decoder = new MyPolylineDecoder();
82+
IEnumerable<(double Latitude, double Longitude)> decoded = decoder.Decode(encoded);
5783
```
5884

5985
## Advanced Usage
6086

61-
- Custom coordinate/polyline types are supported via `AbstractPolylineEncoder` and `AbstractPolylineDecoder`.
62-
- Additional configuration via `PolylineEncodingOptionsBuilder`.
87+
- Pass a `PolylineEncodingOptions` (built via `PolylineEncodingOptionsBuilder`) to the encoder/decoder constructor for custom precision, stack-alloc limit, and logging.
88+
- Use static methods on `PolylineEncoding` for low-level normalization, validation, and bit-level read/write operations.
6389

6490
> See [API Reference](https://petesramek.github.io/polyline-algorithm-csharp/) for full documentation.
6591
@@ -70,7 +96,7 @@ IEnumerable<Coordinate> decoded = decoder.Decode(polyline);
7096
- **What .NET versions are supported?**
7197
Any environment supporting `netstandard2.1`
7298
- **How do I customize encoder options?**
73-
Use `PolylineEncodingOptionsBuilder` and pass to the encoder constructor.
99+
Use `PolylineEncodingOptionsBuilder` and pass the built options to the encoder or decoder constructor.
74100
- **Where can I get help?**
75101
[GitHub issues](https://github.com/petesramek/polyline-algorithm-csharp/issues)
76102

0 commit comments

Comments
 (0)