Example #1
0
        public static void Merge <T>(ISparseGrid <T> src, ISparseGrid <T> dest, int sourceX, int sourceY, int destX, int destY, int width, int height)
        {
            if (width < 0 || height < 0)
            {
                throw new ArgumentException("copy area has negative dimensions");
            }

            if (sourceX < 0 || sourceY < 0 || sourceX + width > src.Width || sourceY + height > src.Height)
            {
                throw new ArgumentException("source area overlaps source bounds");
            }

            if (destX < 0 || destY < 0 || destX + width > dest.Width || destY + height > dest.Height)
            {
                throw new ArgumentException("destination area overlaps destination bounds");
            }

            foreach (var e in src.CoordinateEntries)
            {
                var sourceCoords = e.Key;
                var value        = e.Value;

                if (sourceCoords.X < sourceX ||
                    sourceCoords.Y < sourceY ||
                    sourceCoords.X >= sourceX + width ||
                    sourceCoords.Y >= sourceY + height)
                {
                    continue;
                }

                dest.Set(destX + (sourceCoords.X - sourceX), destY + (sourceCoords.Y - sourceY), value);
            }
        }
Example #2
0
        public static void Merge <T>(ISparseGrid <T> src, ISparseGrid <T> dest, int x, int y)
        {
            if (x < 0 || y < 0 || x + src.Width > dest.Width || y + src.Height > dest.Height)
            {
                throw new ArgumentException("part of the other grid falls outside boundaries");
            }

            foreach (var e in src.CoordinateEntries)
            {
                dest.Set(e.Key.X + x, e.Key.Y + y, e.Value);
            }
        }
Example #3
0
 public BindingSparseGrid(ISparseGrid <T> grid)
 {
     this.grid = grid;
 }
Example #4
0
 public static T GetOrDefault <T>(this ISparseGrid <T> grid, GridPoint point, T defaultValue)
 {
     return(grid.ContainsPoint(point) ? grid.Get(point) : defaultValue);
 }