Beispiel #1
0
        public void TestMethod22()
        {
            PointTree pointTree = new PointTree();
            int       number    = pointTree.Count;

            Assert.AreEqual(0, number);
        }
Beispiel #2
0
        public void TestMethod23()
        {
            PointTree pointTree = new PointTree(new Animals("", "", 1));
            int       number    = pointTree.Count;

            Assert.AreEqual(1, number);
        }
Beispiel #3
0
        private static void AddElementInSearchTree(ref PointTree newTree, int data)
        {
            var newItem = new PointTree(data);

            if (newTree == null)
            {
                newTree = newItem;
                return;
            }

            var r = newTree;


            if (data < r.data)
            {
                while (r.left != null)
                {
                    r = r.left;
                }
                r.left = newItem;
            }
            else
            {
                while (r.right != null)
                {
                    r = r.right;
                }
                r.right = newItem;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Подменю "Бинарное дерево"
        /// </summary>
        private static void TreeMenu()
        {
            int       userAnswer;
            PointTree startOfTree = null;

            do
            {
                Dialog.PrintMenu2ndLevelTree();
                userAnswer = Dialog.InputNumber("Введите пункт меню", 1, 5);
                switch (userAnswer)
                {
                case 1:    //сформировать идеально сбалансированное дерево
                {
                    startOfTree = IdealTree(7, startOfTree);
                    break;
                }

                case 2:    //распечатать дерево
                {
                    ShowTree(startOfTree, 1);
                    break;
                }

                case 3:    //найти минимальный элемент в дереве
                {
                    if (startOfTree == null)
                    {
                        Console.WriteLine("Дерево не сформировано");
                    }
                    else
                    {
                        int currentMin = startOfTree.data;
                        FindMinElementTree(startOfTree, ref currentMin);
                        Console.WriteLine($"Минимальный элемент в дереве: {currentMin}");
                    }
                    break;
                }

                case 4:    //преобразовать идеально сбалансированное дерево в дерево поиска
                {
                    if (startOfTree == null)
                    {
                        Console.WriteLine("Дерево не сформировано");
                    }
                    else
                    {
                        PointTree newTree = null;
                        MakeSearchTree(startOfTree, ref newTree);
                        ShowTree(newTree, 1);
                    }
                    break;
                }

                default:
                    break;
                }
            } while (userAnswer != 5);
        }
Beispiel #5
0
 private static void MakeSearchTree(PointTree p, ref PointTree newTree)
 {
     if (p != null)
     {
         MakeSearchTree(p.left, ref newTree);
         AddElementInSearchTree(ref newTree, p.data);
         MakeSearchTree(p.right, ref newTree);
     }
 }
Beispiel #6
0
        public void TestMethodTree3()
        {
            //Arrange
            PointTree <string> p = new PointTree <string>("aa");

            //Act
            Tree <string> t = new Tree <string>(p);

            //Assert
            Assert.IsTrue(t.Length() == 1);
        }
Beispiel #7
0
        public void TestMethod25()
        {
            PointTree pointTree = new PointTree(new Animals("A", "A", 10000));

            pointTree.Add(new Animals("A", "B", 300));
            pointTree.Add(new Animals("A", "C", 3600));
            pointTree.Add(new Animals("B", "B", 4300));
            Animals a = pointTree.FindMax();

            Assert.AreEqual(a, new Animals("A", "A", 10000));
        }
Beispiel #8
0
 static void FindMinElementTree(PointTree p, ref int min)
 {
     if (p != null)
     {
         FindMinElementTree(p.left, ref min);
         if (p.data < min)
         {
             min = p.data;
         }
         FindMinElementTree(p.right, ref min);
     }
 }
Beispiel #9
0
        public void TestMethod26()
        {
            Animals   a         = new Animals();
            PointTree pointTree = new PointTree(new Animals());

            pointTree.Add((Animals)a.CreateObjectAnimalsRandom().Clone());
            pointTree.Add((Animals)a.CreateObjectAnimalsRandom().Clone());
            pointTree.Add((Animals)a.CreateObjectAnimalsRandom().Clone());
            pointTree.CreateFindTree();
            int number = pointTree.Count;

            Assert.AreEqual(4, number);
        }
Beispiel #10
0
 static void ShowTree(PointTree p, int l)
 {
     if (p != null)
     {
         ShowTree(p.left, l + 3);//переход к левому поддереву
         for (int i = 0; i < l; i++)
         {
             Console.Write(" ");    //формирование отступа
         }
         Console.WriteLine(p.data); //печать узла
         ShowTree(p.right, l + 3);  //переход к правому поддереву
     }
 }
Beispiel #11
0
        private bool CheckCollision(RectangleF rect)
        {
            rect.Inflate(1, 1);

            var rectangles = PointTree.GetObjects(rect).Select(r => r.Rect);

            if (!CheckCollision(rect, rectangles))
            {
                return(false);
            }

            return(true);
        }
Beispiel #12
0
        static PointTree IdealTree(int size, PointTree p)
        {
            PointTree r;
            int       nl, nr;

            if (size == 0)
            {
                p = null;
                return(p);
            }
            nl = size / 2;
            nr = size - nl - 1;
            int info = Dialog.InputNumber("Введите число от 1 до 100", 1, 100);

            r       = new PointTree(info);
            r.left  = IdealTree(nl, r.left);
            r.right = IdealTree(nr, r.right);
            return(r);
        }
        private static void GetDublicateBlocks([NotNull] IEnumerable ids, Matrix3d transToModel, double rotate)
        {
            var idsBtrNext = new List <Tuple <ObjectId, Matrix3d, double> >();

            var isFirstDbo = true;

            foreach (var item in ids)
            {
                if (!(item is ObjectId))
                {
                    continue;
                }
                var idEnt = (ObjectId)item;
                if (!idEnt.IsValidEx())
                {
                    continue;
                }
                var dbo = idEnt.GetObject(OpenMode.ForRead, false, true);

                // Проверялся ли уже такое определение блока
                if (isFirstDbo)
                {
                    isFirstDbo = false;
                    if (!attemptedblocks.Add(dbo.OwnerId))
                    {
                        continue;
                    }
                }

                var blRef = dbo as BlockReference;
                if (blRef == null || !blRef.Visible)
                {
                    continue;
                }
                var blRefInfo = new BlockRefDublicateInfo(blRef, transToModel, rotate);

                if (_ignoreBlocks != null && _ignoreBlocks.Contains(blRefInfo.Name, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }

                var ptTree = new PointTree(blRefInfo.Position.X, blRefInfo.Position.Y);

                if (!dictBlRefInfos.TryGetValue(blRefInfo.Name, out var dictPointsBlInfos))
                {
                    dictPointsBlInfos = new Dictionary <PointTree, List <BlockRefDublicateInfo> >();
                    dictBlRefInfos.Add(blRefInfo.Name, dictPointsBlInfos);
                }

                if (!dictPointsBlInfos.TryGetValue(ptTree, out var listBiAtPoint))
                {
                    listBiAtPoint = new List <BlockRefDublicateInfo>();
                    dictPointsBlInfos.Add(ptTree, listBiAtPoint);
                }

                listBiAtPoint.Add(blRefInfo);

                idsBtrNext.Add(new Tuple <ObjectId, Matrix3d, double>(
                                   blRef.BlockTableRecord, blRef.BlockTransform * transToModel, blRef.Rotation + rotate));
            }

            // Нырок глубже
            if (curDepth < DEPTH)
            {
                curDepth++;
                foreach (var btrNext in idsBtrNext)
                {
                    var btr = (BlockTableRecord)btrNext.Item1.GetObject(OpenMode.ForRead);
                    GetDublicateBlocks(btr, btrNext.Item2, btrNext.Item3);
                }
            }
        }
Beispiel #14
0
                  right; //адрес правого поддерева
 public PointTree()
 {
     data  = 0;
     left  = null;
     right = null;
 }
Beispiel #15
0
 public PointTree(int d)
 {
     data  = d;
     left  = null;
     right = null;
 }
Beispiel #16
0
        public void Insert(IEnumerable <RectangleF> rects)
        {
            var rectList = rects.ToList();

            PointTree.AddRange(rectList.SelectMany(GetEdgePoints));
        }
        private static void GetDublicateBlocks(IEnumerable ids, Matrix3d transToModel, double rotate)
        {
            List<Tuple<ObjectId, Matrix3d, double>> idsBtrNext = new List<Tuple<ObjectId, Matrix3d, double>>();

            bool isFirstDbo = true;

            foreach (var item in ids)
            {
                if (!(item is ObjectId)) continue;
                ObjectId idEnt = (ObjectId)item;

                var dbo = idEnt.GetObject(OpenMode.ForRead, false, true);
                // Проверялся ли уже такое определение блока
                if (isFirstDbo)
                {
                    isFirstDbo = false;
                    if (!attemptedblocks.Add(dbo.OwnerId))
                    {
                        continue;
                    }
                }

                var blRef = dbo as BlockReference;
                if (blRef == null || !blRef.Visible) continue;
                BlockRefDublicateInfo blRefInfo = new BlockRefDublicateInfo(blRef, transToModel, rotate);

                if (_ignoreBlocks!=null && _ignoreBlocks.Contains(blRefInfo.Name, StringComparer.OrdinalIgnoreCase))
                {
                    continue;
                }

                Dictionary<PointTree, List<BlockRefDublicateInfo>> dictPointsBlInfos;
                PointTree ptTree = new PointTree(blRefInfo.Position.X, blRefInfo.Position.Y);

                if (!dictBlRefInfos.TryGetValue(blRefInfo.Name, out dictPointsBlInfos))
                {
                    dictPointsBlInfos = new Dictionary<PointTree, List<BlockRefDublicateInfo>>();
                    dictBlRefInfos.Add(blRefInfo.Name, dictPointsBlInfos);
                }
                List<BlockRefDublicateInfo> listBiAtPoint;
                if (!dictPointsBlInfos.TryGetValue(ptTree, out listBiAtPoint))
                {
                    listBiAtPoint = new List<BlockRefDublicateInfo>();
                    dictPointsBlInfos.Add(ptTree, listBiAtPoint);
                }
                listBiAtPoint.Add(blRefInfo);

                idsBtrNext.Add(new Tuple<ObjectId, Matrix3d, double>(item1: blRef.BlockTableRecord, item2: blRef.BlockTransform* transToModel, item3: blRef.Rotation + rotate));
            }

            // Нырок глубже
            if (curDepth < DEPTH)
            {
                curDepth++;
                foreach (var btrNext in idsBtrNext)
                {
                    var btr = btrNext.Item1.GetObject(OpenMode.ForRead) as BlockTableRecord;
                    GetDublicateBlocks(btr, btrNext.Item2, btrNext.Item3);
                }
            }
        }