예제 #1
0
 public override IEnumerator <Point> GetEnumerator()
 {
     for (var gridIndex = MinIndex; gridIndex <= MaxIndex; gridIndex++)
     {
         yield return(TileMap1D.GetTile(gridIndex, GridWidth));
     }
 }
예제 #2
0
        public override Point this[int index]
        {
            get
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException(nameof(index));
                }

                return(TileMap1D.GetTile(index, GridWidth));
            }
        }
예제 #3
0
        public override Point this[int index]
        {
            get
            {
                if (index < 0 || index >= Count)
                {
                    throw new ArgumentOutOfRangeException(nameof(index));
                }

                var point = TileMap1D.GetTile(index, Size.Width);
                return(Point.Add(Origin, (Size)point));
            }
        }
예제 #4
0
        public BoxTileMapSelection(Point origin, Size size, int gridWidth)
            : base(origin, gridWidth)
        {
            if (size.Width < 0 || size.Height < 0)
            {
                throw new ArgumentException();
            }

            Size     = size;
            Count    = Size.Width * Size.Height;
            MaxIndex = TileMap1D.GetTileIndex(
                Point.Add(origin, size),
                GridWidth);
        }
예제 #5
0
        protected TileMapSelection(Point origin, int gridWidth)
        {
            if (origin.X < 0 || origin.Y < 0)
            {
                throw new ArgumentException();
            }

            if (gridWidth <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(gridWidth));
            }

            Origin    = origin;
            GridWidth = gridWidth;
            MinIndex  = TileMap1D.GetTileIndex(Origin, GridWidth);
        }
예제 #6
0
        public EnumerableTileMapSelection(
            IEnumerable <Point> collection,
            int gridWidth)
            : base(GetFirst(collection), gridWidth)
        {
            List    = new List <Point>(collection);
            HashSet = new HashSet <Point>(List);
            List.Sort(Compare);

            MaxIndex = TileMap1D.GetTileIndex(
                List.LastOrDefault(),
                GridWidth);

            int Compare(Point left, Point right)
            {
                return(left.X != right.X ? left.X - right.X : left.Y - right.Y);
            }
        }
예제 #7
0
        public IEnumerable <T> EnumerateValues <T>(
            IReadOnlyList <T> list)
        {
            if (list is null)
            {
                throw new ArgumentNullException(nameof(list));
            }

            if (MinIndex < 0 || MaxIndex >= Count)
            {
                throw new InvalidOperationException();
            }

            foreach (var gridTile in this)
            {
                var index = TileMap1D.GetTileIndex(gridTile, GridWidth);
                yield return(list[index]);
            }
        }
예제 #8
0
        public override bool Contains(Point gridTile)
        {
            var index = TileMap1D.GetTileIndex(gridTile, GridWidth);

            return(index >= MinIndex && index <= MaxIndex);
        }