Esempio n. 1
0
 private static IGraphSource CreatePascalTriangleGraphSource(int levels)
 {
     var graph = new PascalTriangleGraphSource();
     for (var i = 0; i < levels; i++)
     {
         for (var j = 0; j < i + 1; j++)
         {
             var node = new PascalNode {
                 Position = new Point {
                     Y = RootYPosition + (i * YDelimiterHeight),
                     X = RootXPosition - (i * XStartNegativeOffset) + (j * XDelimiterWidth)
                 },
                 PascalNumber = Binom(i, j),
                 IsTextBoxType = j % 2 == 0
             };
             graph.InternalItems.Add(node);
             var currIndex = (i * (i + 1) / 2) + j;
             if (j == 0) graph.InternalEdges.Add(new PascalEdge { Source = graph.InternalItems[currIndex - i], Target = node });
             if (j == i && i != 0) graph.InternalEdges.Add(new PascalEdge { Source = graph.InternalItems[currIndex - i - 1], Target = node });
             if (0 < j && j < i)
             {
                 graph.InternalEdges.Add(new PascalEdge { Source = graph.InternalItems[currIndex - i - 1], Target = node });
                 graph.InternalEdges.Add(new PascalEdge { Source = graph.InternalItems[currIndex - i], Target = node });
             }
         }
     }
     return graph;
 }
Esempio n. 2
0
        private static IGraphSource CreatePascalTriangleGraphSource(int levels)
        {
            var graph = new PascalTriangleGraphSource();

            for (var i = 0; i < levels; i++)
            {
                for (var j = 0; j < i + 1; j++)
                {
                    var node = new PascalNode {
                        Position = new Point {
                            Y = RootYPosition + (i * YDelimiterHeight),
                            X = RootXPosition - (i * XStartNegativeOffset) + (j * XDelimiterWidth)
                        },
                        PascalNumber  = Binom(i, j),
                        IsTextBoxType = j % 2 == 0
                    };
                    graph.InternalItems.Add(node);
                    var currIndex = (i * (i + 1) / 2) + j;
                    if (j == 0)
                    {
                        graph.InternalEdges.Add(new PascalEdge {
                            Source = graph.InternalItems[currIndex - i], Target = node
                        });
                    }
                    if (j == i && i != 0)
                    {
                        graph.InternalEdges.Add(new PascalEdge {
                            Source = graph.InternalItems[currIndex - i - 1], Target = node
                        });
                    }
                    if (0 < j && j < i)
                    {
                        graph.InternalEdges.Add(new PascalEdge {
                            Source = graph.InternalItems[currIndex - i - 1], Target = node
                        });
                        graph.InternalEdges.Add(new PascalEdge {
                            Source = graph.InternalItems[currIndex - i], Target = node
                        });
                    }
                }
            }
            return(graph);
        }