|
| 1 | +### YamlMime:ApiPage |
| 2 | +title: Interface IPolylineEncoder<TValue, TPolyline> |
| 3 | +body: |
| 4 | +- api1: Interface IPolylineEncoder<TValue, TPolyline> |
| 5 | + id: PolylineAlgorithm_Abstraction_IPolylineEncoder_2 |
| 6 | + src: https://github.com/petesramek/polyline-algorithm-csharp/blob/extend-polylinealgorithm-multi-dimensional-support/src/PolylineAlgorithm/Abstraction/IPolylineEncoder.cs#L36 |
| 7 | + metadata: |
| 8 | + uid: PolylineAlgorithm.Abstraction.IPolylineEncoder`2 |
| 9 | + commentId: T:PolylineAlgorithm.Abstraction.IPolylineEncoder`2 |
| 10 | +- facts: |
| 11 | + - name: Namespace |
| 12 | + value: |
| 13 | + text: PolylineAlgorithm.Abstraction |
| 14 | + url: PolylineAlgorithm.Abstraction.html |
| 15 | + - name: Assembly |
| 16 | + value: PolylineAlgorithm.dll |
| 17 | +- markdown: >- |
| 18 | + Contract for encoding a sequence of values into an encoded polyline representation. |
| 19 | +
|
| 20 | + Implementations interpret the generic <code class="typeparamref">TValue</code> type and produce an encoded |
| 21 | +
|
| 22 | + representation of those values as <code class="typeparamref">TPolyline</code>. |
| 23 | +- code: public interface IPolylineEncoder<TValue, TPolyline> |
| 24 | +- h4: Type Parameters |
| 25 | +- parameters: |
| 26 | + - name: TValue |
| 27 | + description: >- |
| 28 | + The concrete value representation used by the encoder (for example a struct or class containing |
| 29 | +
|
| 30 | + <code>Latitude</code> and <code>Longitude</code> values). Implementations must document the expected shape, |
| 31 | +
|
| 32 | + units (typically decimal degrees), and any required fields for <code class="typeparamref">TValue</code>. |
| 33 | +
|
| 34 | + Common shapes: |
| 35 | +
|
| 36 | + - A struct or class with two <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/floating-point-numeric-types">double</a> properties named <code>Latitude</code> and <code>Longitude</code>. |
| 37 | +
|
| 38 | + - A tuple-like type (for example <code>ValueTuple<double,double></code>) where the encoder documents |
| 39 | + which element represents latitude and longitude. |
| 40 | + - name: TPolyline |
| 41 | + description: >- |
| 42 | + The encoded polyline representation returned by the encoder (for example <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/builtin-types/reference-types">string</a>, |
| 43 | +
|
| 44 | + <code>ReadOnlyMemory<char></code>, or a custom wrapper type). Concrete implementations should document |
| 45 | +
|
| 46 | + the chosen representation and any memory / ownership expectations. |
| 47 | +- h4: Extension Methods |
| 48 | +- list: |
| 49 | + - text: PolylineEncoderExtensions.Encode<TValue, TPolyline>(IPolylineEncoder<TValue, TPolyline>, TValue[], PolylineEncodingOptions<TValue>?, CancellationToken) |
| 50 | + url: PolylineAlgorithm.Extensions.PolylineEncoderExtensions.html#PolylineAlgorithm_Extensions_PolylineEncoderExtensions_Encode__2_PolylineAlgorithm_Abstraction_IPolylineEncoder___0___1____0___PolylineAlgorithm_PolylineEncodingOptions___0__System_Threading_CancellationToken_ |
| 51 | +- h2: Remarks |
| 52 | +- markdown: >- |
| 53 | + - This interface is intentionally minimal to allow different encoding strategies (Google encoded polyline, |
| 54 | + precision/scale variants, or custom compressed formats) to be expressed behind a common contract. |
| 55 | + - Implementations should document: |
| 56 | + - Value precision and rounding rules (for example 1e-5 for 5-decimal precision). |
| 57 | + - Value ordering and whether altitude or additional dimensions are supported. |
| 58 | + - Thread-safety guarantees: whether instances are safe to reuse concurrently or must be instantiated per-call. |
| 59 | + - Implementations are encouraged to be memory-efficient; the API accepts a <xref href="System.ReadOnlySpan%601" data-throw-if-not-resolved="false"></xref> |
| 60 | + to avoid forced allocations when callers already have contiguous memory. |
| 61 | +- h2: Methods |
| 62 | +- api3: Encode(ReadOnlySpan<TValue>, PolylineEncodingOptions<TValue>?, CancellationToken) |
| 63 | + id: PolylineAlgorithm_Abstraction_IPolylineEncoder_2_Encode_System_ReadOnlySpan__0__PolylineAlgorithm_PolylineEncodingOptions__0__System_Threading_CancellationToken_ |
| 64 | + src: https://github.com/petesramek/polyline-algorithm-csharp/blob/extend-polylinealgorithm-multi-dimensional-support/src/PolylineAlgorithm/Abstraction/IPolylineEncoder.cs#L76 |
| 65 | + metadata: |
| 66 | + uid: PolylineAlgorithm.Abstraction.IPolylineEncoder`2.Encode(System.ReadOnlySpan{`0},PolylineAlgorithm.PolylineEncodingOptions{`0},System.Threading.CancellationToken) |
| 67 | + commentId: M:PolylineAlgorithm.Abstraction.IPolylineEncoder`2.Encode(System.ReadOnlySpan{`0},PolylineAlgorithm.PolylineEncodingOptions{`0},System.Threading.CancellationToken) |
| 68 | +- markdown: >- |
| 69 | + Encodes a sequence of values into an encoded polyline representation. |
| 70 | +
|
| 71 | + The order of values in <code class="paramref">coordinates</code> is preserved in the encoded result. |
| 72 | +- code: TPolyline Encode(ReadOnlySpan<TValue> coordinates, PolylineEncodingOptions<TValue>? options = null, CancellationToken cancellationToken = default) |
| 73 | +- h4: Parameters |
| 74 | +- parameters: |
| 75 | + - name: coordinates |
| 76 | + type: |
| 77 | + - text: ReadOnlySpan |
| 78 | + url: https://learn.microsoft.com/dotnet/api/system.readonlyspan-1 |
| 79 | + - < |
| 80 | + - TValue |
| 81 | + - '>' |
| 82 | + description: >- |
| 83 | + The collection of <code class="typeparamref">TValue</code> instances to encode into a polyline. |
| 84 | +
|
| 85 | + The span may be empty; implementations should return an appropriate empty encoded representation |
| 86 | +
|
| 87 | + (for example an empty string or an empty memory slice) rather than <a href="https://learn.microsoft.com/dotnet/csharp/language-reference/keywords/null">null</a>. |
| 88 | + - name: options |
| 89 | + type: |
| 90 | + - text: PolylineEncodingOptions |
| 91 | + url: PolylineAlgorithm.PolylineEncodingOptions-1.html |
| 92 | + - < |
| 93 | + - TValue |
| 94 | + - '>' |
| 95 | + - '?' |
| 96 | + optional: true |
| 97 | + - name: cancellationToken |
| 98 | + type: |
| 99 | + - text: CancellationToken |
| 100 | + url: https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken |
| 101 | + description: >- |
| 102 | + A <xref href="System.Threading.CancellationToken" data-throw-if-not-resolved="false"></xref> that can be used to cancel the encoding operation. |
| 103 | +
|
| 104 | + Implementations should observe this token and throw <xref href="System.OperationCanceledException" data-throw-if-not-resolved="false"></xref> |
| 105 | +
|
| 106 | + when cancellation is requested. For fast, in-memory encoders cancellation may be best-effort. |
| 107 | + optional: true |
| 108 | +- h4: Returns |
| 109 | +- parameters: |
| 110 | + - type: |
| 111 | + - TPolyline |
| 112 | + description: >- |
| 113 | + A <code class="typeparamref">TPolyline</code> containing the encoded polyline that represents the input values. |
| 114 | +
|
| 115 | + The exact format and any delimiting/terminating characters are implementation-specific and must be |
| 116 | +
|
| 117 | + documented by concrete encoder types. |
| 118 | +- h4: Examples |
| 119 | +- markdown: >- |
| 120 | + <pre><code class="lang-csharp">// Example pseudocode for typical usage with a string-based encoder: |
| 121 | +
|
| 122 | + var values = new[] { |
| 123 | + new Value { Latitude = 47.6219, Longitude = -122.3503 }, |
| 124 | + new Value { Latitude = 47.6220, Longitude = -122.3504 } |
| 125 | + }; |
| 126 | +
|
| 127 | + IPolylineEncoder<Value,string> encoder = new GoogleEncodedPolylineEncoder(); |
| 128 | +
|
| 129 | + string encoded = encoder.Encode(values, CancellationToken.None);</code></pre> |
| 130 | +- h4: Remarks |
| 131 | +- markdown: >- |
| 132 | + - Implementations should validate input as appropriate and document any preconditions (for example |
| 133 | + if values must be within [-90,90] latitude and [-180,180] longitude). |
| 134 | + - For large input sequences, implementations may provide streaming or incremental encoders; those |
| 135 | + variants can still implement this interface by materializing the final encoded result. |
| 136 | +- h4: Exceptions |
| 137 | +- parameters: |
| 138 | + - type: |
| 139 | + - text: OperationCanceledException |
| 140 | + url: https://learn.microsoft.com/dotnet/api/system.operationcanceledexception |
| 141 | + description: Thrown if the operation is canceled via <code class="paramref">cancellationToken</code>. |
| 142 | +languageId: csharp |
| 143 | +metadata: |
| 144 | + description: >- |
| 145 | + Contract for encoding a sequence of values into an encoded polyline representation. |
| 146 | +
|
| 147 | + Implementations interpret the generic TValue type and produce an encoded |
| 148 | +
|
| 149 | + representation of those values as TPolyline. |
0 commit comments