Skip to content

Commit 23fbbd2

Browse files
Copilotpetesramek
andauthored
feat: add released versions section to index.md with per-version guide and API links
Agent-Logs-Url: https://github.com/petesramek/polyline-algorithm-csharp/sessions/b02a112c-f47f-48ac-ac0e-6da6ec9b5c69 Co-authored-by: petesramek <2333452+petesramek@users.noreply.github.com>
1 parent db066dc commit 23fbbd2

10 files changed

Lines changed: 567 additions & 13 deletions

File tree

.github/workflows/publish-documentation.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ jobs:
9191
docfx metadata assembly-metadata.json
9292
mv temp ${{ env.friendly-version }}
9393
94+
- name: 'Snapshot guide for v${{ env.friendly-version }}'
95+
shell: bash
96+
run: |
97+
cp -r api-reference/guide api-reference/${{ env.friendly-version }}/guide
98+
9499
- name: 'Discover all versions'
95100
id: discover-versions
96101
shell: bash
@@ -116,7 +121,10 @@ jobs:
116121
cp api-reference/api-reference.json /tmp/api-reference.json
117122
for ver in $(echo "${{ steps.discover-versions.outputs.versions }}" | tr ',' ' '); do
118123
jq --arg ver "$ver" --arg group "v${ver}" \
119-
'.build.content += [{"dest": "", "files": ["*.yml"], "group": $group, "src": $ver, "rootTocPath": "~/toc.html"}] |
124+
'.build.content += [
125+
{"dest": "", "files": ["*.yml"], "group": $group, "src": $ver, "rootTocPath": "~/toc.html"},
126+
{"dest": "guide", "files": ["*.{md,yml}"], "group": $group, "src": ($ver + "/guide"), "rootTocPath": "~/toc.html"}
127+
] |
120128
.build.groups = (.build.groups // {}) |
121129
.build.groups[$group] = {"dest": $ver}' \
122130
/tmp/api-reference.json > /tmp/api-reference-new.json
@@ -131,7 +139,7 @@ jobs:
131139
{
132140
echo "### YamlMime:TableOfContent"
133141
echo "- name: Guide"
134-
echo " href: guide/"
142+
echo " href: ${latest}/guide/introduction.html"
135143
echo "- name: Reference"
136144
echo " dropdown: true"
137145
echo " items:"
@@ -145,6 +153,11 @@ jobs:
145153
done
146154
} > api-reference/toc.yml
147155
156+
- name: 'Inject latest version into index.md'
157+
shell: bash
158+
run: |
159+
sed -i "s|{version}|${{ steps.discover-versions.outputs.latest }}|g" api-reference/index.md
160+
148161
- name: 'Build documentation'
149162
shell: bash
150163
run: docfx build api-reference/api-reference.json
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Advanced Usage
2+
3+
PolylineAlgorithm is designed for extensibility and integration with advanced .NET scenarios.
4+
This guide covers custom types, integrations, and best practices for power users.
5+
6+
---
7+
8+
## Custom Coordinate and Polyline Types
9+
10+
You can encode and decode custom coordinate or polyline representations by extending the abstract base classes:
11+
12+
- `AbstractPolylineEncoder<TCoordinate, TPolyline>`
13+
- `AbstractPolylineDecoder<TPolyline, TCoordinate>`
14+
15+
### Example: Custom Encoder
16+
17+
```csharp
18+
public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string>
19+
{
20+
public MyPolylineEncoder() : base() { }
21+
22+
public MyPolylineEncoder(PolylineEncodingOptions options)
23+
: base(options) { }
24+
25+
protected override double GetLatitude((double Latitude, double Longitude) coordinate)
26+
=> coordinate.Latitude;
27+
28+
protected override double GetLongitude((double Latitude, double Longitude) coordinate)
29+
=> coordinate.Longitude;
30+
31+
protected override string CreatePolyline(ReadOnlyMemory<char> polyline)
32+
=> polyline.ToString();
33+
}
34+
```
35+
36+
---
37+
38+
## Example: Custom Decoder
39+
40+
```csharp
41+
public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double Latitude, double Longitude)>
42+
{
43+
public MyPolylineDecoder() : base() { }
44+
45+
public MyPolylineDecoder(PolylineEncodingOptions options)
46+
: base(options) { }
47+
48+
protected override (double Latitude, double Longitude) CreateCoordinate(double latitude, double longitude)
49+
=> (latitude, longitude);
50+
51+
protected override ReadOnlyMemory<char> GetReadOnlyMemory(ref string polyline)
52+
=> polyline.AsMemory();
53+
}
54+
```
55+
56+
---
57+
58+
# Registering Custom Encoder and Decoder with `IServiceCollection`
59+
60+
For ASP.NET Core or DI-enabled .NET applications, you can easily register your custom polyline encoder and decoder as services with `IServiceCollection` by defining an extension method. This enables constructor injection and central DI management.
61+
62+
---
63+
64+
## Example: Register Custom Polyline Encoder/Decoder
65+
66+
Suppose you have the following custom encoder and decoder (see [Advanced Usage](./advanced.md)):
67+
68+
```csharp
69+
public sealed class MyPolylineEncoder : AbstractPolylineEncoder<(double Latitude, double Longitude), string>
70+
{
71+
public MyPolylineEncoder(PolylineEncodingOptions options = null)
72+
: base(options) { }
73+
74+
// ... override required members ...
75+
}
76+
77+
public sealed class MyPolylineDecoder : AbstractPolylineDecoder<string, (double Latitude, double Longitude)>
78+
{
79+
public MyPolylineDecoder(PolylineEncodingOptions options = null)
80+
: base(options) { }
81+
82+
// ... override required members ...
83+
}
84+
```
85+
86+
---
87+
88+
## IServiceCollection Extension Method
89+
90+
```csharp
91+
using Microsoft.Extensions.DependencyInjection;
92+
using PolylineAlgorithm;
93+
94+
public static class PolylineServiceCollectionExtensions
95+
{
96+
public static IServiceCollection AddMyPolylineEncoderDecoder(
97+
this IServiceCollection services,
98+
PolylineEncodingOptions options = null)
99+
{
100+
// Register encoder and decoder as singletons (adjust lifetime as needed)
101+
services.AddSingleton<IPolylineEncoder<(double Latitude, double Longitude), string>>(
102+
_ => new MyPolylineEncoder(options));
103+
services.AddSingleton<IPolylineDecoder<string, (double Latitude, double Longitude)>>(
104+
_ => new MyPolylineDecoder(options));
105+
return services;
106+
}
107+
}
108+
```
109+
110+
---
111+
112+
## Usage
113+
114+
In your application startup (e.g., `Program.cs` or `Startup.cs`):
115+
116+
```csharp
117+
using PolylineAlgorithm;
118+
119+
var builder = WebApplication.CreateBuilder(args);
120+
121+
builder.Services.AddMyPolylineEncoderDecoder(
122+
PolylineEncodingOptionsBuilder.Create()
123+
.WithStackAllocLimit(1024)
124+
.Build()
125+
);
126+
127+
// Now you can inject IPolylineEncoder<(double, double), string> and IPolylineDecoder<string, (double, double)>
128+
```
129+
130+
---
131+
132+
## Benefits
133+
134+
- **Central DI management** for polyline components
135+
- Plug-and-play integration with ASP.NET Core and modern .NET project styles
136+
- Easily swap out or configure encoders/decoders for different environments
137+
138+
---
139+
140+
> **Tip:**
141+
> You can generalize the extension method for different encoder/decoder types or include multiple algorithms by adding extra parameters.
142+
143+
---
144+
145+
## Integration Guidance
146+
147+
- **Batch or incremental processing:**
148+
For large datasets, control the stack allocation limit via `PolylineEncodingOptions.StackAllocLimit`.
149+
- **Thread safety:**
150+
Default encoders/decoders are stateless and thread-safe. If extending for mutable types, ensure synchronization.
151+
- **Logging:**
152+
Integrate with .NET's `ILoggerFactory` when diagnostics or audit trails are needed.
153+
154+
---
155+
156+
## Best Practices
157+
158+
- Always validate input data—leverage built-in validation or extend for custom rules.
159+
- Document all public APIs using XML comments for seamless integration with the auto-generated docs.
160+
- For non-standard coordinate systems or precision, clearly specify semantics in your custom encoder/decoder.
161+
162+
---
163+
164+
## More Resources
165+
166+
- [Configuration](./configuration.md)
167+
- [FAQ](./faq.md)
168+
- [API Reference](https://petesramek.github.io/polyline-algorithm-csharp/)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Configuration
2+
3+
PolylineAlgorithm offers flexible configuration for encoding and decoding polylines, allowing you to fine-tune performance, control validation, and integrate diagnostics and logging.
4+
5+
---
6+
7+
## PolylineEncodingOptions
8+
9+
Most configuration is handled via the `PolylineEncodingOptions` object, which you can build using the fluent `PolylineEncodingOptionsBuilder`.
10+
11+
### Example: Customizing Stack Alloc Limit
12+
13+
```csharp
14+
using PolylineAlgorithm;
15+
16+
var options = PolylineEncodingOptionsBuilder.Create()
17+
.WithStackAllocLimit(1024) // Set stack allocation threshold (bytes)
18+
.Build();
19+
20+
var encoder = new PolylineEncoder(options);
21+
```
22+
23+
---
24+
25+
## Logging and Diagnostics
26+
27+
PolylineAlgorithm supports internal logging for advanced scenarios and diagnostic purposes.
28+
29+
- Use your preferred .NET logging framework (`ILoggerFactory`)
30+
- Attach loggers for encoding/decoding diagnostics, especially in automated or agent-based environments
31+
32+
---
33+
34+
## Validation
35+
36+
Input validation is always enabled by default:
37+
38+
- Latitude: must be between -90 and 90
39+
- Longitude: must be between -180 and 180
40+
- Invalid or malformed coordinates throw descriptive exceptions
41+
42+
For custom validation (e.g., for custom coordinate types), extend the provided interfaces or abstract base classes.
43+
44+
---
45+
46+
## Advanced Configuration Options
47+
48+
When using `PolylineEncodingOptionsBuilder`, you may set:
49+
50+
- **Stack alloc limit:** Configure the threshold below which buffers are stack-allocated vs. rented from `ArrayPool<char>`
51+
- **Logging hooks:** Integrate your logger for troubleshooting/instrumentation
52+
- **(Future)** Custom precision, additional metadata (as needed)
53+
54+
See the XML API documentation for all available builder methods.
55+
56+
---
57+
58+
## Example: Full Custom Encoder with Options
59+
60+
```csharp
61+
var options = PolylineEncodingOptionsBuilder.Create()
62+
.WithStackAllocLimit(512)
63+
.WithLoggerFactory(myLoggerFactory)
64+
.Build();
65+
66+
var encoder = new PolylineEncoder(options);
67+
```
68+
69+
---
70+
71+
## Further Reading
72+
73+
- [Getting Started Guide](./guide.md)
74+
- [Advanced Usage](./advanced.md)
75+
- [API Reference](https://petesramek.github.io/polyline-algorithm-csharp/)

api-reference/1.0/guide/faq.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# FAQ
2+
3+
Frequently Asked Questions for PolylineAlgorithm
4+
5+
---
6+
7+
## General
8+
9+
**Q: What coordinate ranges are valid?**
10+
A: Latitude must be between -90 and 90; longitude must be between -180 and 180. Passing out-of-range values throws `ArgumentOutOfRangeException`.
11+
12+
**Q: Which .NET versions are supported?**
13+
A: Any platform supporting `netstandard2.1`, including .NET Core, .NET 5+, Xamarin, Unity, and Blazor.
14+
15+
**Q: Can the library be used in Unity, Xamarin, Blazor, or other .NET-compatible platforms?**
16+
A: Yes! Any environment that supports `netstandard2.1` can use this library.
17+
18+
---
19+
20+
## Usage & Extensibility
21+
22+
**Q: How do I add a new polyline algorithm or coordinate type?**
23+
A: Implement your own encoder/decoder using `AbstractPolylineEncoder<TCoordinate, TPolyline>` and `AbstractPolylineDecoder<TPolyline, TCoordinate>`. Add unit tests and XML doc comments, then submit a PR.
24+
25+
**Q: How do I customize encoding options (e.g., buffer size, logging)?**
26+
A: Use `PolylineEncodingOptionsBuilder` to set options, and pass the result to the encoder or decoder constructor.
27+
28+
**Q: Is the library thread-safe?**
29+
A: Yes, main encoding/decoding APIs are stateless and thread-safe. If you extend using shared mutable resources, ensure proper synchronization.
30+
31+
**Q: What happens if I pass invalid or malformed input to the decoder?**
32+
A: The decoder throws descriptive exceptions for malformed polyline strings. Ensure proper exception handling in your application.
33+
34+
**Q: Does the library support streaming or incremental decoding of polylines?**
35+
A: Currently, only batch encode/decode is supported. For streaming scenarios, implement your own logic using `PolylineEncoding` utilities.
36+
37+
---
38+
39+
## Features & Support
40+
41+
**Q: Is there support for elevation, timestamps, or third coordinate values?**
42+
A: Not currently, and not planned for the core library. You may implement your own encoder/decoder using `PolylineEncoding` methods for extended coordinate data.
43+
44+
**Q: How do I contribute documentation improvements?**
45+
A: Update XML doc comments in the codebase and submit a pull request. To improve guides, update relevant markdown files in `/api-reference/guide`.
46+
47+
**Q: Where can I report bugs or request features?**
48+
A: Open a GitHub issue using the provided templates and tag `@petesramek`.
49+
50+
---
51+
52+
## Documentation & Community
53+
54+
**Q: Where can I find detailed API documentation?**
55+
A: [API Reference](https://petesramek.github.io/polyline-algorithm-csharp/)
56+
57+
**Q: How do I contribute?**
58+
A: Read [CONTRIBUTING.md](../CONTRIBUTING.md), follow coding style and testing guidelines, and use issue/PR templates.
59+
60+
**Q: Need more help?**
61+
A: Open an issue in the [GitHub repository](https://github.com/petesramek/polyline-algorithm-csharp/issues).
62+
63+
---

0 commit comments

Comments
 (0)