EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CuboidVolumeBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file CuboidVolumeBoundsTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
17 
18 namespace Acts {
19 namespace Test {
20 
22 
23 double hx{10.}, hy{20.}, hz{30.};
24 
25 BOOST_AUTO_TEST_SUITE(Geometry)
26 
27 BOOST_AUTO_TEST_CASE(CuboidVolumeConstruction) {
28  // Test Construction
30 
31  // Test copy construction
32  CuboidVolumeBounds copied(box);
33  BOOST_CHECK_EQUAL(box, copied);
34 
35  // Test assigned
36  CuboidVolumeBounds assigned = box;
37  BOOST_CHECK_EQUAL(box, assigned);
38 }
39 
40 BOOST_AUTO_TEST_CASE(CuboidVolumeRecreation) {
41  CuboidVolumeBounds original(hx, hy, hz);
42  auto valvector = original.values();
43  std::array<double, CuboidVolumeBounds::eSize> values;
44  std::copy_n(valvector.begin(), CuboidVolumeBounds::eSize, values.begin());
45  CuboidVolumeBounds recreated(values);
46  BOOST_CHECK_EQUAL(original, recreated);
47 }
48 
49 BOOST_AUTO_TEST_CASE(CuboidVolumeException) {
50  // Test exception negative x
51  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, hy, hz), std::logic_error);
52  // Test exception negative y
53  BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, hz), std::logic_error);
54  // Test exception negative z
55  BOOST_CHECK_THROW(CuboidVolumeBounds(hx, hy, -hz), std::logic_error);
56  // Other iterations 0
57  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, hy, -hz), std::logic_error);
58  // Other iterations 1
59  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, hz), std::logic_error);
60  // Other iterations 2
61  BOOST_CHECK_THROW(CuboidVolumeBounds(hx, -hy, -hz), std::logic_error);
62  // Other iterations : all
63  BOOST_CHECK_THROW(CuboidVolumeBounds(-hx, -hy, -hz), std::logic_error);
64 }
65 
66 BOOST_AUTO_TEST_CASE(CuboidVolumeProperties) {
68  // Test the type
69  BOOST_CHECK_EQUAL(box.type(), VolumeBounds::eCuboid);
70  // Test the halflength x
72  // Test the halflength y
74  // Test the halflength z
76  // Test the streaming
77  std::vector<double> actvalues = box.values();
78  std::vector<double> refvalues = {hx, hy, hz};
79  BOOST_CHECK_EQUAL_COLLECTIONS(actvalues.begin(), actvalues.end(),
80  refvalues.begin(), refvalues.end());
81 
82  // Inside position
83  Vector3D inside({5., 10., 8.});
84  // Outside positions in x, y, z
85  std::vector<Vector3D> outsides = {
86  {20., 1., -2.}, {1., -30., 2.}, {-1., 2., 100.}};
87 
88  // Inside position
89  BOOST_CHECK(box.inside(inside, s_onSurfaceTolerance));
90 
91  // Outside position
92  for (const auto& outside : outsides) {
93  BOOST_CHECK(!box.inside(outside, s_onSurfaceTolerance));
94  }
95 }
96 
97 BOOST_AUTO_TEST_CASE(CuboidVolumeBoundarySurfaces) {
98  CuboidVolumeBounds box(5, 8, 7);
99  auto cvbOrientedSurfaces = box.orientedSurfaces(Transform3D::Identity());
100 
101  BOOST_CHECK_EQUAL(cvbOrientedSurfaces.size(), 6);
102 
103  auto geoCtx = GeometryContext();
104 
105  for (auto& os : cvbOrientedSurfaces) {
106  auto osCenter = os.first->center(geoCtx);
107  auto osNormal = os.first->normal(geoCtx);
108  double nDir = (double)os.second;
109  // Check if you step inside the volume with the oriented normal
110  auto insideBox = osCenter + nDir * osNormal;
111  auto outsideBox = osCenter - nDir * osNormal;
112  BOOST_CHECK(box.inside(insideBox));
113  BOOST_CHECK(!box.inside(outsideBox));
114  }
115 
116  Vector3D xaxis(1., 0., 0.);
117  Vector3D yaxis(0., 1., 0.);
118  Vector3D zaxis(0., 0., 1.);
119 
120  // Test the orientation of the boundary surfaces
121  auto nFaceXY =
122  cvbOrientedSurfaces[negativeFaceXY].first->transform(geoCtx).rotation();
123  BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
124  BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
125  BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
126 
127  auto pFaceXY =
128  cvbOrientedSurfaces[positiveFaceXY].first->transform(geoCtx).rotation();
129  BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
130  BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
131  BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
132 
133  auto nFaceYZ =
134  cvbOrientedSurfaces[negativeFaceYZ].first->transform(geoCtx).rotation();
135  BOOST_CHECK(nFaceYZ.col(0).isApprox(yaxis));
136  BOOST_CHECK(nFaceYZ.col(1).isApprox(zaxis));
137  BOOST_CHECK(nFaceYZ.col(2).isApprox(xaxis));
138 
139  auto pFaceYZ =
140  cvbOrientedSurfaces[positiveFaceYZ].first->transform(geoCtx).rotation();
141  BOOST_CHECK(pFaceYZ.col(0).isApprox(yaxis));
142  BOOST_CHECK(pFaceYZ.col(1).isApprox(zaxis));
143  BOOST_CHECK(pFaceYZ.col(2).isApprox(xaxis));
144 
145  auto nFaceZX =
146  cvbOrientedSurfaces[negativeFaceZX].first->transform(geoCtx).rotation();
147  BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
148  BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
149  BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
150 
151  auto pFaceZX =
152  cvbOrientedSurfaces[positiveFaceZX].first->transform(geoCtx).rotation();
153  BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
154  BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
155  BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
156 }
157 
158 BOOST_AUTO_TEST_SUITE_END()
159 
160 } // namespace Test
161 } // namespace Acts