From 8ad5f7c39db55cab3f78fdefab323435261941fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 16 Jun 2018 12:52:48 +0200 Subject: Add hovering to visualization. --- src/grid.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/grid.h b/src/grid.h index 6d3933b..85c7465 100644 --- a/src/grid.h +++ b/src/grid.h @@ -53,15 +53,18 @@ public: T operator()(Index x, Index y) const; T& operator()(Pos pos); T& operator()(Index x, Index y); + std::vector const& getAllEntries() const; void resize(Index width, Index height); void assign(Index width, Index height, T value); + void setDefaultValue(T value); private: Index _width; Index _height; std::vector _entries; + T default_value; }; template @@ -99,25 +102,31 @@ auto Grid::height() const -> Index template T Grid::operator()(Pos pos) const { - return _entries.at(pos.x + _width*pos.y); + return is_valid(pos) ? _entries[pos.x + _width*pos.y] : default_value; } template T Grid::operator()(Index x, Index y) const { - return _entries.at(x + _width*y); + return is_valid(x, y) ? _entries[x + _width*y] : default_value; } template T& Grid::operator()(Pos pos) { - return _entries.at(pos.x + _width*pos.y); + return is_valid(pos) ? _entries[pos.x + _width*pos.y] : default_value; } template T& Grid::operator()(Index x, Index y) { - return _entries.at(x + _width*y); + return is_valid(x, y) ? _entries[x + _width*y] : default_value; +} + +template +std::vector const& Grid::getAllEntries() const +{ + return _entries; } template @@ -135,3 +144,9 @@ void Grid::assign(Index width, Index height, T value) _height = height; _entries.assign(_width*_height, value); } + +template +void Grid::setDefaultValue(T value) +{ + default_value = value; +} -- cgit v1.2.3