forked from sPHENIX-Collaboration/acts
/
TrapezoidVolumeBoundsTests.cpp
104 lines (79 loc) · 3.31 KB
/
TrapezoidVolumeBoundsTests.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// This file is part of the Acts project.
//
// Copyright (C) 2019-2020 CERN for the benefit of the Acts project
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <boost/test/unit_test.hpp>
#include "Acts/Geometry/BoundarySurfaceFace.hpp"
#include "Acts/Geometry/TrapezoidVolumeBounds.hpp"
#include "Acts/Surfaces/PlanarBounds.hpp"
#include "Acts/Surfaces/PlaneSurface.hpp"
#include "Acts/Surfaces/Surface.hpp"
#include "Acts/Tests/CommonHelpers/FloatComparisons.hpp"
#include "Acts/Utilities/BoundingBox.hpp"
#include "Acts/Utilities/Definitions.hpp"
namespace tt = boost::test_tools;
namespace Acts {
namespace Test {
BOOST_AUTO_TEST_SUITE(Volumes)
BOOST_AUTO_TEST_CASE(bounding_box_creation) {
float tol = 1e-4;
TrapezoidVolumeBounds tvb(5, 10, 8, 4);
auto bb = tvb.boundingBox();
CHECK_CLOSE_ABS(bb.max(), Vector3D(10, 8, 4), tol);
CHECK_CLOSE_ABS(bb.min(), Vector3D(-10, -8, -4), tol);
Transform3D trf;
trf = Translation3D(Vector3D(0, 30, 20));
bb = tvb.boundingBox(&trf);
CHECK_CLOSE_ABS(bb.max(), Vector3D(10, 38, 24), tol);
CHECK_CLOSE_ABS(bb.min(), Vector3D(-10, 22, 16), tol);
trf = AngleAxis3D(M_PI / 2., Vector3D(-2, 4, 5).normalized());
bb = tvb.boundingBox(&trf);
CHECK_CLOSE_ABS(bb.max(), Vector3D(9.32577, 11.4906, 11.5777), tol);
CHECK_CLOSE_ABS(bb.min(), Vector3D(-9.77021, -8.65268, -9.23688), tol);
}
BOOST_AUTO_TEST_CASE(TrapezoidVolumeBoundarySurfaces) {
TrapezoidVolumeBounds tvb(5, 10, 8, 4);
auto tvbOrientedSurfaces = tvb.orientedSurfaces(Transform3D::Identity());
BOOST_CHECK_EQUAL(tvbOrientedSurfaces.size(), 6);
auto geoCtx = GeometryContext();
for (auto& os : tvbOrientedSurfaces) {
auto osCenter = os.first->center(geoCtx);
auto osNormal = os.first->normal(geoCtx, osCenter);
double nDir = (double)os.second;
// Check if you step inside the volume with the oriented normal
auto insideTvb = osCenter + nDir * osNormal;
auto outsideTvb = osCenter - nDir * osNormal;
BOOST_CHECK(tvb.inside(insideTvb));
BOOST_CHECK(!tvb.inside(outsideTvb));
}
Vector3D xaxis(1., 0., 0.);
Vector3D yaxis(0., 1., 0.);
Vector3D zaxis(0., 0., 1.);
// Test the orientation of the boundary surfaces
auto nFaceXY =
tvbOrientedSurfaces[negativeFaceXY].first->transform(geoCtx).rotation();
BOOST_CHECK(nFaceXY.col(0).isApprox(xaxis));
BOOST_CHECK(nFaceXY.col(1).isApprox(yaxis));
BOOST_CHECK(nFaceXY.col(2).isApprox(zaxis));
auto pFaceXY =
tvbOrientedSurfaces[positiveFaceXY].first->transform(geoCtx).rotation();
BOOST_CHECK(pFaceXY.col(0).isApprox(xaxis));
BOOST_CHECK(pFaceXY.col(1).isApprox(yaxis));
BOOST_CHECK(pFaceXY.col(2).isApprox(zaxis));
auto nFaceZX =
tvbOrientedSurfaces[negativeFaceZX].first->transform(geoCtx).rotation();
BOOST_CHECK(nFaceZX.col(0).isApprox(zaxis));
BOOST_CHECK(nFaceZX.col(1).isApprox(xaxis));
BOOST_CHECK(nFaceZX.col(2).isApprox(yaxis));
auto pFaceZX =
tvbOrientedSurfaces[positiveFaceZX].first->transform(geoCtx).rotation();
BOOST_CHECK(pFaceZX.col(0).isApprox(zaxis));
BOOST_CHECK(pFaceZX.col(1).isApprox(xaxis));
BOOST_CHECK(pFaceZX.col(2).isApprox(yaxis));
}
BOOST_AUTO_TEST_SUITE_END()
} // namespace Test
} // namespace Acts