Exemplo n.º 1
0
        public override void RunTask()
        {
            InitializeArea();
            for (int x = area.MinX; x < area.MaxX; x++)
            {
                for (int y = area.MinY; y < area.MaxY; y++)
                {
                    CheckedPoint point            = new CheckedPoint(x, y);
                    RootPoint    closestRootPoint = area.GetClosesRootPoint(point);
                    if (closestRootPoint == null)
                    {
                        continue;
                    }
                    area.RootPoints.FirstOrDefault(pt => pt.Number == closestRootPoint.Number).Points.Add(point);
                    //point.RootPoint = sourceRootPoint;
                    //sourceRootPoint.Points.Add(point);
                }
            }
            area.SetBoundriesFlags();
            List <RootPoint> boundedPoints = area.GetBoundedPoints();

            RootPoint maxAreaPoint = boundedPoints.OrderByDescending(x => x.Area).First();

            Console.WriteLine("Point {0} has max area of {1}", maxAreaPoint.Number, maxAreaPoint.Area);
        }
Exemplo n.º 2
0
        private void InitializeArea()
        {
            List <string>    rootNodes = ReadLines();
            List <RootPoint> points    = new List <RootPoint>();

            foreach (var point in rootNodes)
            {
                points.Add(RootPoint.FromStringCoordinates(point));
            }
            area = new Area(points);
        }
Exemplo n.º 3
0
        public RootPoint GetClosesRootPoint(CheckedPoint point)
        {
            int       minDistance  = int.MaxValue;
            RootPoint closestPoint = null;

            foreach (var rootPoint in RootPoints)
            {
                int distance = rootPoint.CalculateDistance(point);
                if (distance == minDistance)
                {
                    return(null);
                }
                if (distance < minDistance)
                {
                    minDistance  = distance;
                    closestPoint = rootPoint;
                }
            }
            return(closestPoint);
        }