Make SetPixel safe, remove incomplete safety elsewhere

This commit is contained in:
Ian Gulliver
2017-08-12 16:05:41 -07:00
parent 30fba94b1b
commit 0ccae577eb
2 changed files with 11 additions and 10 deletions

11
image.h
View File

@@ -30,21 +30,22 @@ constexpr const Color<C>& Image<X, Y, C>::GetPixel(const Coord<2>& coord) const
template <int32_t X, int32_t Y, int32_t C>
void Image<X, Y, C>::SetPixel(const Coord<2>& coord, const Color<C>& color) {
if (coord.at(0) >= X || coord.at(1) >= Y) {
return;
}
this->at(coord.at(1)).at(coord.at(0)) = color;
}
template <int32_t X, int32_t Y, int32_t C>
void Image<X, Y, C>::DrawXLine(const Coord<2>& coord, const Color<C>& color, int32_t length) {
auto& row = this->at(coord.at(1));
for (int32_t x = coord.at(0); x < std::min(X - 1, coord.at(0) + length); ++x) {
row.at(x) = color;
for (int32_t x = coord.at(0); x <= coord.at(0) + length; ++x) {
SetPixel({{{{x, coord.at(1)}}}}, color);
}
}
template <int32_t X, int32_t Y, int32_t C>
void Image<X, Y, C>::DrawYLine(const Coord<2>& coord, const Color<C>& color, int32_t length) {
for (int32_t y = coord.at(1); y <= std::min(Y - 1, coord.at(1) + length); ++y) {
for (int32_t y = coord.at(1); y <= coord.at(1) + length; ++y) {
SetPixel({{{{coord.at(0), y}}}}, color);
}
}