コード例 #1
0
ファイル: Language.cs プロジェクト: hiromi-mi/kurogane
        public void それぞれ_によるMap処理()
        {
            // リストに対して
            var actual1   = Execute <ListCell>("【○×○】を二乗とする。[1,2,3,4,5]をそれぞれ二乗する。");
            var expected1 = ListCell.Of(1, 4, 9, 16, 25);

            Assert.AreEqual(expected1, actual1);

            var actual2   = Execute <Tuple <object, object> >("【○×2】を二倍とする。3と4をそれぞれ二倍する。");
            var expected2 = new Tuple <object, object>(6, 8);

            Assert.AreEqual(expected2, actual2);

            var actual3   = Execute <ListCell>("[1,2,3]をそれぞれ【□+1】する。");
            var expected3 = ListCell.Of(2, 3, 4);

            Assert.AreEqual(expected3, actual3);

            var actual4   = Execute <ListCell>("[1:2,3:4,5:6,7:8]をそれぞれ【○+△】する。");
            var expected4 = ListCell.Of(3, 7, 11, 15);

            Assert.AreEqual(expected4, actual4);
        }
コード例 #2
0
 /// <summary>
 /// Private constructor turns representation into abstract object.
 /// But since List is a struct, this constructor doesn't actually
 /// do anything but copy the pointer.
 /// </summary>
 /// <param name="headCell">The concrete representation of the list.</param>
 private List(ListCell headCell)
 {
     this.headCell = headCell;
 }
コード例 #3
0
        public override void ApplyLayout(LayoutGraph graph)
        {
            ApplyLayoutCore(graph);

            foreach (Node n in graph.Nodes)
            {
                foreach (Edge e in n.OutEdges)
                {
                    bool        lastSegmentOverlap = false;
                    IEdgeLayout er = graph.GetLayout(e);
                    if (er.PointCount() > 0)
                    {
                        // last bend point
                        YPoint bendPoint = er.GetPoint(er.PointCount() - 1);

                        IEnumerator <Edge> ecc = n.OutEdges.GetEnumerator();
                        loop : while (ecc.MoveNext())
                        {
                            Edge eccEdge = ecc.Current;
                            if (eccEdge != e)
                            {
                                YPointPath path = graph.GetPath(eccEdge);
                                for (ILineSegmentCursor lc = path.LineSegments(); lc.Ok; lc.Next())
                                {
                                    LineSegment seg = lc.LineSegment;
                                    if (seg.Contains(bendPoint))
                                    {
                                        lastSegmentOverlap = true;
                                        goto loop;
                                    }
                                }
                            }
                        }
                    }


                    YList points = graph.GetPointList(e);
                    for (ListCell c = points.FirstCell; c != null; c = c.Succ())
                    {
                        YPoint p = (YPoint)c.Info;
                        if (c.Succ() == null && !lastSegmentOverlap)
                        {
                            break;
                        }

                        YPoint p0 = (YPoint)(c.Pred() == null ? graph.GetSourcePointAbs(e) : c.Pred().Info);
                        YPoint p2;
                        if (Math.Abs(p0.X - p.X) < 0.01)
                        {
                            p2 = new YPoint(p.X, p.Y - 0.001);
                        }
                        else
                        {
                            p2 = new YPoint(p.X - 0.001, p.Y);
                        }

                        points.InsertBefore(p2, c);
                    }
                    graph.SetPoints(e, points);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Get cell thanks to the index
        /// </summary>
        /// <param name="index"></param>
        /// <returns>Cell identified</returns>
        public Cell GetCell(int index)
        {
            Predicate <Cell> filtreCell = (Cell c) => { return(c.Id == index); };

            return(ListCell.Find(filtreCell));
        }
コード例 #5
0
        public static void Main()
        {
            //create new YList instance
            YList list = new YList();

            //add numbered String elements to list
            for (int i = 0; i < 20; i++)
            {
                list.AddLast("" + i);
            }

            //iterate over list from first to last
            Console.WriteLine("List elements from front to back");
            for (ICursor c = list.Cursor(); c.Ok; c.Next())
            {
                //output element at cursor position
                Console.WriteLine(c.Current);
            }

            //iterate over list from last to first
            Console.WriteLine("List elements from back to front");
            ICursor rc = list.Cursor();

            for (rc.ToLast(); rc.Ok; rc.Prev())
            {
                //output element at cursor position
                Console.WriteLine(rc.Current);
            }

            //sort list lexicografically
            list.Sort(new LexicographicComparer());

            //iterate over list from first to last
            Console.WriteLine("Lexicographically sorted list");
            for (ICursor c = list.Cursor(); c.Ok; c.Next())
            {
                //output element at cursor position
                Console.WriteLine(c.Current);
            }

            //low level iteration on list cells (non-const iteration)
            for (ListCell cell = list.FirstCell; cell != null; cell = cell.Succ())
            {
                String s = (String)cell.Info;
                //remove all Strings from list that have length == 1
                if (s.Length == 1)
                {
                    list.RemoveCell(cell);
                    //note that cell is still half-valid, i.e it's Succ() and Pred()
                    //pointers are still unchanged. therefore cell = cell.Succ() is
                    //valid in the for-statement
                }
            }

            Console.WriteLine("list after element removal");
            Console.WriteLine(list);

            //initialize list2 with the elements from list
            YList list2 = new YList(list.Cursor());

            Console.WriteLine("list2 after creation");
            Console.WriteLine(list2);

            //reverse element order in list2
            list2.Reverse();
            Console.WriteLine("list2 after reversal");
            Console.WriteLine(list2);

            //move all elements of list2 to the end of list
            list.Splice(list2);

            Console.WriteLine("list after splicing");
            Console.WriteLine(list);
            Console.WriteLine("list2 after splicing");
            Console.WriteLine(list2);

            Console.WriteLine("\nPress key to end demo.");
            Console.ReadKey();
        }