Analysis Software
Documentation for sPHENIX simulation 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 
17 #include <algorithm>
18 #include <cstddef>
19 #include <vector>
20 
22 
23 namespace Acts {
24 namespace Test {
25 BOOST_AUTO_TEST_SUITE(Surfaces)
26 // See: https://en.wikipedia.org/wiki/Bounding_volume
27 //
28 // Aligned box w/ simple check
29 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxSimple) {
30  BoundaryCheck check(true);
31  Vector2 ll(-1, -1);
32  Vector2 ur(1, 1);
33  BOOST_CHECK(check.isInside({0, 0}, ll, ur));
34  BOOST_CHECK(!check.isInside({2, 2}, ll, ur));
35  BOOST_CHECK(!check.isInside({0, 2}, ll, ur));
36  BOOST_CHECK(!check.isInside({2, 0}, ll, ur));
37 }
38 // Aligned box w/ tolerance check along first axis
39 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxToleranceLoc0) {
40  BoundaryCheck check(true, false, 1.5, 0.0);
41  Vector2 ll(-1, -1);
42  Vector2 ur(1, 1);
43  BOOST_CHECK(check.isInside({0, 0}, ll, ur));
44  BOOST_CHECK(check.isInside({2, 2}, ll, ur));
45  BOOST_CHECK(!check.isInside({4, 4}, ll, ur));
46  BOOST_CHECK(check.isInside({0, 2}, ll, ur));
47  BOOST_CHECK(check.isInside({2, 0}, ll, ur));
48 }
49 
50 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxDistance) {
51  BoundaryCheck bcheck(true);
52 
53  for (size_t i = 0; i < rectTestPoints.size(); i++) {
54  const Vector2& testPoint = rectTestPoints.at(i);
55  double refDistance = rectDistances.at(i);
56  Vector2 ll(rectDimensions.xmin, rectDimensions.ymin);
57  Vector2 ur(rectDimensions.xmax, rectDimensions.ymax);
58  double distance = bcheck.distance(testPoint, ll, ur);
59  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
60  }
61 
62  for (size_t i = 0; i < rectShiftedTestPoints.size(); i++) {
63  const Vector2& testPoint = rectShiftedTestPoints.at(i);
64  double refDistance = rectShiftedDistances.at(i);
67  double distance = bcheck.distance(testPoint, ll, ur);
68  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
69  }
70 }
71 
72 // Aligned box w/ covariance check
73 BOOST_AUTO_TEST_CASE(BoundaryCheckBoxCovariance) {
75  cov << 1, 0.5, 0.5, 2;
76  BoundaryCheck check(cov, 3.0);
77  Vector2 ll(-1, -1);
78  Vector2 ur(1, 1);
79  BOOST_CHECK(check.isInside({0, 0}, ll, ur));
80  BOOST_CHECK(check.isInside({2, 2}, ll, ur));
81  BOOST_CHECK(!check.isInside({4, 4}, ll, ur));
82  BOOST_CHECK(check.isInside({0, 3}, ll, ur));
83  BOOST_CHECK(check.isInside({3, 0}, ll, ur));
84 }
85 
86 BOOST_AUTO_TEST_CASE(BoundaryCheckPolyDistance) {
87  // we check a box again, but this time described as a poly
88 
89  BoundaryCheck bcheck(true);
90 
91  for (size_t i = 0; i < rectTestPoints.size(); i++) {
92  const Vector2& testPoint = rectTestPoints.at(i);
93  double refDistance = rectDistances.at(i);
94  double distance = bcheck.distance(testPoint, rectVertices);
95  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
96  }
97 
98  for (size_t i = 0; i < rectShiftedTestPoints.size(); i++) {
99  const Vector2& testPoint = rectShiftedTestPoints.at(i);
100  double refDistance = rectShiftedDistances.at(i);
101  double distance = bcheck.distance(testPoint, rectShiftedVertices);
102  CHECK_CLOSE_REL(refDistance, distance, 1e-6);
103  }
104 }
105 
106 // Triangle w/ simple check
107 BOOST_AUTO_TEST_CASE(BoundaryCheckTriangleSimple) {
108  Vector2 vertices[] = {{-2, 0}, {2, 0}, {0, 2}};
109  BoundaryCheck check(true);
110  BOOST_CHECK(check.isInside({0, 0}, vertices));
111  BOOST_CHECK(check.isInside({0, 1}, vertices));
112  BOOST_CHECK(!check.isInside({2, 2}, vertices));
113  BOOST_CHECK(!check.isInside({0, -1}, vertices));
114 }
115 // Triangle w/ covariance check
116 BOOST_AUTO_TEST_CASE(BoundaryCheckTriangleCovariance) {
117  Vector2 vertices[] = {{-2, 0}, {2, 0}, {0, 2}};
119  cov << 0.5, 0, 0, 0.5;
120  BoundaryCheck check(cov, 4.1);
121  BOOST_CHECK(check.isInside({0, 0}, vertices));
122  BOOST_CHECK(check.isInside({0, 1}, vertices));
123  BOOST_CHECK(check.isInside({0, 2}, vertices));
124  BOOST_CHECK(check.isInside({0, 3}, vertices));
125  BOOST_CHECK(check.isInside({0, 4}, vertices));
126  BOOST_CHECK(!check.isInside({0, 5}, vertices));
127 }
128 BOOST_AUTO_TEST_SUITE_END()
129 } // namespace Test
130 } // namespace Acts