示例#1
0
        private void PlaceQVertices(
            [NotNull, ItemNotNull] AlternatingLayer alternatingLayer,
            [NotNull, ItemNotNull] IEnumerable <SugiVertex> nextLayer,
            bool straightSweep)
        {
            Debug.Assert(alternatingLayer != null);
            Debug.Assert(nextLayer != null);

            VertexTypes type      = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var         qVertices = new HashSet <SugiVertex>();

            foreach (SugiVertex vertex in nextLayer)
            {
                if (vertex.Type != type)
                {
                    continue;
                }

                qVertices.Add(vertex);
            }

            for (int i = 0; i < alternatingLayer.Count; ++i)
            {
                var segmentContainer = alternatingLayer[i] as SegmentContainer;
                if (segmentContainer is null)
                {
                    continue;
                }

                for (int j = 0; j < segmentContainer.Count; ++j)
                {
                    ThrowIfCancellationRequested();

                    Segment    segment = segmentContainer[j];
                    SugiVertex vertex  = straightSweep ? segment.QVertex : segment.PVertex;
                    if (!qVertices.Contains(vertex))
                    {
                        continue;
                    }

                    alternatingLayer.RemoveAt(i);
                    segmentContainer.Split(segment, out ISegmentContainer container1, out ISegmentContainer container2);
                    container1.Position = segmentContainer.Position;
                    container2.Position = segmentContainer.Position + container1.Count + 1;
                    alternatingLayer.Insert(i, container1);
                    alternatingLayer.Insert(i + 1, vertex);
                    alternatingLayer.Insert(i + 2, container2);
                    ++i;
                    break;
                }
            }
        }
示例#2
0
        private void PlaceQVertices(AlternatingLayer alternatingLayer, IList <SugiVertex> nextLayer, bool straightSweep, CancellationToken cancellationToken)
        {
            var type      = straightSweep ? VertexTypes.QVertex : VertexTypes.PVertex;
            var qVertices = new HashSet <SugiVertex>();

            foreach (var vertex in nextLayer)
            {
                if (vertex.Type != type)
                {
                    continue;
                }

                qVertices.Add(vertex);
            }

            for (int i = 0; i < alternatingLayer.Count; i++)
            {
                var segmentContainer = alternatingLayer[i] as SegmentContainer;
                if (segmentContainer == null)
                {
                    continue;
                }
                for (int j = 0; j < segmentContainer.Count; j++)
                {
                    cancellationToken.ThrowIfCancellationRequested();

                    var segment = segmentContainer[j];
                    var vertex  = straightSweep ? segment.QVertex : segment.PVertex;
                    if (!qVertices.Contains(vertex))
                    {
                        continue;
                    }

                    alternatingLayer.RemoveAt(i);
                    ISegmentContainer sc1, sc2;
                    segmentContainer.Split(segment, out sc1, out sc2);
                    sc1.Position = segmentContainer.Position;
                    sc2.Position = segmentContainer.Position + sc1.Count + 1;
                    alternatingLayer.Insert(i, sc1);
                    alternatingLayer.Insert(i + 1, vertex);
                    alternatingLayer.Insert(i + 2, sc2);
                    i = i + 1;
                    break;
                }
            }
        }
示例#3
0
        private static void ReinsertVerticesIntoLayer(
            AlternatingLayer layer,
            HashSet <SugiVertex> vertexSet,
            IList <SugiVertex> vertexList)
        {
            int reinsertIndex = 0;

            for (int i = 0; i < layer.Count; i++)
            {
                var vertex = layer[i] as SugiVertex;
                if (vertex == null || !vertexSet.Contains(vertex))
                {
                    continue;
                }

                layer.RemoveAt(i);
                layer.Insert(i, vertexList[reinsertIndex]);
                reinsertIndex++;
            }
        }
示例#4
0
        private static void ReinsertVerticesIntoLayer(
            [NotNull, ItemNotNull] AlternatingLayer layer,
            [NotNull, ItemNotNull] ICollection <SugiVertex> vertexSet,
            [NotNull, ItemNotNull] IList <SugiVertex> vertexList)
        {
            Debug.Assert(layer != null);
            Debug.Assert(vertexSet != null);
            Debug.Assert(vertexList != null);

            int reinsertIndex = 0;

            for (int i = 0; i < layer.Count; ++i)
            {
                var vertex = layer[i] as SugiVertex;
                if (vertex is null || !vertexSet.Contains(vertex))
                {
                    continue;
                }

                layer.RemoveAt(i);
                layer.Insert(i, vertexList[reinsertIndex]);
                ++reinsertIndex;
            }
        }