Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RectangleBounds.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file RectangleBounds.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2020 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 #pragma once
10 
15 
16 #include <array>
17 #include <cassert>
18 #include <iosfwd>
19 #include <limits>
20 #include <stdexcept>
21 #include <vector>
22 
23 namespace Acts {
24 
30 class RectangleBounds : public PlanarBounds {
31  public:
32  enum BoundValues : int {
33  eMinX = 0,
34  eMinY = 1,
35  eMaxX = 2,
36  eMaxY = 3,
37  eSize = 4
38  };
39 
40  RectangleBounds() = delete;
41 
46  RectangleBounds(double halfX, double halfY) noexcept(false)
47  : m_min({-halfX, -halfY}), m_max({halfX, halfY}) {
49  }
50 
54  RectangleBounds(const std::array<double, eSize>& values) noexcept(false)
55  : m_min({values[eMinX], values[eMinY]}),
58  }
59 
64  RectangleBounds(const Vector2& min, const Vector2& max) noexcept(false)
65  : m_min(min), m_max(max) {
67  }
68 
69  ~RectangleBounds() override = default;
70 
71  BoundsType type() const final;
72 
73  std::vector<double> values() const final;
74 
82  bool inside(const Vector2& lposition,
83  const BoundaryCheck& bcheck) const final;
84 
93  std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
94 
95  // Bounding box representation
96  const RectangleBounds& boundingBox() const final;
97 
101  std::ostream& toStream(std::ostream& sl) const final;
102 
105  double get(BoundValues bValue) const;
106 
108  double halfLengthX() const;
109 
111  double halfLengthY() const;
112 
115  const Vector2& min() const;
116 
119  const Vector2& max() const;
120 
121  private:
124 
127  void checkConsistency() noexcept(false);
128 };
129 
132 }
133 
134 inline const Vector2& RectangleBounds::min() const {
135  return m_min;
136 }
137 
138 inline const Vector2& RectangleBounds::max() const {
139  return m_max;
140 }
141 
142 inline double RectangleBounds::halfLengthX() const {
143  return 0.5 * (m_max.x() - m_min.x());
144 }
145 
146 inline double RectangleBounds::halfLengthY() const {
147  return 0.5 * (m_max.y() - m_min.y());
148 }
149 
150 inline std::vector<double> RectangleBounds::values() const {
151  return {m_min.x(), m_min.y(), m_max.x(), m_max.y()};
152 }
153 
154 inline double RectangleBounds::get(BoundValues bValue) const {
155  switch (bValue) {
156  case eMinX:
157  return m_min.x();
158  case eMinY:
159  return m_min.y();
160  case eMaxX:
161  return m_max.x();
162  case eMaxY:
163  return m_max.y();
164  default:
165  assert(false and "Invalid BoundValue enum value");
166  return std::numeric_limits<double>::quiet_NaN();
167  }
168 }
169 
170 inline void RectangleBounds::checkConsistency() noexcept(false) {
171  if (get(eMinX) > get(eMaxX)) {
172  throw std::invalid_argument("RectangleBounds: invalid local x setup");
173  }
174  if (get(eMinY) > get(eMaxY)) {
175  throw std::invalid_argument("RectangleBounds: invalid local y setup");
176  }
177 }
178 
179 } // namespace Acts