/// <summary> /// Tiles the on area. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <returns>An ITileCollection.</returns> public ITileCollection TilesOnArea(int x, int y, int width, int height) { uint px = (uint)(x / CellSize); uint py = (uint)(y / CellSize); int w = width / CellSize; int h = height / CellSize; if (width < 2 && height < 2) { PositionKey pk = new PositionKey(px, py); if (tiles.ContainsKey(pk)) { TileMaskCollection ret = new TileMaskCollection(BytesPerColor); foreach (TileMask selT in tiles[pk]) { ret.Add(selT); } return(ret); } else { return(null); } } IEnumerable filtered = tiles.Where(kvp => { if (kvp.Key.X < px) { return(false); } if (kvp.Key.Y < py) { return(false); } if (kvp.Key.X >= w + px) { return(false); } if (kvp.Key.Y >= h + py) { return(false); } return(true); }); TileMaskCollection t = new TileMaskCollection(BytesPerColor); foreach (KeyValuePair <PositionKey, List <TileMask> > kvp in filtered) { foreach (TileMask selT in kvp.Value) { t.Add(selT); } } return(t); }
/// <summary> /// Clones the. /// </summary> /// <returns>A SpriteTileMaskCollection.</returns> public TileMaskCollection Clone() { TileMaskCollection col = new TileMaskCollection(BytesPerColor); foreach (TileMask t in tiles) { col.Add(t.Clone()); } return(col); }
/// <summary> /// Finds the by position. /// </summary> /// <param name="x">The x.</param> /// <param name="y">The y.</param> public TileMaskCollection FindByPosition(int x, int y) { ClearSelection(); TileMask tm = tiles.FirstOrDefault((t) => { if (t.X <= x && t.X + t.Width >= x && t.Y <= y && t.Y + t.Height >= y) { return(true); } return(false); }); if (tm == default) { return(selection); } selection.Add(tm); OnSelectionChanged?.Invoke(this, selection); return(selection); }