diff --git a/cpp/visualmesh/engine/cpu/pixel.hpp b/cpp/visualmesh/engine/cpu/pixel.hpp index 1f1a92d..b362207 100644 --- a/cpp/visualmesh/engine/cpu/pixel.hpp +++ b/cpp/visualmesh/engine/cpu/pixel.hpp @@ -130,8 +130,8 @@ namespace engine { const Scalar y = P[1]; const int x1 = std::max(int(std::floor(P[0])), 0); const int y1 = std::max(int(std::floor(P[1])), 0); - const int x2 = std::max(x1 + 1, dimensions[0]); - const int y2 = std::max(y1 + 1, dimensions[1]); + const int x2 = std::min(x1 + 1, dimensions[0] - 1); + const int y2 = std::min(y1 + 1, dimensions[1] - 1); const vec4 Q1 = get_pixel(vec2{x1, y1}, image, dimensions, format); const vec4 Q2 = get_pixel(vec2{x2, y1}, image, dimensions, format); const vec4 Q3 = get_pixel(vec2{x1, y2}, image, dimensions, format);