Skip to content

Commit b59eca1

Browse files
committed
added documentation and file headers
1 parent c369d06 commit b59eca1

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

utilities/PolylineAlgorithm.Utility/RandomValueProvider.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,30 @@
1-
namespace PolylineAlgorithm.Utility;
1+
//
2+
// Copyright © Pete Sramek. All rights reserved.
3+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace PolylineAlgorithm.Utility;
27

38
using System;
49
using System.Collections.Concurrent;
510
using System.Collections.Generic;
611
using System.Linq;
712

13+
/// <summary>
14+
/// Provides random generation and caching of coordinate collections and their encoded polyline representations.
15+
/// Useful for testing and benchmarking polyline algorithms with reproducible random data.
16+
/// </summary>
817
internal static class RandomValueProvider {
918
private static readonly Random _random = new(DateTime.Now.Millisecond);
1019
private static readonly ConcurrentDictionary<int, PolylineCoordinateCollectionPair> _cache = new();
1120
private static readonly PolylineEncoder _encoder = new();
1221

22+
/// <summary>
23+
/// Gets a collection of random <see cref="Coordinate"/> instances of the specified count.
24+
/// The same collection is cached and reused for the same count value.
25+
/// </summary>
26+
/// <param name="count">The number of coordinates to generate.</param>
27+
/// <returns>An enumerable collection of random <see cref="Coordinate"/> objects.</returns>
1328
public static IEnumerable<Coordinate> GetCoordinates(int count) {
1429
var entry = GetCaheEntry(count);
1530

@@ -20,12 +35,25 @@ public static IEnumerable<Coordinate> GetCoordinates(int count) {
2035
}
2136
}
2237

38+
/// <summary>
39+
/// Gets a <see cref="Polyline"/> representing the encoded polyline for a random collection of coordinates of the specified count.
40+
/// The same polyline is cached and reused for the same count value.
41+
/// </summary>
42+
/// <param name="count">The number of coordinates to generate and encode.</param>
43+
/// <returns>A <see cref="Polyline"/> representing the encoded polyline.</returns>
2344
public static Polyline GetPolyline(int count) {
2445
var entry = GetCaheEntry(count);
2546

2647
return entry.Polyline;
2748
}
2849

50+
/// <summary>
51+
/// Gets or creates a cached entry containing a collection of random coordinates and its encoded polyline for the specified count.
52+
/// </summary>
53+
/// <param name="count">The number of coordinates to generate and cache.</param>
54+
/// <returns>
55+
/// A <see cref="PolylineCoordinateCollectionPair"/> containing the coordinates and their encoded polyline.
56+
/// </returns>
2957
private static PolylineCoordinateCollectionPair GetCaheEntry(int count) {
3058
if (_cache.TryGetValue(count, out var entry)) {
3159
return entry;
@@ -41,16 +69,36 @@ private static PolylineCoordinateCollectionPair GetCaheEntry(int count) {
4169
return entry;
4270
}
4371

72+
/// <summary>
73+
/// Generates a random longitude value in the range [-180, 180), rounded to 5 decimal places.
74+
/// </summary>
75+
/// <returns>A random longitude value.</returns>
4476
private static double RandomLongitude() {
4577
return Math.Round(_random.Next(-180, 180) + _random.NextDouble(), 5);
4678
}
4779

80+
/// <summary>
81+
/// Generates a random latitude value in the range [-90, 90), rounded to 5 decimal places.
82+
/// </summary>
83+
/// <returns>A random latitude value.</returns>
4884
private static double RandomLatitude() {
4985
return Math.Round(_random.Next(-90, 90) + _random.NextDouble(), 5);
5086
}
5187

88+
/// <summary>
89+
/// Represents a pair of a collection of coordinates and its encoded polyline.
90+
/// </summary>
91+
/// <param name="coordinates">The collection of coordinates.</param>
92+
/// <param name="polyline">The encoded polyline.</param>
5293
private readonly struct PolylineCoordinateCollectionPair(IEnumerable<Coordinate> coordinates, Polyline polyline) {
94+
/// <summary>
95+
/// Gets the collection of coordinates.
96+
/// </summary>
5397
public IEnumerable<Coordinate> Coordinates { get; } = coordinates;
98+
99+
/// <summary>
100+
/// Gets the encoded polyline.
101+
/// </summary>
54102
public Polyline Polyline { get; } = polyline;
55103
}
56104
}

utilities/PolylineAlgorithm.Utility/StaticValueProvider.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
namespace PolylineAlgorithm.Utility;
1+
//
2+
// Copyright © Pete Sramek. All rights reserved.
3+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
4+
//
5+
6+
namespace PolylineAlgorithm.Utility;
27

38
using System.Collections.Generic;
49

10+
/// <summary>
11+
/// Provides static, predefined coordinate and polyline values for use in tests and benchmarks.
12+
/// </summary>
513
internal static class StaticValueProvider {
14+
/// <summary>
15+
/// A predefined polyline instance representing a fixed encoded polyline string.
16+
/// </summary>
617
private static readonly Polyline _polyline = Polyline.FromString("???_gsia@_cidP??~fsia@?~fsia@~bidP?~bidP??_gsia@");
18+
19+
/// <summary>
20+
/// A predefined collection of <see cref="Coordinate"/> instances representing a closed path around the globe.
21+
/// </summary>
722
private static readonly IEnumerable<Coordinate> _coordinates = [
823
new (0, 0),
924
new (0, 180),
@@ -15,10 +30,18 @@ internal static class StaticValueProvider {
1530
new (-90, 0)
1631
];
1732

33+
/// <summary>
34+
/// Gets the predefined collection of <see cref="Coordinate"/> instances.
35+
/// </summary>
36+
/// <returns>An <see cref="IEnumerable{Coordinate}"/> containing the static coordinates.</returns>
1837
public static IEnumerable<Coordinate> GetCoordinates() {
1938
return _coordinates;
2039
}
2140

41+
/// <summary>
42+
/// Gets the predefined <see cref="Polyline"/> instance.
43+
/// </summary>
44+
/// <returns>The static <see cref="Polyline"/> value.</returns>
2245
public static Polyline GetPolyline() {
2346
return _polyline;
2447
}

0 commit comments

Comments
 (0)