Exemple #1
0
        public static PolyLine GetCopy(PolyLine source)
        {
            PolyLine destination = source;    // копирование структуры по полям

            // !!! отдельно обрабатываем поля, являющиеся ссылочными типами данных
            destination.Points = (Point[])source.Points.Clone();

            return(destination);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //PointstWithoutStructs();

            //PointstWithStructs();

            //PolyLine pl1;

            //pl1.Points = null;

            //PolyLine pl1 = new PolyLine() { Points = null };

            PolyLine pl1 = new PolyLine()
            {
                Points = new Point[0]
            };

            BL.Add(ref pl1, new Point()
            {
                X = 2, Y = 12, Color = ConsoleColor.Red
            });
            BL.Add(ref pl1, new Point()
            {
                X = 12, Y = 5, Color = ConsoleColor.Blue
            });
            BL.Add(ref pl1, new Point()
            {
                X = 42, Y = 22, Color = ConsoleColor.Yellow
            });

            Console.WriteLine("pl1 (1)");
            UI.Show(pl1);

            Console.ReadKey();

            //PolyLine pl1Copy = pl1;    // !!! копирование "по-полям"

            PolyLine pl1Copy = BL.GetCopy(pl1);    // !!! копирование полное

            pl1Copy.Points[1].Color = ConsoleColor.Green;

            Console.Clear();

            Console.WriteLine("pl1 (2)");
            UI.Show(pl1);

            Console.ReadKey();
            Console.Clear();

            Console.WriteLine("pl1Copy");
            UI.Show(pl1Copy);

            Console.ReadKey();
        }
Exemple #3
0
        public static void Add(ref PolyLine pl, Point newPoint)
        {
            if (pl.Points == null)
            {
                pl.Points = new Point[] { newPoint };
                return;
            }

            Array.Resize(ref pl.Points, pl.Points.Length + 1);

            pl.Points[pl.Points.Length - 1] = newPoint;
        }
Exemple #4
0
        public static bool IsExist(PolyLine pl, Point p)
        {
            bool existed = false;

            for (int i = 0; i < pl.Points.Length; i++)
            {
                if ((pl.Points[i].X == p.X) && (pl.Points[i].Y == p.Y))
                {
                    existed = true;
                    break;
                }
            }

            return(existed);
        }
Exemple #5
0
 public static void Add(PolyLine pl, Point[] newPoints)
 {
     // ...
 }