Esempio n. 1
0
            public bool IsVertice(int index)
            {
                int round = Shape.RoundOf(index);

                if (!VerticesPositions.ContainsKey(round))
                {
                    VerticesPositions.Add(round, getVerticeOfRound(round));
                }

                return(VerticesPositions[round].ContainsKey(index));
            }
Esempio n. 2
0
        /// <summary>
        /// Initializes the data of the compound vertices.
        /// </summary>
        /// <param name="verticesBorders">Dictionary of the vertices border thicknesses.</param>
        /// <param name="verticesSizes">Dictionary of the vertices sizes.</param>
        /// <param name="layoutTypes">Dictionary of the layout types.</param>
        /// <param name="movableParentUpdateQueue">
        /// The compound vertices with fixed layout should be added to this queue.
        /// </param>
        private void InitCompoundVertices(
            [NotNull] IDictionary <TVertex, Thickness> verticesBorders,
            [NotNull] IDictionary <TVertex, Size> verticesSizes,
            [NotNull] IDictionary <TVertex, CompoundVertexInnerLayoutType> layoutTypes,
            [NotNull, ItemNotNull] Queue <TVertex> movableParentUpdateQueue)
        {
            for (int i = Levels.Count - 1; i >= 0; --i)
            {
                foreach (TVertex vertex in Levels[i])
                {
                    if (!_compoundGraph.IsCompoundVertex(vertex))
                    {
                        continue;
                    }

                    // Get the data of the vertex
                    verticesBorders.TryGetValue(vertex, out Thickness border);

                    verticesSizes.TryGetValue(vertex, out Size vertexSize);
                    layoutTypes.TryGetValue(vertex, out CompoundVertexInnerLayoutType layoutType);

                    if (layoutType == CompoundVertexInnerLayoutType.Fixed)
                    {
                        movableParentUpdateQueue.Enqueue(vertex);
                    }

                    VerticesPositions.TryGetValue(vertex, out Point position);

                    // Create the information container for this compound vertex
                    var dataContainer = new CompoundVertexData(vertex, _rootCompoundVertex, false, position, vertexSize, border, layoutType);
                    if (i == 0)
                    {
                        dataContainer.Parent = _rootCompoundVertex;
                        // ReSharper disable once PossibleNullReferenceException, Justification: root always has children
                        _rootCompoundVertex.Children.Add(dataContainer);
                    }
                    _compoundVerticesData[vertex] = dataContainer;
                    _verticesData[vertex]         = dataContainer;

                    // Add the data of the children
                    IEnumerable <TVertex> children     = _compoundGraph.GetChildrenVertices(vertex);
                    List <VertexData>     childrenData = children.Select(v => _verticesData[v]).ToList();
                    dataContainer.Children = childrenData;
                    foreach (VertexData child in dataContainer.Children)
                    {
                        // ReSharper disable once PossibleNullReferenceException, Justification: root always has children
                        _rootCompoundVertex.Children.Remove(child);
                        child.Parent = dataContainer;
                    }
                }
            }
        }
        /// <inheritdoc />
        protected override void Initialize()
        {
            base.Initialize();

            _fixedPositions = VerticesPositions
                              .Where(pair => _verticesTypes.TryGetValue(pair.Key, out RandomVertexType type) &&
                                     type == RandomVertexType.Fixed)
                              .ToDictionary(pair => pair.Key, pair => pair.Value);

            VerticesPositions.Clear();

            foreach (KeyValuePair <TVertex, Point> pair in _fixedPositions)
            {
                VerticesPositions.Add(pair);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Initializes the data of the simple vertices.
        /// </summary>
        /// <param name="verticesSizes">Dictionary of the vertex sizes.</param>
        private void InitSimpleVertices([NotNull] IDictionary <TVertex, Size> verticesSizes)
        {
            foreach (TVertex vertex in _compoundGraph.SimpleVertices)
            {
                verticesSizes.TryGetValue(vertex, out Size vertexSize);

                VerticesPositions.TryGetValue(vertex, out Point position);

                // Create the information container for this simple vertex
                var dataContainer = new SimpleVertexData(vertex, _rootCompoundVertex, false, position, vertexSize)
                {
                    Parent = _rootCompoundVertex
                };
                _verticesData[vertex] = dataContainer;
                // ReSharper disable once PossibleNullReferenceException, Justification: root always has children
                _rootCompoundVertex.Children.Add(dataContainer);
            }
        }
Esempio n. 5
0
            public PointF PositionOfIndex(int index)
            {
                if (Shape.IsPolygon)
                {
                    int round = Shape.RoundOf(index);

                    if (!VerticesPositions.ContainsKey(round))
                    {
                        VerticesPositions.Add(round, getVerticeOfRound(round));
                    }

                    if (VerticesPositions[round].ContainsKey(index))
                    {
                        return(VerticesPositions[round][index]);
                    }
                    else
                    {
                        Double edgeLength = Shape.LengthOfRound(round) / Shape.Edges;

                        int previousVertex = (from vIndex in VerticesPositions[round].Keys
                                              where index > vIndex
                                              select vIndex).LastOrDefault();

                        int nextVertex = (from vIndex in VerticesPositions[round].Keys
                                          where index < vIndex
                                          select vIndex).Min();

                        if (nextVertex == 0)
                        {
                            throw new Exception();
                        }

                        PointF prev, next;
                        if (previousVertex == 0)
                        {
                            previousVertex = (from vIndex in VerticesPositions[round].Keys
                                              select vIndex).Last();
                            prev = VerticesPositions[round][previousVertex];
                            next = VerticesPositions[round][nextVertex];
                        }
                        else
                        {
                            prev = VerticesPositions[round][previousVertex];
                            next = VerticesPositions[round][nextVertex];
                        }
                        double x, y;

                        x = next.X - (next.X - prev.X) * (nextVertex - index) / edgeLength;
                        y = next.Y - (next.Y - prev.Y) * (nextVertex - index) / edgeLength;

                        return(new PointF((float)x, (float)y));
                    }
                }
                else
                {
                    Double tan, radius, x, y;
                    int    round;

                    if (index > 360 && index != 361)
                    {
                        index %= 360;
                    }

                    round = Shape.RoundOf(index);

                    tan    = Math.Tan(Math.PI / Shape.Edges);
                    radius = 0.5 / tan + round - 1;
                    Angle angle;

                    if (round == 0)
                    {
                        angle = Shape.Vertices[Shape.Edges - 1];
                    }
                    else
                    {
                        angle = Shape.Vertices[(index + Shape.Edges - 1) % Shape.Edges];
                    }
                    x = radius * Math.Cos(angle.Radians);
                    y = radius * Math.Sin(angle.Radians);
                    return(new PointF((float)x, (float)y));
                }
            }