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);
        }
Example #2
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);
        }