Exemplo n.º 1
0
        private static PathSegmentCollection SortPathSegmentCollection(PathSegmentCollection segments)
        {
            var n = segments.Count - 2;
            Debug.Assert(n % 2 == 0);
            var m = n / 2;

            // TODO: use better variables for v1, v2 and v3
            var v1 = Enumerable.Range(0, m).ToList();
            var v2 = v1.Select(x => x * 2 + 1);
            var v3 = v1.Select(x => x * 2 + 2);

            var sortedSegments = new List<PathSegment> { segments.First() };
            sortedSegments.AddRange(v2.Select(x => segments[x]));
            sortedSegments.Add(segments.Last());
            sortedSegments.AddRange(v3.Select(x => segments[x]).Reverse());

            return new PathSegmentCollection(sortedSegments);
        }