diff --git a/common/DetectorGeometryModular.cpp b/common/DetectorGeometryModular.cpp index e48e39ee..1e475afe 100644 --- a/common/DetectorGeometryModular.cpp +++ b/common/DetectorGeometryModular.cpp @@ -12,11 +12,24 @@ DetectorGeometryModular::DetectorGeometryModular(const std::vector(width, m.GetMaxX()+1); - height = std::max(height, m.GetMaxY()+1); + min_x = std::min(min_x, m.GetMinX()); + max_x = std::max(max_x, m.GetMaxX()); + min_y = std::min(min_y, m.GetMinY()); + max_y = std::max(max_y, m.GetMaxY()); } + width = max_x - min_x + 1; + height = max_y - min_y + 1; + + for (auto &m: modules) + m.Translate(-min_x, -min_y); + if (vertical_flip) VerticalFlip(); } diff --git a/tests/DetectorGeometryTest.cpp b/tests/DetectorGeometryTest.cpp index 593b1439..fb42b6f1 100644 --- a/tests/DetectorGeometryTest.cpp +++ b/tests/DetectorGeometryTest.cpp @@ -218,6 +218,22 @@ TEST_CASE("DetectorGeometryModular_Custom", "[DetectorGeometry]") { CHECK(geometry.GetSlowDirectionStep(2) == 1); } +TEST_CASE("DetectorGeometryModular_Limit", "[DetectorGeometry]") { + std::vector module_geom; + + REQUIRE_NOTHROW(module_geom.emplace_back(-100, 2999, DetectorModuleGeometry::Direction::Xneg, + DetectorModuleGeometry::Direction::Yneg)); + + REQUIRE_NOTHROW(module_geom.emplace_back(5000, 500, DetectorModuleGeometry::Direction::Ypos, + DetectorModuleGeometry::Direction::Xpos)); + + DetectorGeometryModular geometry(module_geom); + + REQUIRE(geometry.GetModulesNum() == 2); + CHECK(geometry.GetWidth(true) == 5000 + 513 - (-100 - 1029)); + CHECK(geometry.GetHeight(true) == 2999 + 513 - 500); +} + TEST_CASE("DetectorGeometryModular_Custom_Mirror", "[DetectorGeometry]") { std::vector module_geom;