floodFill

Implements a flood fill algorithm, like the bucket tool in MS Paint.

Note it assumes what.length == width*height.

@safe
void
floodFill
(
T
)
(
T[] what
,
int width
,
int height
,,,
int x
,
int y
,
bool delegate
(
int x
,
int y
)
@safe
additionalCheck
)

Parameters

what T[]

the canvas to work with, arranged as top to bottom, left to right elements

width int

the width of the canvas

height int

the height of the canvas

target T

the type to replace. You may pass the existing value if you want to do what Paint does

replacement T

the replacement value

x int

the x-coordinate to start the fill (think of where the user clicked in Paint)

y int

the y-coordinate to start the fill

additionalCheck bool delegate
(
int x
,
int y
)
@safe

A custom additional check to perform on each square before continuing. Returning true means keep flooding, returning false means stop. If null, it is not used.

Suggestion Box / Bug Report