ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BoundaryCheckTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file BoundaryCheckTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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/data/test_case.hpp>
10 #include <boost/test/tools/output_test_stream.hpp>
11 #include <boost/test/unit_test.hpp>
12 
16 #include "Acts/Utilities/Units.hpp"
17 
18 namespace Acts {
19 namespace Test {
20 BOOST_AUTO_TEST_SUITE(Surfaces)
21 // See: https://en.wikipedia.org/wiki/Bounding_volume
22 //
23 // Aligned box w/ simple check
24 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxSimple) {
25  BoundaryCheck check(true);
26  Vector2D ll(-1, -1);
27  Vector2D ur(1, 1);
28  BOOST_CHECK(check.isInside({0, 0}, ll, ur));
29  BOOST_CHECK(!check.isInside({2, 2}, ll, ur));
30  BOOST_CHECK(!check.isInside({0, 2}, ll, ur));
31  BOOST_CHECK(!check.isInside({2, 0}, ll, ur));
32 }
33 // Aligned box w/ tolerance check along first axis
34 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxToleranceLoc0) {
35  BoundaryCheck check(true, false, 1.5, 0.0);
36  Vector2D ll(-1, -1);
37  Vector2D ur(1, 1);
38  BOOST_CHECK(check.isInside({0, 0}, ll, ur));
39  BOOST_CHECK(check.isInside({2, 2}, ll, ur));
40  BOOST_CHECK(!check.isInside({4, 4}, ll, ur));
41  BOOST_CHECK(check.isInside({0, 2}, ll, ur));
42  BOOST_CHECK(check.isInside({2, 0}, ll, ur));
43 }
44 
45 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxDistance) {
47 
48  BoundaryCheck bcheck(true);
49 
50  for (size_t i = 0; i < rectTestPoints.size(); i++) {
51  const Vector2D& testPoint = rectTestPoints.at(i);
52  double refDistance = rectDistances.at(i);
53  Vector2D ll(rectDimensions.xmin, rectDimensions.ymin);
54  Vector2D ur(rectDimensions.xmax, rectDimensions.ymax);
55  double distance = bcheck.distance(testPoint, ll, ur);
56  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
57  }
58 
59  for (size_t i = 0; i < rectShiftedTestPoints.size(); i++) {
60  const Vector2D& testPoint = rectShiftedTestPoints.at(i);
61  double refDistance = rectShiftedDistances.at(i);
64  double distance = bcheck.distance(testPoint, ll, ur);
65  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
66  }
67 }
68 
69 // Aligned box w/ covariance check
70 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxCovariance) {
72  cov << 1, 0.5, 0.5, 2;
73  BoundaryCheck check(cov, 3.0);
74  Vector2D ll(-1, -1);
75  Vector2D ur(1, 1);
76  BOOST_CHECK(check.isInside({0, 0}, ll, ur));
77  BOOST_CHECK(check.isInside({2, 2}, ll, ur));
78  BOOST_CHECK(!check.isInside({4, 4}, ll, ur));
79  BOOST_CHECK(check.isInside({0, 3}, ll, ur));
80  BOOST_CHECK(check.isInside({3, 0}, ll, ur));
81 }
82 
83 BOOST_AUTO_TEST_CASE(BoundaryCheckPolyDistance) {
84  // we check a box again, but this time described as a poly
85 
87 
88  BoundaryCheck bcheck(true);
89 
90  for (size_t i = 0; i < rectTestPoints.size(); i++) {
91  const Vector2D& testPoint = rectTestPoints.at(i);
92  double refDistance = rectDistances.at(i);
93  double distance = bcheck.distance(testPoint, rectVertices);
94  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
95  }
96 
97  for (size_t i = 0; i < rectShiftedTestPoints.size(); i++) {
98  const Vector2D& testPoint = rectShiftedTestPoints.at(i);
99  double refDistance = rectShiftedDistances.at(i);
100  double distance = bcheck.distance(testPoint, rectShiftedVertices);
101  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
102  }
103 }
104 
105 // Triangle w/ simple check
106 BOOST_AUTO_TEST_CASE(BoundaryCheckTriangleSimple) {
107  Vector2D vertices[] = {{-2, 0}, {2, 0}, {0, 2}};
108  BoundaryCheck check(true);
109  BOOST_CHECK(check.isInside({0, 0}, vertices));
110  BOOST_CHECK(check.isInside({0, 1}, vertices));
111  BOOST_CHECK(!check.isInside({2, 2}, vertices));
112  BOOST_CHECK(!check.isInside({0, -1}, vertices));
113 }
114 // Triangle w/ covariance check
115 BOOST_AUTO_TEST_CASE(BoundaryCheckTriangleCovariance) {
116  Vector2D vertices[] = {{-2, 0}, {2, 0}, {0, 2}};
117  ActsSymMatrixD<2> cov;
118  cov << 0.5, 0, 0, 0.5;
119  BoundaryCheck check(cov, 4.1);
120  BOOST_CHECK(check.isInside({0, 0}, vertices));
121  BOOST_CHECK(check.isInside({0, 1}, vertices));
122  BOOST_CHECK(check.isInside({0, 2}, vertices));
123  BOOST_CHECK(check.isInside({0, 3}, vertices));
124  BOOST_CHECK(check.isInside({0, 4}, vertices));
125  BOOST_CHECK(!check.isInside({0, 5}, vertices));
126 }
127 BOOST_AUTO_TEST_SUITE_END()
128 } // namespace Test
129 } // namespace Acts