Make SetPixel safe, remove incomplete safety elsewhere
This commit is contained in:
@@ -103,11 +103,11 @@ std::unique_ptr<Image<X, Y, C>> HighlightClosest(const Image<X, Y, C>& image) {
|
||||
for (int32_t cc = 0; cc < kColorCheckerSrgb.ssize(); ++cc) {
|
||||
const auto& coord = closest.at(cc);
|
||||
const auto& color = kColorCheckerSrgb.at(cc);
|
||||
out->DrawSquare({{{{std::max(5, coord.at(0)) - 5, std::max(5, coord.at(1)) - 5}}}}, kBlack, 10);
|
||||
out->DrawSquare({{{{std::max(6, coord.at(0)) - 6, std::max(6, coord.at(1)) - 6}}}}, color, 12);
|
||||
out->DrawSquare({{{{std::max(7, coord.at(0)) - 7, std::max(7, coord.at(1)) - 7}}}}, color, 14);
|
||||
out->DrawSquare({{{{std::max(8, coord.at(0)) - 8, std::max(8, coord.at(1)) - 8}}}}, color, 16);
|
||||
out->DrawSquare({{{{std::max(9, coord.at(0)) - 9, std::max(9, coord.at(1)) - 9}}}}, kWhite, 18);
|
||||
out->DrawSquare({{{{coord.at(0) - 5, coord.at(1) - 5}}}}, kBlack, 10);
|
||||
out->DrawSquare({{{{coord.at(0) - 6, coord.at(1) - 6}}}}, color, 12);
|
||||
out->DrawSquare({{{{coord.at(0) - 7, coord.at(1) - 7}}}}, color, 14);
|
||||
out->DrawSquare({{{{coord.at(0) - 8, coord.at(1) - 8}}}}, color, 16);
|
||||
out->DrawSquare({{{{coord.at(0) - 9, coord.at(1) - 9}}}}, kWhite, 18);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
11
image.h
11
image.h
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user