Skip to content

Commit 47cf6cf

Browse files
authored
minor code changes, documentation func updates (#179)
1 parent f0cd3cf commit 47cf6cf

6 files changed

Lines changed: 66 additions & 50 deletions

File tree

.github/workflows/publish-documentation.yml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,25 +132,16 @@ jobs:
132132
done
133133
mv /tmp/api-reference.json api-reference/api-reference.json
134134
135-
- name: 'Update toc.yml with Reference dropdown'
135+
- name: 'Update toc.yml with navigation links'
136136
shell: bash
137137
run: |
138138
latest="${{ steps.discover-versions.outputs.latest }}"
139139
{
140140
echo "### YamlMime:TableOfContent"
141141
echo "- name: Guide"
142142
echo " href: ${latest}/guide/introduction.html"
143-
echo "- name: Reference"
144-
echo " dropdown: true"
145-
echo " items:"
146-
for ver in $(echo "${{ steps.discover-versions.outputs.versions }}" | tr ',' '\n' | sort -Vr); do
147-
if [ "$ver" = "$latest" ]; then
148-
echo " - name: v${ver} (latest)"
149-
else
150-
echo " - name: v${ver}"
151-
fi
152-
echo " href: ${ver}/PolylineAlgorithm.html"
153-
done
143+
echo "- name: API Reference"
144+
echo " href: ${latest}/PolylineAlgorithm.html"
154145
} > api-reference/toc.yml
155146
156147
- name: 'Inject latest version and released versions table into index.md'

api-reference/1.0/toc.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,3 @@
3232
href: PolylineAlgorithm.Extensions.PolylineDecoderExtensions.yml
3333
- name: PolylineEncoderExtensions
3434
href: PolylineAlgorithm.Extensions.PolylineEncoderExtensions.yml
35-
- name: PolylineAlgorithm.Internal.Diagnostics
36-
href: PolylineAlgorithm.Internal.Diagnostics.yml
37-
items:
38-
- name: Classes
39-
- name: ExceptionGuard
40-
href: PolylineAlgorithm.Internal.Diagnostics.ExceptionGuard.yml

api-reference/docs-versioning/layout/_master.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@
7171
<i class="bi bi-three-dots"></i>
7272
</button>
7373
<div class="collapse navbar-collapse" id="navpanel">
74-
<div id="navbar">
74+
<div id="version-picker-container" class="d-flex align-items-center px-2">
75+
<select id="version-picker" class="form-select form-select-sm" style="width:auto" aria-label="Select version"></select>
76+
</div>
77+
<div id="navbar" class="flex-grow-1">
7578
{{#_enableSearch}}
7679
<form class="search" role="search" id="search">
7780
<i class="bi bi-search"></i>
7881
<input class="form-control" id="search-query" type="search" disabled placeholder="{{__global.search}}" autocomplete="off" aria-label="Search">
7982
</form>
8083
{{/_enableSearch}}
8184
</div>
82-
<div id="version-picker-container" class="ms-auto d-flex align-items-center px-2">
83-
<select id="version-picker" class="form-select form-select-sm" style="width:auto" aria-label="Select version"></select>
84-
</div>
8585
</div>
8686
</div>
8787
</nav>

api-reference/docs-versioning/public/version-switcher.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,29 @@
1616
return meta ? meta.getAttribute('content') : './';
1717
}
1818

19+
var VERSION_PATTERN = /\/\d+(\.\d+)*\//;
20+
21+
function updateNavLinks(version) {
22+
var navbar = document.getElementById('navbar');
23+
if (!navbar || !version) return;
24+
if (!/^\d+(\.\d+)*$/.test(version)) return;
25+
26+
var links = navbar.querySelectorAll('a');
27+
links.forEach(function (link) {
28+
var absUrl;
29+
try {
30+
absUrl = new URL(link.href);
31+
} catch (e) {
32+
return;
33+
}
34+
if (absUrl.origin !== window.location.origin) return;
35+
var newPathname = absUrl.pathname.replace(VERSION_PATTERN, '/' + version + '/');
36+
if (newPathname !== absUrl.pathname) {
37+
link.setAttribute('href', absUrl.origin + newPathname + absUrl.search + absUrl.hash);
38+
}
39+
});
40+
}
41+
1942
function initVersionPicker(versions, latest) {
2043
var select = document.getElementById('version-picker');
2144
if (!select) return;
@@ -42,10 +65,16 @@
4265
select.insertBefore(placeholder, select.firstChild);
4366
}
4467

68+
window.addEventListener('load', function () {
69+
updateNavLinks(currentVersion || latest);
70+
});
71+
4572
select.addEventListener('change', function () {
4673
var targetVersion = select.value;
4774
if (!targetVersion) return;
4875

76+
updateNavLinks(targetVersion);
77+
4978
var newPathname;
5079
if (currentVersion && relativePath) {
5180
newPathname = window.location.pathname.replace(

api-reference/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
### YamlMime:TableOfContent
22
- name: Guide
3-
href: guide/
3+
href: guide/
4+
- name: API Reference
5+
href: 1.0/

src/PolylineAlgorithm/Internal/Diagnostics/ExceptionGuard.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace PolylineAlgorithm.Internal.Diagnostics;
2626
/// attributes to avoid polluting callers' stack traces (__StackTraceHidden__ on supported targets)
2727
/// or to prevent inlining on older targets.
2828
/// </remarks>
29-
public static class ExceptionGuard {
29+
internal static class ExceptionGuard {
3030
/// <summary>
3131
/// Throws an <see cref="ArgumentOutOfRangeException"/> when a numeric argument is not a finite value.
3232
/// </summary>
@@ -37,7 +37,7 @@ public static class ExceptionGuard {
3737
[MethodImpl(MethodImplOptions.NoInlining)]
3838
#endif
3939
[DoesNotReturn]
40-
public static void ThrowNotFiniteNumber(string paramName) {
40+
internal static void ThrowNotFiniteNumber(string paramName) {
4141
throw new ArgumentOutOfRangeException(paramName, ExceptionMessage.GetArgumentValueMustBeFiniteNumber());
4242
}
4343

@@ -51,7 +51,7 @@ public static void ThrowNotFiniteNumber(string paramName) {
5151
[MethodImpl(MethodImplOptions.NoInlining)]
5252
#endif
5353
[DoesNotReturn]
54-
public static void ThrowArgumentNull(string paramName) {
54+
internal static void ThrowArgumentNull(string paramName) {
5555
throw new ArgumentNullException(paramName);
5656
}
5757

@@ -65,7 +65,7 @@ public static void ThrowArgumentNull(string paramName) {
6565
[MethodImpl(MethodImplOptions.NoInlining)]
6666
#endif
6767
[DoesNotReturn]
68-
public static void ThrowBufferOverflow(string message) {
68+
internal static void ThrowBufferOverflow(string message) {
6969
throw new OverflowException(message);
7070
}
7171

@@ -82,7 +82,7 @@ public static void ThrowBufferOverflow(string message) {
8282
[MethodImpl(MethodImplOptions.NoInlining)]
8383
#endif
8484
[DoesNotReturn]
85-
public static void ThrowCoordinateValueOutOfRange(double value, double min, double max, string paramName) {
85+
internal static void ThrowCoordinateValueOutOfRange(double value, double min, double max, string paramName) {
8686
throw new ArgumentOutOfRangeException(paramName, ExceptionMessage.FormatCoordinateValueMustBeBetween(paramName, min, max));
8787
}
8888

@@ -97,7 +97,7 @@ public static void ThrowCoordinateValueOutOfRange(double value, double min, doub
9797
[MethodImpl(MethodImplOptions.NoInlining)]
9898
#endif
9999
[DoesNotReturn]
100-
public static void StackAllocLimitMustBeEqualOrGreaterThan(int minValue, string paramName) {
100+
internal static void StackAllocLimitMustBeEqualOrGreaterThan(int minValue, string paramName) {
101101
throw new ArgumentOutOfRangeException(paramName, ExceptionMessage.FormatStackAllocLimitMustBeEqualOrGreaterThan(minValue));
102102
}
103103

@@ -111,7 +111,7 @@ public static void StackAllocLimitMustBeEqualOrGreaterThan(int minValue, string
111111
[MethodImpl(MethodImplOptions.NoInlining)]
112112
#endif
113113
[DoesNotReturn]
114-
public static void ThrowArgumentCannotBeEmptyEnumerationMessage(string paramName) {
114+
internal static void ThrowArgumentCannotBeEmptyEnumerationMessage(string paramName) {
115115
throw new ArgumentException(ExceptionMessage.GetArgumentCannotBeEmpty(), paramName);
116116
}
117117

@@ -124,7 +124,7 @@ public static void ThrowArgumentCannotBeEmptyEnumerationMessage(string paramName
124124
[MethodImpl(MethodImplOptions.NoInlining)]
125125
#endif
126126
[DoesNotReturn]
127-
public static void ThrowCouldNotWriteEncodedValueToBuffer() {
127+
internal static void ThrowCouldNotWriteEncodedValueToBuffer() {
128128
throw new InvalidOperationException(ExceptionMessage.GetCouldNotWriteEncodedValueToTheBuffer());
129129
}
130130

@@ -140,7 +140,7 @@ public static void ThrowCouldNotWriteEncodedValueToBuffer() {
140140
[MethodImpl(MethodImplOptions.NoInlining)]
141141
#endif
142142
[DoesNotReturn]
143-
public static void ThrowDestinationArrayLengthMustBeEqualOrGreaterThanPolylineLength(int destinationLength, int polylineLength, string paramName) {
143+
internal static void ThrowDestinationArrayLengthMustBeEqualOrGreaterThanPolylineLength(int destinationLength, int polylineLength, string paramName) {
144144

145145
throw new ArgumentException(ExceptionMessage.FormatDestinationArrayLengthMustBeEqualOrGreaterThanPolylineLength(destinationLength, polylineLength), paramName);
146146
}
@@ -156,7 +156,7 @@ public static void ThrowDestinationArrayLengthMustBeEqualOrGreaterThanPolylineLe
156156
[MethodImpl(MethodImplOptions.NoInlining)]
157157
#endif
158158
[DoesNotReturn]
159-
public static void ThrowInvalidPolylineLength(int length, int min) {
159+
internal static void ThrowInvalidPolylineLength(int length, int min) {
160160
throw new InvalidPolylineException(ExceptionMessage.FormatInvalidPolylineLength(length, min));
161161
}
162162

@@ -171,7 +171,7 @@ public static void ThrowInvalidPolylineLength(int length, int min) {
171171
[MethodImpl(MethodImplOptions.NoInlining)]
172172
#endif
173173
[DoesNotReturn]
174-
public static void ThrowInvalidPolylineCharacter(char character, int position) {
174+
internal static void ThrowInvalidPolylineCharacter(char character, int position) {
175175
throw new InvalidPolylineException(ExceptionMessage.FormatInvalidPolylineCharacter(character, position));
176176
}
177177

@@ -185,7 +185,7 @@ public static void ThrowInvalidPolylineCharacter(char character, int position) {
185185
[MethodImpl(MethodImplOptions.NoInlining)]
186186
#endif
187187
[DoesNotReturn]
188-
public static void ThrowPolylineBlockTooLong(int position) {
188+
internal static void ThrowPolylineBlockTooLong(int position) {
189189
throw new InvalidPolylineException(ExceptionMessage.FormatPolylineBlockTooLong(position));
190190
}
191191

@@ -199,7 +199,7 @@ public static void ThrowPolylineBlockTooLong(int position) {
199199
[MethodImpl(MethodImplOptions.NoInlining)]
200200
#endif
201201
[DoesNotReturn]
202-
public static void ThrowInvalidPolylineFormat(long position) {
202+
internal static void ThrowInvalidPolylineFormat(long position) {
203203
throw new InvalidPolylineException(ExceptionMessage.FormatMalformedPolyline(position));
204204
}
205205

@@ -212,7 +212,7 @@ public static void ThrowInvalidPolylineFormat(long position) {
212212
[MethodImpl(MethodImplOptions.NoInlining)]
213213
#endif
214214
[DoesNotReturn]
215-
public static void ThrowInvalidPolylineBlockTerminator() {
215+
internal static void ThrowInvalidPolylineBlockTerminator() {
216216
throw new InvalidPolylineException(ExceptionMessage.GetInvalidPolylineBlockTerminator());
217217
}
218218

@@ -221,7 +221,7 @@ public static void ThrowInvalidPolylineBlockTerminator() {
221221
/// </summary>
222222
/// <remarks>
223223
/// Keeps message formatting centralized so exception text remains consistent and can reuse
224-
/// resource strings. This class is public because messages are only used by the guard methods.
224+
/// resource strings. This class is internal because messages are only used by the guard methods.
225225
/// </remarks>
226226
[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Internal use only.")]
227227
internal static class ExceptionMessage {
@@ -253,73 +253,73 @@ internal static class ExceptionMessage {
253253
/// <summary>
254254
/// Formats the message for stack allocation limit violations.
255255
/// </summary>
256-
public static string FormatStackAllocLimitMustBeEqualOrGreaterThan(int minValue) =>
256+
internal static string FormatStackAllocLimitMustBeEqualOrGreaterThan(int minValue) =>
257257
string.Format(CultureInfo.InvariantCulture, StackAllocLimitMustBeEqualOrGreaterThanFormat, minValue);
258258

259259
/// <summary>
260260
/// Formats the message when a polyline is shorter than the required minimum.
261261
/// </summary>
262-
public static string FormatPolylineCannotBeShorterThan(int length, int minLength) =>
262+
internal static string FormatPolylineCannotBeShorterThan(int length, int minLength) =>
263263
string.Format(CultureInfo.InvariantCulture, PolylineCannotBeShorterThanFormat, length, minLength);
264264

265265
/// <summary>
266266
/// Formats a message indicating the polyline is malformed at a given position.
267267
/// </summary>
268-
public static string FormatMalformedPolyline(long position) =>
268+
internal static string FormatMalformedPolyline(long position) =>
269269
string.Format(CultureInfo.InvariantCulture, PolylineIsMalformedAtFormat, position);
270270

271271
/// <summary>
272272
/// Formats a message indicating a coordinate parameter must be within a range.
273273
/// </summary>
274-
public static string FormatCoordinateValueMustBeBetween(string name, double min, double max) =>
274+
internal static string FormatCoordinateValueMustBeBetween(string name, double min, double max) =>
275275
string.Format(CultureInfo.InvariantCulture, CoordinateValueMustBeBetweenFormat, name, min, max);
276276

277277
/// <summary>
278278
/// Formats a message for polyline blocks that exceed allowed length.
279279
/// </summary>
280-
public static string FormatPolylineBlockTooLong(int position) =>
280+
internal static string FormatPolylineBlockTooLong(int position) =>
281281
string.Format(CultureInfo.InvariantCulture, PolylineBlockTooLongFormat, position);
282282

283283
/// <summary>
284284
/// Formats a message for invalid characters found in a polyline.
285285
/// </summary>
286-
public static string FormatInvalidPolylineCharacter(char character, int position) =>
286+
internal static string FormatInvalidPolylineCharacter(char character, int position) =>
287287
string.Format(CultureInfo.InvariantCulture, InvalidPolylineCharacterFormat, character, position);
288288

289289
/// <summary>
290290
/// Formats a message when a destination array is too small for the polyline.
291291
/// </summary>
292-
public static string FormatDestinationArrayLengthMustBeEqualOrGreaterThanPolylineLength(int destinationLength, int polylineLength) =>
292+
internal static string FormatDestinationArrayLengthMustBeEqualOrGreaterThanPolylineLength(int destinationLength, int polylineLength) =>
293293
string.Format(CultureInfo.InvariantCulture, DestinationArrayLengthMustBeEqualOrGreaterThanPolylineLengthFormat, destinationLength, polylineLength);
294294

295295
/// <summary>
296296
/// Formats an invalid polyline length message.
297297
/// </summary>
298-
public static string FormatInvalidPolylineLength(int length, int min) =>
298+
internal static string FormatInvalidPolylineLength(int length, int min) =>
299299
string.Format(CultureInfo.InvariantCulture, InvalidPolylineLengthFormat, length, min);
300300

301301
/// <summary>
302302
/// Gets the message used when a numeric argument must be finite.
303303
/// </summary>
304-
public static string GetArgumentValueMustBeFiniteNumber() =>
304+
internal static string GetArgumentValueMustBeFiniteNumber() =>
305305
ArgumentValueMustBeFiniteNumberMessage;
306306

307307
/// <summary>
308308
/// Gets the message used when the library could not write an encoded value to a buffer.
309309
/// </summary>
310-
public static string GetCouldNotWriteEncodedValueToTheBuffer() =>
310+
internal static string GetCouldNotWriteEncodedValueToTheBuffer() =>
311311
CouldNotWriteEncodedValueToTheBufferMessage;
312312

313313
/// <summary>
314314
/// Gets the message used when an argument collection must not be empty.
315315
/// </summary>
316-
public static string GetArgumentCannotBeEmpty() =>
316+
internal static string GetArgumentCannotBeEmpty() =>
317317
ArgumentCannotBeEmptyMessage;
318318

319319
/// <summary>
320320
/// Gets the message used when a polyline block terminator is invalid.
321321
/// </summary>
322-
public static string GetInvalidPolylineBlockTerminator() =>
322+
internal static string GetInvalidPolylineBlockTerminator() =>
323323
InvalidPolylineBlockTerminatorMessage;
324324
}
325325
}

0 commit comments

Comments
 (0)