From 8eb43f0c90e4bb3f0c50df13cc9bedf0d26d0f61 Mon Sep 17 00:00:00 2001 From: poljvd Date: Wed, 26 Mar 2014 16:26:11 +0100 Subject: [PATCH] Fix led mapping boundaries Former-commit-id: 3f41d6b41ceff5c0b81c0041ea185233e37d363c --- libsrc/hyperion/ImageToLedsMap.cpp | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/libsrc/hyperion/ImageToLedsMap.cpp b/libsrc/hyperion/ImageToLedsMap.cpp index 3e9a7fd3..202f22ff 100644 --- a/libsrc/hyperion/ImageToLedsMap.cpp +++ b/libsrc/hyperion/ImageToLedsMap.cpp @@ -1,4 +1,3 @@ - // STL includes #include #include @@ -33,17 +32,35 @@ ImageToLedsMap::ImageToLedsMap( for (const Led& led : leds) { + // skip leds without area + if ((led.maxX_frac-led.minX_frac) < 1e-6 || (led.maxY_frac-led.minY_frac) < 1e-6) + { + continue; + } + // Compute the index boundaries for this led - const unsigned minX_idx = xOffset + unsigned(std::round((actualWidth-1) * led.minX_frac)); - const unsigned maxX_idx = xOffset + unsigned(std::round((actualWidth-1) * led.maxX_frac)); - const unsigned minY_idx = yOffset + unsigned(std::round((actualHeight-1) * led.minY_frac)); - const unsigned maxY_idx = yOffset + unsigned(std::round((actualHeight-1) * led.maxY_frac)); + unsigned minX_idx = xOffset + unsigned(std::round(actualWidth * led.minX_frac)); + unsigned maxX_idx = xOffset + unsigned(std::round(actualWidth * led.maxX_frac)); + unsigned minY_idx = yOffset + unsigned(std::round(actualHeight * led.minY_frac)); + unsigned maxY_idx = yOffset + unsigned(std::round(actualHeight * led.maxY_frac)); + + // make sure that the area is at least a single led large + minX_idx = std::min(minX_idx, xOffset + actualWidth - 1); + if (minX_idx == maxX_idx) + { + maxX_idx = minX_idx + 1; + } + minY_idx = std::min(minY_idx, yOffset + actualHeight - 1); + if (minY_idx == maxY_idx) + { + maxY_idx = minY_idx + 1; + } // Add all the indices in the above defined rectangle to the indices for this led std::vector ledColors; - for (unsigned y = minY_idx; y<=maxY_idx && y