Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RectangleBoundsTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RectangleBoundsTests.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 
18 
19 #include <algorithm>
20 #include <array>
21 #include <iostream>
22 #include <limits>
23 #include <stdexcept>
24 #include <vector>
25 
26 namespace utf = boost::unit_test;
27 const double inf = std::numeric_limits<double>::infinity();
28 
29 namespace Acts {
30 
31 namespace Test {
33  const auto& v = r.vertices();
34  for (const auto& i : v) {
35  std::cout << "(" << i[0] << ", " << i[1] << ")" << std::endl;
36  }
37 }
38 bool approximatelyEqual(const Vector2& a, const Vector2& b) {
39  const double dif0 = std::abs(a[0] - b[0]);
40  const double dif1 = std::abs(a[1] - b[1]);
41  const double tol = 1e-9;
42  return ((dif0 < tol) and (dif1 < tol));
43 }
44 BOOST_AUTO_TEST_SUITE(Surfaces)
45 
46 
47 BOOST_AUTO_TEST_CASE(RectangleBoundsConstruction) {
48  const double halfX(10.), halfY(5.);
49  RectangleBounds twentyByTenRectangle(halfX, halfY);
50  BOOST_CHECK_EQUAL(twentyByTenRectangle.type(),
52  //
53  // nonsensical bounds are also permitted, but maybe should not be
54  const double zeroHalfX(0.), zeroHalfY(0.);
55  const double infHalfX(inf), infHalfY(inf);
56  //
57  // BOOST_TEST_MESSAGE("Initialise with zero dimensions");
58  RectangleBounds zeroDimensionsRectangle(zeroHalfX, zeroHalfY);
59  BOOST_CHECK_EQUAL(zeroDimensionsRectangle.type(),
61  //
62  // BOOST_TEST_MESSAGE("Initialise with infinite dimensions");
63  RectangleBounds infinite(infHalfX, infHalfY);
64  BOOST_CHECK_EQUAL(infinite.type(), Acts::SurfaceBounds::eRectangle);
65 }
66 
68 BOOST_AUTO_TEST_CASE(RectangleBoundsRecreation) {
69  const double halfX(10.), halfY(2.);
70  RectangleBounds original(halfX, halfY);
71  // const bool symmetric(false);
72  auto valvector = original.values();
73  std::array<double, RectangleBounds::eSize> values{};
74  std::copy_n(valvector.begin(), RectangleBounds::eSize, values.begin());
75  RectangleBounds recreated(values);
76  BOOST_CHECK_EQUAL(original, recreated);
77 }
78 
79 // Exception tests
80 BOOST_AUTO_TEST_CASE(RadialBoundsException) {
81  const double halfX(10.), halfY(2.);
82 
83  // Negative x half length
84  BOOST_CHECK_THROW(RectangleBounds(-halfX, halfY), std::logic_error);
85 
86  // Negative y half length
87  BOOST_CHECK_THROW(RectangleBounds(halfX, -halfY), std::logic_error);
88 }
89 
91 BOOST_TEST_DECORATOR(*utf::tolerance(1e-10))
92 BOOST_AUTO_TEST_CASE(RectangleBoundsProperties) {
93  const double halfX(10.), halfY(5.);
94  RectangleBounds rect(halfX, halfY);
95  BOOST_CHECK_EQUAL(rect.halfLengthX(), 10.);
96  BOOST_CHECK_EQUAL(rect.halfLengthY(), 5.);
97 
98  CHECK_CLOSE_ABS(rect.min(), Vector2(-halfX, -halfY), 1e-6);
99  CHECK_CLOSE_ABS(rect.max(), Vector2(halfX, halfY), 1e-6);
100 
101  const std::vector<Vector2> coords = {
102  {-10., -5.}, {10., -5.}, {10., 5.}, {-10., 5.}};
103  // equality, ensure ordering is ok
104  const auto& rectVertices = rect.vertices();
105  BOOST_CHECK_EQUAL_COLLECTIONS(coords.cbegin(), coords.cend(),
106  rectVertices.cbegin(), rectVertices.cend());
107  const Vector2 pointA{1.0, 1.0};
108  // distance is signed, from boundary to point. (doesn't seem right, given
109  BoundaryCheck bcheck(true, true);
110  BOOST_CHECK(rect.inside(pointA, bcheck));
111 }
112 BOOST_AUTO_TEST_CASE(RectangleBoundsAssignment) {
113  const double halfX(10.), halfY(2.);
114  RectangleBounds rectA(halfX, halfY);
115  RectangleBounds rectB(0.0, 0.0);
116  rectB = rectA;
117  const auto originalVertices = rectA.vertices();
118  const auto assignedVertices = rectB.vertices();
119  BOOST_CHECK_EQUAL_COLLECTIONS(
120  originalVertices.cbegin(), originalVertices.cend(),
121  assignedVertices.cbegin(), assignedVertices.cend());
122 }
123 
124 BOOST_AUTO_TEST_SUITE_END()
125 } // namespace Test
126 
127 } // namespace Acts