|
1 |
| - |
2 | 1 | // STL includes
|
3 | 2 | #include <algorithm>
|
4 | 3 | #include <cmath>
|
@@ -33,17 +32,35 @@ ImageToLedsMap::ImageToLedsMap(
|
33 | 32 |
|
34 | 33 | for (const Led& led : leds)
|
35 | 34 | {
|
| 35 | + // skip leds without area |
| 36 | + if ((led.maxX_frac-led.minX_frac) < 1e-6 || (led.maxY_frac-led.minY_frac) < 1e-6) |
| 37 | + { |
| 38 | + continue; |
| 39 | + } |
| 40 | + |
36 | 41 | // Compute the index boundaries for this led
|
37 |
| - const unsigned minX_idx = xOffset + unsigned(std::round((actualWidth-1) * led.minX_frac)); |
38 |
| - const unsigned maxX_idx = xOffset + unsigned(std::round((actualWidth-1) * led.maxX_frac)); |
39 |
| - const unsigned minY_idx = yOffset + unsigned(std::round((actualHeight-1) * led.minY_frac)); |
40 |
| - const unsigned maxY_idx = yOffset + unsigned(std::round((actualHeight-1) * led.maxY_frac)); |
| 42 | + unsigned minX_idx = xOffset + unsigned(std::round(actualWidth * led.minX_frac)); |
| 43 | + unsigned maxX_idx = xOffset + unsigned(std::round(actualWidth * led.maxX_frac)); |
| 44 | + unsigned minY_idx = yOffset + unsigned(std::round(actualHeight * led.minY_frac)); |
| 45 | + unsigned maxY_idx = yOffset + unsigned(std::round(actualHeight * led.maxY_frac)); |
| 46 | + |
| 47 | + // make sure that the area is at least a single led large |
| 48 | + minX_idx = std::min(minX_idx, xOffset + actualWidth - 1); |
| 49 | + if (minX_idx == maxX_idx) |
| 50 | + { |
| 51 | + maxX_idx = minX_idx + 1; |
| 52 | + } |
| 53 | + minY_idx = std::min(minY_idx, yOffset + actualHeight - 1); |
| 54 | + if (minY_idx == maxY_idx) |
| 55 | + { |
| 56 | + maxY_idx = minY_idx + 1; |
| 57 | + } |
41 | 58 |
|
42 | 59 | // Add all the indices in the above defined rectangle to the indices for this led
|
43 | 60 | std::vector<unsigned> ledColors;
|
44 |
| - for (unsigned y = minY_idx; y<=maxY_idx && y<height; ++y) |
| 61 | + for (unsigned y = minY_idx; y<maxY_idx && y<(yOffset+actualHeight); ++y) |
45 | 62 | {
|
46 |
| - for (unsigned x = minX_idx; x<=maxX_idx && x<width; ++x) |
| 63 | + for (unsigned x = minX_idx; x<maxX_idx && x<(xOffset+actualWidth); ++x) |
47 | 64 | {
|
48 | 65 | ledColors.push_back(y*width + x);
|
49 | 66 | }
|
|
0 commit comments