Analysis Software
Documentation for sPHENIX simulation 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 
16 
17 #include <array>
18 #include <cmath>
19 #include <cstddef>
20 #include <exception>
21 #include <iosfwd>
22 #include <vector>
23 
24 #include <boost/container/small_vector.hpp>
25 
26 namespace Acts {
27 
34  public:
37  std::ostream& toStream(std::ostream& sl) const final;
38 
42  std::vector<double> values() const final;
43 
44  protected:
48  template <typename coll_t>
49  static RectangleBounds makeBoundingBox(const coll_t& vertices);
50 
56  template <typename coll_t>
57  static void convex_impl(const coll_t& vertices) noexcept(false);
58 };
59 
65 template <int N>
67  public:
70  static constexpr size_t num_vertices = N;
73  using vertex_array = std::array<Vector2, num_vertices>;
76  static constexpr size_t eSize = 2 * N;
79  using value_array = std::array<double, eSize>;
80 
81  static_assert(N >= 3, "ConvexPolygonBounds needs at least 3 sides.");
82 
83  ConvexPolygonBounds() = delete;
84 
89  ConvexPolygonBounds(const std::vector<Vector2>& vertices) noexcept(false);
90 
94  ConvexPolygonBounds(const vertex_array& vertices) noexcept(false);
95 
99  ConvexPolygonBounds(const value_array& values) noexcept(false);
100 
101  ~ConvexPolygonBounds() override = default;
102 
103  BoundsType type() const final;
104 
110  bool inside(const Vector2& lposition,
111  const BoundaryCheck& bcheck) const final;
112 
121  std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
122 
125  const RectangleBounds& boundingBox() const final;
126 
127  private:
130 
133  void checkConsistency() const noexcept(false);
134 };
135 
137 constexpr int PolygonDynamic = -1;
138 
142 template <>
143 class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase {
144  public:
145  constexpr static int eSize = -1;
146 
148  ConvexPolygonBounds() = delete;
149 
151  ~ConvexPolygonBounds() override = default;
152 
156  ConvexPolygonBounds(const std::vector<Vector2>& vertices);
157 
160  BoundsType type() const final;
161 
167  bool inside(const Vector2& lposition,
168  const BoundaryCheck& bcheck) const final;
169 
178  std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
179 
184  const RectangleBounds& boundingBox() const final;
185 
186  private:
187  boost::container::small_vector<Vector2, 10> m_vertices;
188  RectangleBounds m_boundingBox;
189 
192  void checkConsistency() const noexcept(false);
193 };
194 
195 } // namespace Acts
196 
197 #include "Acts/Surfaces/ConvexPolygonBounds.ipp"