Пример #1
0
        public void RectaglesIntersectionTest4()
        {
            var res = GeometricSolver.AreModuleInBounds(
                new Point(0, 0),
                new Point(10, 10),
                new Point(-5, -5),
                new Point(20, 20));

            Assert.IsTrue(res);
        }
Пример #2
0
        public void RectaglesIntersectionTest2()
        {
            var res = GeometricSolver.AreModuleInBounds(
                new Point(0, 0),
                new Point(10, 10),
                new Point(11, 11),
                new Point(20, 20));

            Assert.IsFalse(res);
        }
Пример #3
0
        /// <summary>
        /// Приводит плату к корректному виду без пересечений модулей
        /// </summary>
        /// <param name="modules"> Список модулей которые нужно проверить на пересечение</param>
        public void LeadToCorrectForm(List <Module> modules)
        {
            int swapCount  = 0;
            var notVisited = modules.ToList();

            foreach (var e in notVisited)
            {
                if (!Modules.Contains(e))
                {
                    throw new Exception("Invalid arguments for lead to correct form");
                }
            }
            var rnd = new Random();

            while (true)
            {
                if (notVisited.Count == 0)
                {
                    break;
                }
                var curModule = notVisited[notVisited.Count - 1];
                notVisited.Remove(curModule);

                foreach (var module in Modules)
                {
                    if (curModule.Equals(module))
                    {
                        continue;
                    }

                    if (AreModulesIntersect(curModule, module))
                    {
                        swapCount++;
                        if (module.IsLocked())
                        {
                            DivideModules(module, curModule);
                        }
                        else
                        {
                            DivideModules(curModule, module);
                        }
                        if (!notVisited.Contains(module))
                        {
                            notVisited.Add(module);
                        }
                        if (!GeometricSolver.AreModuleInBounds(module.LeftUpperBound + module.Position,
                                                               module.RighLowerBound + module.Position,
                                                               Chromosome.LeftUpperPoint,
                                                               new Point(Chromosome.LeftUpperPoint.X + Chromosome.WorkspaceWidth,
                                                                         Chromosome.LeftUpperPoint.Y + Chromosome.WorkspaceHeight)))
                        {
                            module.Position = GeometricSolver.GetRandomPointInRange(Chromosome.WorkspaceWidth, Chromosome.WorkspaceHeight, rnd) + Chromosome.LeftUpperPoint;
                        }
                    }
                }
                if (swapCount > 500)
                {
                    break;
                }
            }
        }