ECCE @ 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 <boost/container/small_vector.hpp>
16 #include <cmath>
17 #include <exception>
18 
19 namespace Acts {
20 
27  public:
30  std::ostream& toStream(std::ostream& sl) const final;
31 
35  std::vector<double> values() const final;
36 
37  protected:
41  template <typename coll_t>
42  static RectangleBounds makeBoundingBox(const coll_t& vertices);
43 
49  template <typename coll_t>
50  static void convex_impl(const coll_t& vertices) noexcept(false);
51 };
52 
58 template <int N>
60  public:
63  static constexpr size_t num_vertices = N;
66  using vertex_array = std::array<Vector2D, num_vertices>;
69  static constexpr size_t eSize = 2 * N;
72  using value_array = std::array<double, eSize>;
73 
74  static_assert(N >= 3, "ConvexPolygonBounds needs at least 3 sides.");
75 
76  ConvexPolygonBounds() = delete;
77 
82  ConvexPolygonBounds(const std::vector<Vector2D>& vertices) noexcept(false);
83 
87  ConvexPolygonBounds(const vertex_array& vertices) noexcept(false);
88 
92  ConvexPolygonBounds(const value_array& values) noexcept(false);
93 
94  ~ConvexPolygonBounds() override = default;
95 
96  BoundsType type() const final;
97 
103  bool inside(const Vector2D& lposition,
104  const BoundaryCheck& bcheck) const final;
105 
110  double distanceToBoundary(const Vector2D& lposition) const final;
111 
120  std::vector<Vector2D> vertices(unsigned int lseg = 1) const final;
121 
124  const RectangleBounds& boundingBox() const final;
125 
126  private:
129 
132  void checkConsistency() const noexcept(false);
133 };
134 
136 constexpr int PolygonDynamic = -1;
137 
141 template <>
142 class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase {
143  public:
145  ConvexPolygonBounds() = delete;
146 
148  ~ConvexPolygonBounds() override = default;
149 
153  ConvexPolygonBounds(const std::vector<Vector2D>& vertices);
154 
157  BoundsType type() const final;
158 
164  bool inside(const Vector2D& lposition,
165  const BoundaryCheck& bcheck) const final;
166 
171  double distanceToBoundary(const Vector2D& lposition) const final;
172 
181  std::vector<Vector2D> vertices(unsigned int lseg = 1) const final;
182 
187  const RectangleBounds& boundingBox() const final;
188 
189  private:
190  boost::container::small_vector<Vector2D, 10> m_vertices;
192 
195  void checkConsistency() const noexcept(false);
196 };
197 
198 } // namespace Acts
199 
200 #include "Acts/Surfaces/ConvexPolygonBounds.ipp"