Exemple #1
0
        private void CheckAround(Point p, int range)
        {
            for (int x = -range; x <= range; x++)
            {
                for (int y = -range; y <= range; y++)
                {
                    var p2 = new Point(p.x + x, p.y + y);

                    if (x == 0 && y == 0)
                    {
                        continue; // Dont check center
                    }

                    if (p2.y < 0 || p2.x < 0)
                    {
                        continue; // dont check negative values
                    }

                    // only check if the value is on the border

                    if ((x != -range && x != range) && (y != -range && y != range))
                    {
                        continue;
                    }

                    if (astroids2.ContainsKey(p2))
                    {
                        if (astroids2[p2])
                        {
                            int deltaX = p2.x - p.x;
                            int deltaY = p2.y - p.y;
                            var cd     = mm.GCD(Math.Abs(deltaX), Math.Abs(deltaY));

                            if (cd == 1) //
                            {
                                // Im possible to find a astroid that is closer
                                //astroidDetect[p] += 1;
                            }
                            else
                            {
                                // possibility for a match in smaller items
                                // check for the posibilty

                                int  smallX = deltaX / (int)cd;
                                int  smally = deltaY / (int)cd;
                                bool found  = false;


                                for (int i = (int)cd - 1; i > 0; i--)
                                {
                                    if (astroids2[new Point(p.x + (smallX * i), p.y + (smally * i))])
                                    {
                                        // Found a astroid that is close by
                                        found = true;
                                    }
                                }

                                if (found) // Found a astroid that is closer
                                {
                                    // Just disable the astroid for now, no need to check it anymore
                                    astroids2[p2] = false;
                                }
                                else // Didnt found an astroid that is closer. add the astroid
                                {
                                    //astroidDetect[p] += 1;
                                }
                            }



                            if (p.x == 11 && p.y == 13)
                            {
                                var l = 1;
                            }
                        }
                    }
                }
            }
        }