Implement a simplified Paint editor that supports drawing on a 2D canvas and reverting changes using undo and redo operations.
You are given a 2D grid representing a canvas. Each cell can store:
None
for an empty cell.
You will initialize the canvas with a given width and height.
Assume coordinates are zero-based and given as (x, y) where x is the column index and y is the row index.
Coordinates are guaranteed to be within bounds.
You must design and implement a Paint class with the following methods:
draw(x, y, color)
(x, y)
to the given
color
.
erase(x, y)
(x, y)
and set it back to empty (
None
).
fill(x, y, color)
(x, y)
:
orig
be the color currently at
(x, y)
.
(x, y)
with
color
.
orig
with
color
.
orig
is already equal to
color
, the operation may be a no-op.
undo()
draw
,
erase
, or
fill
).
redo()
draw
,
erase
,
fill
) should become an undoable action.
undo()
moves the current state into a redo history so that it can be restored with
redo()
.
redo()
re-applies that state and moves it back into the undo history.
draw
,
erase
,
fill
), the redo history must be cleared.
Paint
class and its methods.
Assume reasonable constraints, e.g., canvas up to a few thousand by a few thousand cells and up to tens of thousands of operations.