|
@ -44,14 +44,18 @@ public: |
|
|
const size_t width = size<0>(); |
|
|
const size_t width = size<0>(); |
|
|
const size_t height = size<1>(); |
|
|
const size_t height = size<1>(); |
|
|
|
|
|
|
|
|
const size_t x = 0.5*position[0]*width + width*.5; |
|
|
const size_t c = 0.5*position[0]*width + width*.5; |
|
|
const size_t y = 0.5*position[1]*width + height*.5; |
|
|
const size_t r = 0.5*position[1]*width + height*.5; |
|
|
|
|
|
|
|
|
if(x < width && y < height) { |
|
|
if(c < width && r < height) { |
|
|
storage[x][y]++; |
|
|
storage[r][c]++; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
size_t size() const { |
|
|
|
|
|
return size<0>() * size<1>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
template <size_t N> |
|
|
template <size_t N> |
|
|
size_t size() const { |
|
|
size_t size() const { |
|
|
if ( N == 0 ) return storage.size(); |
|
|
if ( N == 0 ) return storage.size(); |
|
@ -87,15 +91,15 @@ public: |
|
|
struct iterator : public std::iterator<std::forward_iterator_tag, value_type> { |
|
|
struct iterator : public std::iterator<std::forward_iterator_tag, value_type> { |
|
|
iterator(iterator const & rh) |
|
|
iterator(iterator const & rh) |
|
|
: canvas(rh.canvas) |
|
|
: canvas(rh.canvas) |
|
|
, x(rh.x) |
|
|
, c(rh.c) |
|
|
, y(rh.y) |
|
|
, r(rh.r) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
|
iterator & operator++(){ |
|
|
iterator & operator++(){ |
|
|
++x; |
|
|
++c; |
|
|
if (x >= canvas->size<0>()) { |
|
|
if (c >= canvas->size<0>()) { |
|
|
x = 0; |
|
|
c = 0; |
|
|
++y; |
|
|
++r; |
|
|
} |
|
|
} |
|
|
return *this; |
|
|
return *this; |
|
|
} |
|
|
} |
|
@ -107,48 +111,48 @@ public: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool operator==(iterator const & rh) const { |
|
|
bool operator==(iterator const & rh) const { |
|
|
return canvas == rh.canvas && x == rh.x && y == rh.y; |
|
|
return canvas == rh.canvas && c == rh.c && r == rh.r; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool operator!=(iterator const & rh) const { |
|
|
bool operator!=(iterator const & rh) const { |
|
|
return canvas != rh.canvas || x != rh.x || y != rh.y; |
|
|
return canvas != rh.canvas || c != rh.c || r != rh.r; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
value_type & operator*(){ |
|
|
value_type & operator*(){ |
|
|
return (*canvas)[x][y]; |
|
|
return (*canvas)[r][c]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
value_type & operator->(){ |
|
|
value_type & operator->(){ |
|
|
return (*canvas)[x][y]; |
|
|
return (*canvas)[r][c]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
friend class Canvas2D; |
|
|
friend class Canvas2D; |
|
|
iterator(Canvas2D * canvas, size_t x = 0, size_t y = 0) |
|
|
iterator(Canvas2D * canvas, size_t c = 0, size_t r = 0) |
|
|
: canvas(canvas) |
|
|
: canvas(canvas) |
|
|
, x(x) |
|
|
, c(c) |
|
|
, y(y) |
|
|
, r(r) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
|
iterator(); |
|
|
iterator(); |
|
|
|
|
|
|
|
|
Canvas2D * canvas; |
|
|
Canvas2D * canvas; |
|
|
size_t x; |
|
|
size_t c; |
|
|
size_t y; |
|
|
size_t r; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
struct const_iterator : public std::iterator<std::forward_iterator_tag, value_type const> { |
|
|
struct const_iterator : public std::iterator<std::forward_iterator_tag, value_type const> { |
|
|
const_iterator(const_iterator const & rh) |
|
|
const_iterator(const_iterator const & rh) |
|
|
: canvas(rh.canvas) |
|
|
: canvas(rh.canvas) |
|
|
, x(rh.x) |
|
|
, c(rh.c) |
|
|
, y(rh.y) |
|
|
, r(rh.r) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
|
const_iterator & operator++(){ |
|
|
const_iterator & operator++(){ |
|
|
++x; |
|
|
++c; |
|
|
if (x >= canvas->size<0>()) { |
|
|
if (c >= canvas->size<0>()) { |
|
|
x = 0; |
|
|
c = 0; |
|
|
++y; |
|
|
++r; |
|
|
} |
|
|
} |
|
|
return *this; |
|
|
return *this; |
|
|
} |
|
|
} |
|
@ -160,34 +164,34 @@ public: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool operator==(const_iterator const & rh) const { |
|
|
bool operator==(const_iterator const & rh) const { |
|
|
return canvas == rh.canvas && x == rh.x && y == rh.y; |
|
|
return canvas == rh.canvas && c == rh.c && r == rh.r; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool operator!=(const_iterator const & rh) const { |
|
|
bool operator!=(const_iterator const & rh) const { |
|
|
return canvas != rh.canvas || x != rh.x || y != rh.y; |
|
|
return canvas != rh.canvas || c != rh.c || r != rh.r; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
value_type const & operator*() const { |
|
|
value_type const & operator*() const { |
|
|
return (*canvas)[x][y]; |
|
|
return (*canvas)[r][c]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
value_type const & operator->() const { |
|
|
value_type const & operator->() const { |
|
|
return (*canvas)[x][y]; |
|
|
return (*canvas)[r][c]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
friend class Canvas2D; |
|
|
friend class Canvas2D; |
|
|
const_iterator(Canvas2D const * canvas, size_t x = 0, size_t y = 0) |
|
|
const_iterator(Canvas2D const * canvas, size_t c = 0, size_t r = 0) |
|
|
: canvas(canvas) |
|
|
: canvas(canvas) |
|
|
, x(x) |
|
|
, c(c) |
|
|
, y(y) |
|
|
, r(r) |
|
|
{} |
|
|
{} |
|
|
|
|
|
|
|
|
const_iterator(); |
|
|
const_iterator(); |
|
|
|
|
|
|
|
|
Canvas2D const * canvas; |
|
|
Canvas2D const * canvas; |
|
|
size_t x; |
|
|
size_t c; |
|
|
size_t y; |
|
|
size_t r; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|