diff --git a/common/DetectorGeometry.cpp b/common/DetectorGeometry.cpp index 05243ab1..14f0dfae 100644 --- a/common/DetectorGeometry.cpp +++ b/common/DetectorGeometry.cpp @@ -29,6 +29,8 @@ DetectorGeometry::DetectorGeometry(int32_t nmodules, int32_t horizontal_stacking throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap x has to be non-negative"); if (gap_y < 0) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, "Gap y has to be non-negative"); + if (nmodules < horizontal_stacking) + horizontal_stacking = nmodules; width = horizontal_stacking * CONVERTED_MODULE_COLS + (horizontal_stacking - 1) * gap_x; int64_t conv_lines = nmodules / horizontal_stacking + (nmodules % horizontal_stacking > 0 ? 1 : 0); diff --git a/tests/DetectorGeometryTest.cpp b/tests/DetectorGeometryTest.cpp index d3ff8981..0b70958c 100644 --- a/tests/DetectorGeometryTest.cpp +++ b/tests/DetectorGeometryTest.cpp @@ -20,6 +20,20 @@ TEST_CASE("DetectorGeometry_Regular", "[DetectorGeometry]") { REQUIRE(pbuf.module_geometry(15).slow_direction_step() == pbuf.width_pxl()); } +TEST_CASE("DetectorGeometry_Regular_1Module", "[DetectorGeometry]") { + DetectorGeometry geometry(1, 3, 8, 36, false); + + const JFJochProtoBuf::DetectorGeometry pbuf = geometry; + REQUIRE(pbuf.module_geometry_size() == 1); + + REQUIRE(pbuf.width_pxl() == CONVERTED_MODULE_COLS); + REQUIRE(pbuf.height_pxl() == CONVERTED_MODULE_LINES); + REQUIRE(pbuf.module_geometry(0).pixel0() == 0); + + REQUIRE(pbuf.module_geometry(0).fast_direction_step() == 1); + REQUIRE(pbuf.module_geometry(0).slow_direction_step() == CONVERTED_MODULE_COLS); +} + TEST_CASE("DetectorGeometry_RegularMirror", "[DetectorGeometry]") { DetectorGeometry geometry(18, 3, 8, 36, true);