Skip to content

Filter Cells - Keep Largest Regions

Keep only the N largest connected regions from an input set of grid cells. Useful after generators that produce scattered pockets (Cellular Automata, Drunkard’s Walk, etc.).

What it does

Finds connected components (4-way or 8-way) in the input cell set, optionally discards tiny regions, then keeps the largest N and drops the rest.

Inputs

Field Description
Cells Input open cells as Vector2Int positions.
Keep Count Number of largest regions to keep (e.g., 1 for a single main area).
Use 8 Neighbors If enabled, diagonal cells are considered connected (8-way). If disabled, uses 4-way.
Min Region Size Discard regions smaller than this size before ranking (0 = no minimum).

Outputs

Field Description
Filtered Cells Cells from the kept region(s). Supports input == output safely.

How it works

Performs flood-fill to identify components, applies Min Region Size, sorts by size, then concatenates the top Keep Count regions.

Tips

  • Use 8-way for organic caves; 4-way to enforce Manhattan connectivity.
  • To guarantee a single playable area, set Keep Count = 1.
  • Pair with Remove Small Regions first if you want to strip specks before ranking.