示例#1
0
        private List <SugiVertex> FindVerticesWithSameMeasure(
            [NotNull, ItemNotNull] AlternatingLayer nextAlternatingLayer,
            bool straightSweep,
            [NotNull] out IList <int> ranges,
            out int maxRangeLength)
        {
            Debug.Assert(nextAlternatingLayer != null);

            VertexTypes ignorableVertexType     = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var         verticesWithSameMeasure = new List <SugiVertex>();

            SugiVertex[] vertices = nextAlternatingLayer.OfType <SugiVertex>().ToArray();
            int          startIndex;
            int          endIndex;

            maxRangeLength = 0;
            ranges         = new List <int>();
            for (startIndex = 0; startIndex < vertices.Length; startIndex = endIndex + 1)
            {
                ThrowIfCancellationRequested();

                endIndex = FindNearVertexEndIndex(startIndex, vertices);

                if (endIndex > startIndex)
                {
                    int rangeLength = 0;
                    for (int i = startIndex; i <= endIndex; ++i)
                    {
                        ThrowIfCancellationRequested();

                        if (vertices[i].Type == ignorableVertexType || vertices[i].DoNotOptimize)
                        {
                            continue;
                        }

                        ++rangeLength;
                        verticesWithSameMeasure.Add(vertices[i]);
                    }

                    if (rangeLength > 0)
                    {
                        maxRangeLength = Math.Max(rangeLength, maxRangeLength);
                        ranges.Add(rangeLength);
                    }
                }
            }

            return(verticesWithSameMeasure);
        }
示例#2
0
        private IList <SugiVertex> FindVerticesWithSameMeasure(CancellationToken cancellationToken, AlternatingLayer nextAlternatingLayer, bool straightSweep, out IList <int> ranges, out int maxRangeLength)
        {
            var ignorableVertexType     = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var verticesWithSameMeasure = new List <SugiVertex>();
            var vertices = nextAlternatingLayer.OfType <SugiVertex>().ToArray();
            int startIndex, endIndex;

            maxRangeLength = 0;
            int rangeCount = 0;

            ranges = new List <int>();
            for (startIndex = 0; startIndex < vertices.Length; startIndex = endIndex + 1)
            {
                cancellationToken.ThrowIfCancellationRequested();

                for (endIndex = startIndex + 1;
                     endIndex < vertices.Length && vertices[startIndex].MeasuredPosition == vertices[endIndex].MeasuredPosition;
                     endIndex++)
                {
                }
                endIndex -= 1;

                if (endIndex > startIndex)
                {
                    int rangeLength = 0;
                    for (int i = startIndex; i <= endIndex; i++)
                    {
                        cancellationToken.ThrowIfCancellationRequested();

                        if (vertices[i].Type == ignorableVertexType || vertices[i].DoNotOpt)
                        {
                            continue;
                        }

                        rangeLength++;
                        verticesWithSameMeasure.Add(vertices[i]);
                    }
                    if (rangeLength > 0)
                    {
                        maxRangeLength = Math.Max(rangeLength, maxRangeLength);
                        ranges.Add(rangeLength);
                        rangeCount++;
                    }
                }
            }
            return(verticesWithSameMeasure);
        }
示例#3
0
        private AlternatingLayer InitialOrderingOfNextLayer(AlternatingLayer alternatingLayer, IList <SugiVertex> nextLayer, bool straightSweep)
        {
            //get the list of the containers and vertices
            var segmentContainerStack = new Stack <ISegmentContainer>(alternatingLayer.OfType <ISegmentContainer>().Reverse());
            var ignorableVertexType   = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var vertexStack           = new Stack <SugiVertex>(nextLayer.Where(v => v.Type != ignorableVertexType).OrderBy(v => v.MeasuredPosition).Reverse());
            var newAlternatingLayer   = new AlternatingLayer();

            while (vertexStack.Count > 0 && segmentContainerStack.Count > 0)
            {
                var vertex           = vertexStack.Peek();
                var segmentContainer = segmentContainerStack.Peek();
                if (vertex.MeasuredPosition <= segmentContainer.Position)
                {
                    newAlternatingLayer.Add(vertexStack.Pop());
                }
                else if (vertex.MeasuredPosition >= (segmentContainer.Position + segmentContainer.Count - 1))
                {
                    newAlternatingLayer.Add(segmentContainerStack.Pop());
                }
                else
                {
                    vertexStack.Pop();
                    segmentContainerStack.Pop();
                    int k = (int)Math.Ceiling(vertex.MeasuredPosition - segmentContainer.Position);
                    ISegmentContainer sc1, sc2;
                    segmentContainer.Split(k, out sc1, out sc2);
                    newAlternatingLayer.Add(sc1);
                    newAlternatingLayer.Add(vertex);
                    sc2.Position = segmentContainer.Position + k;
                    segmentContainerStack.Push(sc2);
                }
            }
            if (vertexStack.Count > 0)
            {
                newAlternatingLayer.AddRange(vertexStack.OfType <IData>());
            }
            if (segmentContainerStack.Count > 0)
            {
                newAlternatingLayer.AddRange(segmentContainerStack.OfType <IData>());
            }

            return(newAlternatingLayer);
        }
示例#4
0
        private static AlternatingLayer InitialOrderingOfNextLayer(
            [NotNull, ItemNotNull] AlternatingLayer alternatingLayer,
            [NotNull, ItemNotNull] IEnumerable <SugiVertex> nextLayer,
            bool straightSweep)
        {
            Debug.Assert(alternatingLayer != null);
            Debug.Assert(nextLayer != null);

            // Get the list of the containers and vertices
            var         segmentContainerStack = new Stack <ISegmentContainer>(alternatingLayer.OfType <ISegmentContainer>().Reverse());
            VertexTypes ignorableVertexType   = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var         vertexStack           = new Stack <SugiVertex>(
                nextLayer
                .Where(v => v.Type != ignorableVertexType)
                .OrderBy(v => v.MeasuredPosition)
                .Reverse());
            var newAlternatingLayer = new AlternatingLayer();

            while (vertexStack.Count > 0 && segmentContainerStack.Count > 0)
            {
                SugiVertex        vertex           = vertexStack.Peek();
                ISegmentContainer segmentContainer = segmentContainerStack.Peek();
                if (vertex.MeasuredPosition <= segmentContainer.Position)
                {
                    newAlternatingLayer.Add(vertexStack.Pop());
                }
                else if (vertex.MeasuredPosition >= segmentContainer.Position + segmentContainer.Count - 1)
                {
                    newAlternatingLayer.Add(segmentContainerStack.Pop());
                }
                else
                {
                    vertexStack.Pop();
                    segmentContainerStack.Pop();
                    int k = (int)Math.Ceiling(vertex.MeasuredPosition - segmentContainer.Position);
                    segmentContainer.Split(k, out ISegmentContainer container1, out ISegmentContainer container2);
                    newAlternatingLayer.Add(container1);
                    newAlternatingLayer.Add(vertex);
                    container2.Position = segmentContainer.Position + k;
                    segmentContainerStack.Push(container2);
                }
            }

            if (vertexStack.Count > 0)
            {
                newAlternatingLayer.AddRange(
                    vertexStack
#if !SUPPORTS_ENUMERABLE_COVARIANT
                    .OfType <IData>()
#endif
                    );
            }

            if (segmentContainerStack.Count > 0)
            {
                newAlternatingLayer.AddRange(
                    segmentContainerStack
#if !SUPPORTS_ENUMERABLE_COVARIANT
                    .OfType <IData>()
#endif
                    );
            }

            return(newAlternatingLayer);
        }