EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ConvexPolygonBounds.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ConvexPolygonBounds.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 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 
14 
15 #include <cmath>
16 #include <exception>
17 
18 #include <boost/container/small_vector.hpp>
19 
20 namespace Acts {
21 
28  public:
31  std::ostream& toStream(std::ostream& sl) const final;
32 
36  std::vector<double> values() const final;
37 
38  protected:
42  template <typename coll_t>
43  static RectangleBounds makeBoundingBox(const coll_t& vertices);
44 
50  template <typename coll_t>
51  static void convex_impl(const coll_t& vertices) noexcept(false);
52 };
53 
59 template <int N>
61  public:
64  static constexpr size_t num_vertices = N;
67  using vertex_array = std::array<Vector2D, num_vertices>;
70  static constexpr size_t eSize = 2 * N;
73  using value_array = std::array<double, eSize>;
74 
75  static_assert(N >= 3, "ConvexPolygonBounds needs at least 3 sides.");
76 
77  ConvexPolygonBounds() = delete;
78 
83  ConvexPolygonBounds(const std::vector<Vector2D>& vertices) noexcept(false);
84 
88  ConvexPolygonBounds(const vertex_array& vertices) noexcept(false);
89 
93  ConvexPolygonBounds(const value_array& values) noexcept(false);
94 
95  ~ConvexPolygonBounds() override = default;
96 
97  BoundsType type() const final;
98 
104  bool inside(const Vector2D& lposition,
105  const BoundaryCheck& bcheck) const final;
106 
115  std::vector<Vector2D> vertices(unsigned int lseg = 1) const final;
116 
119  const RectangleBounds& boundingBox() const final;
120 
121  private:
124 
127  void checkConsistency() const noexcept(false);
128 };
129 
131 constexpr int PolygonDynamic = -1;
132 
136 template <>
137 class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase {
138  public:
140  ConvexPolygonBounds() = delete;
141 
143  ~ConvexPolygonBounds() override = default;
144 
148  ConvexPolygonBounds(const std::vector<Vector2D>& vertices);
149 
152  BoundsType type() const final;
153 
159  bool inside(const Vector2D& lposition,
160  const BoundaryCheck& bcheck) const final;
161 
170  std::vector<Vector2D> vertices(unsigned int lseg = 1) const final;
171 
176  const RectangleBounds& boundingBox() const final;
177 
178  private:
179  boost::container::small_vector<Vector2D, 10> m_vertices;
181 
184  void checkConsistency() const noexcept(false);
185 };
186 
187 } // namespace Acts
188 
189 #include "Acts/Surfaces/ConvexPolygonBounds.ipp"