fix: harden path smoothing contracts
This commit is contained in:
@@ -53,7 +53,7 @@ public sealed class PathSmoothingResult
|
||||
IReadOnlyList<SmoothedPathSegment> segments,
|
||||
PathSmoothingDiagnostics diagnostics)
|
||||
{
|
||||
ValidatePublishedPath(path, segments);
|
||||
ValidatePublishedResult(method, path, segments, diagnostics);
|
||||
return new PathSmoothingResult(
|
||||
PathSmoothingStatus.Success,
|
||||
method,
|
||||
@@ -69,7 +69,7 @@ public sealed class PathSmoothingResult
|
||||
IReadOnlyList<SmoothedPathSegment> segments,
|
||||
PathSmoothingDiagnostics diagnostics)
|
||||
{
|
||||
ValidatePublishedPath(path, segments);
|
||||
ValidatePublishedResult(attemptedMethod, path, segments, diagnostics);
|
||||
return new PathSmoothingResult(
|
||||
PathSmoothingStatus.FallbackToCoarsePath,
|
||||
attemptedMethod,
|
||||
@@ -88,14 +88,20 @@ public sealed class PathSmoothingResult
|
||||
return new PathSmoothingResult(status, null, EmptyPath, EmptySegments, diagnostics);
|
||||
}
|
||||
|
||||
private static void ValidatePublishedPath(
|
||||
private static void ValidatePublishedResult(
|
||||
SmoothingMethod method,
|
||||
IReadOnlyList<SmoothedPathPoint> path,
|
||||
IReadOnlyList<SmoothedPathSegment> segments)
|
||||
IReadOnlyList<SmoothedPathSegment> segments,
|
||||
PathSmoothingDiagnostics diagnostics)
|
||||
{
|
||||
if (!Enum.IsDefined(typeof(SmoothingMethod), method))
|
||||
throw new ArgumentOutOfRangeException(nameof(method));
|
||||
if (path == null || path.Count == 0)
|
||||
throw new ArgumentException("Published smoothing results require a non-empty path.", nameof(path));
|
||||
if (segments == null || segments.Count == 0)
|
||||
throw new ArgumentException("Published smoothing results require non-empty segments.", nameof(segments));
|
||||
if (diagnostics == null || diagnostics.Metrics == null || !diagnostics.Metrics.IsFeasible)
|
||||
throw new ArgumentException("Published smoothing results require feasible diagnostics.", nameof(diagnostics));
|
||||
}
|
||||
|
||||
private static IReadOnlyList<T> CopyReadOnly<T>(IReadOnlyList<T> source)
|
||||
|
||||
Reference in New Issue
Block a user