当前位置: 首页>>代码示例>>C#>>正文


C# Line.Clone方法代码示例

本文整理汇总了C#中Line.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Line.Clone方法的具体用法?C# Line.Clone怎么用?C# Line.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Line的用法示例。


在下文中一共展示了Line.Clone方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NodePointLine

 public NodePointLine(Line owner, ePoint id)
 {
     m_owner = owner;
     m_clone = m_owner.Clone() as Line;
     m_pointId = id;
     m_originalPoint = GetPoint(m_pointId);
 }
开发者ID:sduxiaowu,项目名称:NineLineScore,代码行数:7,代码来源:LineTool.cs

示例2: Run

        public Line Run(Point[] _points, string id = "")
        {
            const int maxiterations = 1001;

            Point[] points = _points;
            Utilities utilities = new Utilities(points);
            Line[] newpopulation = new Line[utilities.lines.Length];
            Directory.CreateDirectory("Output/" + name + " Verbose Output/");
            using (TextWriter output = File.AppendText("Output/" + name + " Verbose Output/" + name + "-Verbose" + id + ".csv"))
            using (TextWriter meta = File.AppendText("Output/" + name + " Verbose Output/" + name + "-Meta" + id + ".csv")) // after every run, find the metadata file and add to it.
            {

                output.WriteLine("Seeds:");
                foreach (Line line in utilities.lines)
                {
                    Console.WriteLine("Seed: {0}x + {1}y = {2}", line.a, line.b, line.c);
                    output.WriteLine("{0}x + {1}y = {2}", line.a, line.b, line.c);
                }
                output.WriteLine(""); //newline
                Line bestLine = new Line(0, 0, 0);
                meta.WriteLine("Set,Best Average Distance,Average Average Distance");
                for (int enforcingmax = 0; enforcingmax < maxiterations; enforcingmax++)
                {
                    Console.WriteLine("Population {0} - Members:", enforcingmax);
                    output.WriteLine();
                    output.WriteLine("Population {0} - Members:", enforcingmax);
                    output.WriteLine("Line,Average Variance,Fitness");
                    if (utilities.lines.Length % 2 == 0) // An array with elements n has the length n-1 starting from 0
                    {
                        for (int i = 0; i < utilities.lines.Length; i += 2)
                        {
                            Line first = utilities.FairRandom();
                            Parents nextTwo = new Parents(first, utilities.FairRandom(utilities.lines.Where(x => x != first).ToArray())); // no need to worry about identification issues because this is reference object, and only bounced around in Select method - not copied
                            // combine and rise again? Something like that.
                            Parents pheonix = utilities.Combine(nextTwo);
                            newpopulation[i] = pheonix.father;
                            newpopulation[i + 1] = pheonix.mother;
                        }
                        utilities.lines = newpopulation.Clone() as Line[];
                        Array.Clear(newpopulation, 0, newpopulation.Length); // Reset for next gen
                        utilities.GiveChances();
                        foreach (Line line in utilities.lines)
                        {
                            // spit out put
                            Console.WriteLine("{0}x + {1}y = {2}", line.a, line.b, line.c);
                            output.WriteLine("{0}x + {1}y = {2},{3},{4}", line.a, line.b, line.c, line.averageDistance, line.selectionChance);
                        }
                        meta.WriteLine("Generation {0},{1},{2}", enforcingmax, utilities.lines.OrderBy(x => x.averageDistance).First().averageDistance, (utilities.lines.Sum(x => x.averageDistance) / utilities.lines.Length));
                    }
                    else if (utilities.lines.Length % 2 == 1)
                    {
                        for (int i = 0; i < utilities.lines.Length - 1; i += 2)
                        {
                            Line first = utilities.FairRandom();
                            Parents nextTwo = new Parents(first, utilities.FairRandom(utilities.lines.Where(x => x != first).ToArray()));

                            Parents pheonix = utilities.Combine(nextTwo);
                            newpopulation[i] = pheonix.father;
                            newpopulation[i + 1] = pheonix.mother;
                        }

                        Line second = utilities.FairRandom(); // There is room only for one
                        Parents nextOne = new Parents(second, utilities.FairRandom(utilities.lines.Where(x => x.selectionChance != second.selectionChance).ToArray()));
                        Line mysognist = utilities.Combine(nextOne).father;
                        newpopulation[newpopulation.Length - 1] = mysognist;

                        utilities.lines = newpopulation.Clone() as Line[];
                        Array.Clear(newpopulation, 0, newpopulation.Length);
                        utilities.GiveChances();
                        foreach(Line line in utilities.lines)
                        {
                            // spit out more put
                            Console.WriteLine("{0}x + {1}y = {2}", line.a, line.b, line.c);
                            output.WriteLine("{0}x + {1}y = {2},{3},{4}", line.a, line.b, line.c, line.averageDistance, line.selectionChance);
                        }
                        meta.WriteLine("Trial {1},{2},{3}", enforcingmax, utilities.lines.OrderBy(x => x.averageDistance).First().averageDistance, (utilities.lines.Sum(x => x.averageDistance) / utilities.lines.Length));
                    }
                }
                output.WriteLine();
                meta.WriteLine();
                bestLine = utilities.lines.OrderBy(x => x.averageDistance).First();
                Console.WriteLine("Final Best Line: {0}x + {1}y = {2}", bestLine.a, bestLine.b, bestLine.c);
                return bestLine;
            }
        }
开发者ID:ThePlatinumTaco,项目名称:ScienceFairConsole,代码行数:85,代码来源:Program.cs

示例3: ModifyingGroups

        public static void ModifyingGroups()
        {
            Line line1 = new Line(new Vector2(0, 0), new Vector2(100, 100));
            line1.Color = AciColor.Red;
            Line line2 = new Line(new Vector2(100, 0), new Vector2(200, 100));
            line2.Color = AciColor.Yellow;
            Line line3 = new Line(new Vector2(200, 0), new Vector2(300, 100));
            line3.Color = AciColor.Magenta;

            DxfDocument doc = new DxfDocument();

            Block blk = new Block("MyBlock");
            blk.Entities.Add(line1);
            Insert ins = new Insert(blk);
            doc.AddEntity(ins);

            doc.AddEntity(line2);

            Layout layout = new Layout("Layout1");
            doc.Layouts.Add(layout);
            doc.ActiveLayout = layout.Name;
            doc.AddEntity(line3);
            
            // group
            Group group = new Group("MyGroup");
            doc.Groups.Add(group);

            // the Add method will also add the entities contained in a group to the document (in the active layout).
            doc.Groups.Add(group);

            // when the group belongs to a document, all entities must belong to the same document.
            // even if it does not sound very useful, a group can contain entities that belongs to different layouts and even blocks.
            group.Entities.Add(line1);
            group.Entities.Add(line2);
            group.Entities.Add(line3);

            Line line4 = new Line(new Vector2(300, 0), new Vector2(400, 100));
            line4.Color = AciColor.Blue;
            // if a new entity, that does not belong to any document, is added to the group, it will be added to the group document active layout.
            doc.ActiveLayout = Layout.ModelSpaceName;
            group.Entities.Add(line4);

            Line line5 = new Line(new Vector2(400, 0), new Vector2(500, 100));
            line5.Color = AciColor.Green;
            DxfDocument doc2 = new DxfDocument();
            doc2.AddEntity(line5);

            // this is illegal, line5 belongs to another document.
            //group.Entities.Add(line5);
            // you need to clone the entity before adding it to the group. This is also the common practice to copy entities between documents.
            group.Entities.Add((EntityObject) line5.Clone());

            // remember removing a group only deletes it from the collection not the entities
            //doc.Groups.Remove(group);
            doc.Save("group.dxf");

            doc = DxfDocument.Load("group.dxf");
        }
开发者ID:NTUST-PTL,项目名称:PTL-Project,代码行数:58,代码来源:Program.cs


注:本文中的Line.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。