Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-26 08:04:40

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Geometry/ConeVolumeBounds.hpp"
0013 #include "Acts/Geometry/CuboidVolumeBounds.hpp"
0014 #include "Acts/Geometry/CylinderVolumeBounds.hpp"
0015 #include "Acts/Geometry/DiamondVolumeBounds.hpp"
0016 #include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
0017 #include "Acts/Geometry/VolumeBounds.hpp"
0018 
0019 #include <iomanip>
0020 #include <memory>
0021 #include <numbers>
0022 #include <sstream>
0023 #include <vector>
0024 
0025 using namespace Acts;
0026 
0027 namespace ActsTests {
0028 
0029 namespace {
0030 
0031 struct StreamState {
0032   std::ios_base::fmtflags flags;
0033   std::streamsize precision;
0034   std::streamsize width;
0035   char fill;
0036 };
0037 
0038 StreamState setNonDefaultStreamState(std::ostringstream& stream) {
0039   stream << std::scientific << std::showpos << std::setfill('#')
0040          << std::setprecision(3);
0041   stream.width(17);
0042   return {stream.flags(), stream.precision(), stream.width(), stream.fill()};
0043 }
0044 
0045 void checkStreamStatePreserved(const VolumeBounds& bounds) {
0046   std::ostringstream stream;
0047   const auto state = setNonDefaultStreamState(stream);
0048 
0049   bounds.toStream(stream);
0050 
0051   BOOST_CHECK(stream.flags() == state.flags);
0052   BOOST_CHECK_EQUAL(stream.precision(), state.precision);
0053   BOOST_CHECK_EQUAL(stream.width(), state.width);
0054   BOOST_CHECK_EQUAL(stream.fill(), state.fill);
0055 }
0056 
0057 }  // namespace
0058 
0059 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0060 
0061 BOOST_AUTO_TEST_CASE(VolumeBoundsTest) {
0062   // Tests if the planes are correctly oriented
0063   // s_planeXY
0064   // s_planeYZ
0065   // s_planeZX
0066 
0067   Vector3 xaxis(1., 0., 0.);
0068   Vector3 yaxis(0., 1., 0.);
0069   Vector3 zaxis(0., 0., 1.);
0070 
0071   auto rotXY = s_planeXY.rotation();
0072   BOOST_CHECK(rotXY.col(0).isApprox(xaxis));
0073   BOOST_CHECK(rotXY.col(1).isApprox(yaxis));
0074   BOOST_CHECK(rotXY.col(2).isApprox(zaxis));
0075 
0076   auto rotYZ = s_planeYZ.rotation();
0077   BOOST_CHECK(rotYZ.col(0).isApprox(yaxis));
0078   BOOST_CHECK(rotYZ.col(1).isApprox(zaxis));
0079   BOOST_CHECK(rotYZ.col(2).isApprox(xaxis));
0080 
0081   auto rotZX = s_planeZX.rotation();
0082   BOOST_CHECK(rotZX.col(0).isApprox(zaxis));
0083   BOOST_CHECK(rotZX.col(1).isApprox(xaxis));
0084   BOOST_CHECK(rotZX.col(2).isApprox(yaxis));
0085 }
0086 
0087 BOOST_AUTO_TEST_CASE(VolumeBoundsToStreamPreservesStreamState) {
0088   std::vector<std::unique_ptr<VolumeBounds>> bounds;
0089   bounds.push_back(std::make_unique<ConeVolumeBounds>(0., 0., 0.45, 50., 50.,
0090                                                       0., std::numbers::pi));
0091   bounds.push_back(std::make_unique<CuboidVolumeBounds>(10., 20., 30.));
0092   bounds.push_back(std::make_unique<CylinderVolumeBounds>(10., 20., 30.));
0093   bounds.push_back(
0094       std::make_unique<DiamondVolumeBounds>(10., 12., 8., 5., 10., 2.));
0095   bounds.push_back(std::make_unique<TrapezoidVolumeBounds>(5., 10., 8., 4.));
0096 
0097   for (const auto& bound : bounds) {
0098     checkStreamStatePreserved(*bound);
0099   }
0100 }
0101 
0102 BOOST_AUTO_TEST_SUITE_END()
0103 
0104 }  // namespace ActsTests