/// <summary>Expand the specified region with an additional cordon. This may expand the region outside the map borders.</summary> public static CellRegion Expand(CellRegion region, int cordon) { var offset = new CVec(cordon, cordon); var tl = Map.MapToCell(region.shape, Map.CellToMap(region.shape, region.TopLeft) - offset); var br = Map.MapToCell(region.shape, Map.CellToMap(region.shape, region.BottomRight) + offset); return(new CellRegion(region.shape, tl, br)); }
public CellRegion(TileShape shape, CPos topLeft, CPos bottomRight) { this.shape = shape; TopLeft = topLeft; BottomRight = bottomRight; mapTopLeft = Map.CellToMap(shape, TopLeft); mapBottomRight = Map.CellToMap(shape, BottomRight); }
// Resolve an array index from cell coordinates int Index(CPos cell) { var uv = Map.CellToMap(Shape, cell); return(Index(uv.X, uv.Y)); }
public bool Contains(CPos cell) { var uv = Map.CellToMap(shape, cell); return(uv.X >= mapTopLeft.X && uv.X <= mapBottomRight.X && uv.Y >= mapTopLeft.Y && uv.Y <= mapBottomRight.Y); }
// Resolve an array index from cell coordinates int Index(CPos cell) { var uv = Map.CellToMap(Shape, cell); return(uv.Y * Size.Width + uv.X); }