Exemple #1
0
        private IEnumerable<ILocation> buildAdjacentLocations(ILocation parent)
        {
            ILocation[] results = new ILocation[8];

            Point[] coordinates = new Point[8];
            namDirections[] directionArray = new namDirections[8];
            int adjustedSize = this.Rect.Width;   // size is distance from center to edge,
            // double to ensure we end up outside of this box

            directionArray[(int)namDirections.East] = namDirections.East;
            directionArray[(int)namDirections.North] = namDirections.North;
            directionArray[(int)namDirections.NorthEast] = namDirections.NorthEast;
            directionArray[(int)namDirections.NorthWest] = namDirections.NorthWest;
            directionArray[(int)namDirections.South] = namDirections.South;
            directionArray[(int)namDirections.SouthEast] = namDirections.SouthEast;
            directionArray[(int)namDirections.SouthWest] = namDirections.SouthWest;
            directionArray[(int)namDirections.West] = namDirections.West;

            coordinates[(int)namDirections.East] = new Point(this.Rect.Center.X + adjustedSize, this.Rect.Center.Y);
            coordinates[(int)namDirections.North] = new Point(this.Rect.Center.X, this.Rect.Center.Y - adjustedSize);
            coordinates[(int)namDirections.NorthEast] = new Point(this.Rect.Center.X + adjustedSize, this.Rect.Center.Y - adjustedSize);
            coordinates[(int)namDirections.NorthWest] = new Point(this.Rect.Center.X - adjustedSize, this.Rect.Center.Y - adjustedSize);
            coordinates[(int)namDirections.South] = new Point(this.Rect.Center.X, this.Rect.Center.Y + adjustedSize);
            coordinates[(int)namDirections.SouthEast] = new Point(this.Rect.Center.X + adjustedSize, this.Rect.Center.Y + adjustedSize);
            coordinates[(int)namDirections.SouthWest] = new Point(this.Rect.Center.X - adjustedSize, this.Rect.Center.Y + adjustedSize);
            coordinates[(int)namDirections.West] = new Point(this.Rect.Center.X - adjustedSize, this.Rect.Center.Y);

            foreach (namDirections d in directionArray)
            {
                if (IsKnown)
                {
                    results[(byte)d] = Parent.GetLocation(coordinates[(int)d]);
                }
                else
                {
                    Point center = coordinates[(int)d];

                    results[(byte)d] = new Location(this,
                        new Rectangle(center.X, center.Y,
                            this.Rect.Width, this.Rect.Height));
                }
            }

            return results;
        }
Exemple #2
0
        public ILocation GetLocation(Point position)
        {
            if (this.Rect.Contains(position))
                return this;
            if (this.Children.Count(x => x.GetLocation(position).IsKnown) == 1)
                return this.Children.FirstOrDefault(x => x.GetLocation(position).IsKnown);

            Location[] mockLocations = new Location[8] ;

            return new Location(this,
                new Rectangle(position.X,
                    position.Y,
                    this.Rect.Width,
                    this.Rect.Height),
                new Location[8]);
        }