using System; using System.Collections.Generic; using System.Collections.ObjectModel; using MultiWheelC.TrajectoryPlanning.CoarsePath; namespace MultiWheelC.TrajectoryPlanning.PathSmoothing.Processing; /// 已校验、已按单一行驶方向分割并重采样的路径段。 public sealed class PreparedDirectionSegment { /// 创建不可变方向段。 public PreparedDirectionSegment( int segmentIndex, TravelDirection direction, IReadOnlyList points, bool startsAtGearSwitch, bool endsAtGearSwitch) { if (segmentIndex < 0) throw new ArgumentOutOfRangeException(nameof(segmentIndex)); if (points == null || points.Count == 0) throw new ArgumentException("A prepared segment requires points.", nameof(points)); SegmentIndex = segmentIndex; Direction = direction; Points = CopyReadOnly(points); StartsAtGearSwitch = startsAtGearSwitch; EndsAtGearSwitch = endsAtGearSwitch; } /// 从零开始的分段序号;在 中必须与其位置一致。 public int SegmentIndex { get; } /// 该段的唯一行驶方向。 public TravelDirection Direction { get; } /// 不包含相邻段点的本段不可变采样点。 public IReadOnlyList Points { get; } /// 本段首点是否为换向后保留的新方向点。 public bool StartsAtGearSwitch { get; } /// 本段末点之后是否紧邻换向点。 public bool EndsAtGearSwitch { get; } private static IReadOnlyList CopyReadOnly(IReadOnlyList source) { var copy = new List(source.Count); for (int index = 0; index < source.Count; index++) copy.Add(source[index]); return new ReadOnlyCollection(copy); } }