diff options
Diffstat (limited to 'src/containers.hh')
| -rw-r--r-- | src/containers.hh | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/containers.hh b/src/containers.hh index fafe5b7..ba7e3cd 100644 --- a/src/containers.hh +++ b/src/containers.hh @@ -239,6 +239,17 @@ struct matrix{ delete[] this->entry; } + // NOTE(fusion): Same as `at` but returns NULL on out of bounds coordinates. + T *boundedAt(int x, int y){ + int xoffset = x - this->xmin; + int yoffset = y - this->ymin; + if(xoffset < 0 || xoffset >= this->dx || yoffset < 0 || yoffset >= this->dy){ + return NULL; + }else{ + return &this->entry[yoffset * this->dx + xoffset]; + } + } + T *at(int x, int y){ int xoffset = x - this->xmin; int yoffset = y - this->ymin; |
