Created
June 30, 2013 08:04
-
-
Save wduminy/5894305 to your computer and use it in GitHub Desktop.
abstract heightmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <typename elemT, size_t m_columns, size_t n_rows > | |
class Heightmap { | |
public: | |
typedef std::array<elemT, n_rows * m_columns> container_t; | |
const container_t& elems() const {return _elems;} | |
container_t& elems() {return _elems;} | |
const elemT& operator() (size_t c, size_t r) const { | |
check_range(c,r); return _elems.at(r * n_rows + c);} | |
elemT& operator() (size_t c, size_t r) { | |
check_range(c,r);return _elems.at(r * n_rows + c);} | |
virtual ~Heightmap() {}; | |
private: | |
container_t _elems; | |
void check_range(size_t c, size_t r) const { | |
if (c < 0 || c >= m_columns) throw std::out_of_range("c is invalid"); | |
if (r < 0 || r >= n_rows) throw std::out_of_range("r is invalid"); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment