using System; using System.Collections.Generic; using System.Collections.ObjectModel; namespace MultiWheelC.TrajectoryPlanning.PathSmoothing.Processing; /// 已校验并按方向拆分的粗路径输入快照。 public sealed class PreparedPath { /// 创建不可变预处理路径。 public PreparedPath(IReadOnlyList segments) { if (segments == null || segments.Count == 0) throw new ArgumentException("A prepared path requires direction segments.", nameof(segments)); for (int segmentIndex = 0; segmentIndex < segments.Count; segmentIndex++) { if (segments[segmentIndex] == null) throw new ArgumentException("A prepared path cannot contain null direction segments.", nameof(segments)); } Segments = CopyReadOnly(segments); Points = Flatten(Segments); } /// 按原始前进/倒车拓扑排列的方向段。 public IReadOnlyList Segments { get; } /// 将所有方向段顺序拼接后的点;换向重复点保留两次。 public IReadOnlyList Points { 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); } private static IReadOnlyList Flatten(IReadOnlyList segments) { var points = new List(); for (int segmentIndex = 0; segmentIndex < segments.Count; segmentIndex++) { PreparedDirectionSegment segment = segments[segmentIndex]; for (int pointIndex = 0; pointIndex < segment.Points.Count; pointIndex++) points.Add(segment.Points[pointIndex]); } return new ReadOnlyCollection(points); } }