using System; using System.Collections.Generic; using System.Collections.ObjectModel; using MultiWheelC.TrajectoryPlanning.PathSmoothing.Processing; namespace MultiWheelC.TrajectoryPlanning.PathSmoothing.Algorithms; /// 平滑方法产生的原始方向段候选,尚未经过统一几何或安全复核。 internal sealed class SmoothingCandidate { private SmoothingCandidate(bool succeeded, IReadOnlyList segments, string reason) { Succeeded = succeeded; Segments = CopyReadOnly(segments); Reason = reason ?? string.Empty; } /// 候选是否成功产生有限的原始几何。 internal bool Succeeded { get; } /// 候选方向段;失败候选始终为空。 internal IReadOnlyList Segments { get; } /// 失败或退化时的稳定说明;成功时为空。 internal string Reason { get; } /// 创建待统一分析和验证的成功候选。 internal static SmoothingCandidate Success(IReadOnlyList segments) { if (segments == null || segments.Count == 0) throw new ArgumentException("A successful smoothing candidate requires direction segments.", nameof(segments)); return new SmoothingCandidate(true, segments, string.Empty); } /// 创建不应重试的数值或构造失败候选。 internal static SmoothingCandidate Failed(string reason) { if (string.IsNullOrWhiteSpace(reason)) throw new ArgumentException("A failed smoothing candidate requires a reason.", nameof(reason)); return new SmoothingCandidate(false, null, reason); } private static IReadOnlyList CopyReadOnly(IReadOnlyList source) { var copy = new List(source == null ? 0 : source.Count); if (source != null) { for (int index = 0; index < source.Count; index++) copy.Add(source[index]); } return new ReadOnlyCollection(copy); } }