Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:03

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/BoundaryTolerance.hpp"
0013 #include "Acts/Surfaces/PlanarBounds.hpp"
0014 #include "Acts/Surfaces/RectangleBounds.hpp"
0015 #include "Acts/Surfaces/SurfaceBounds.hpp"
0016 
0017 #include <array>
0018 #include <cstddef>
0019 #include <iosfwd>
0020 #include <vector>
0021 
0022 #include <boost/container/small_vector.hpp>
0023 
0024 namespace Acts {
0025 
0026 /// @brief base class for convex polygon bounds
0027 ///
0028 /// This class serves as a base class for the actual bounds class.
0029 /// The only deriving type is the templated `ConvexPolygonBounds`.
0030 ///
0031 class ConvexPolygonBoundsBase : public PlanarBounds {
0032  public:
0033   /// Output Method for std::ostream
0034   /// @param sl is the ostream to be written into
0035   std::ostream& toStream(std::ostream& sl) const final;
0036 
0037   /// Return the bound values as dynamically sized vector
0038   ///
0039   /// @return this returns a copy of the internal values
0040   std::vector<double> values() const final;
0041 
0042  protected:
0043   /// Return a rectangle bounds instance that encloses a set of vertices.
0044   /// @param vertices A collection of vertices to enclose.
0045   /// @return Enclosing rectangle.
0046   template <typename coll_t>
0047   static RectangleBounds makeBoundingBox(const coll_t& vertices);
0048 
0049   /// Calculates whether a set of vertices forms a convex polygon. This is
0050   /// generic over the number of vertices, so it's factored out of the concrete
0051   /// classes and into this base class.
0052   /// @param vertices A collection of vertices.
0053   /// throws a logic error if this is not the case
0054   template <typename coll_t>
0055     requires std::same_as<typename coll_t::value_type, Acts::Vector2>
0056   static void convex_impl(const coll_t& vertices) noexcept(false);
0057 };
0058 
0059 /// This is the actual implementation of the bounds.
0060 /// It is templated on the number of vertices, but there is a specialization for
0061 /// *dynamic* number of vertices, where the underlying storage is then a vector.
0062 ///
0063 /// @tparam N Number of vertices
0064 template <int N>
0065 class ConvexPolygonBounds : public ConvexPolygonBoundsBase {
0066  public:
0067   /// Expose number of vertices given as template parameter.
0068   ///
0069   static constexpr std::size_t num_vertices = N;
0070   /// Type that's used to store the vertices, in this case a fixed size array.
0071   ///
0072   using vertex_array = std::array<Vector2, num_vertices>;
0073   /// Expose number of parameters as a template parameter
0074   ///
0075   static constexpr std::size_t eSize = 2 * N;
0076   /// Type that's used to store the vertices, in this case a fixed size array.
0077   ///
0078   using value_array = std::array<double, eSize>;
0079 
0080   static_assert(N >= 3, "ConvexPolygonBounds needs at least 3 sides.");
0081 
0082   /// Constructor from a vector of vertices, to facilitate construction.
0083   /// This will throw if the vector size does not match `num_vertices`.
0084   /// This will throw if the vertices do not form a convex polygon.
0085   /// @param vertices The list of vertices.
0086   ConvexPolygonBounds(const std::vector<Vector2>& vertices) noexcept(false);
0087 
0088   /// Constructor from a fixed size array of vertices.
0089   /// This will throw if the vertices do not form a convex polygon.
0090   /// @param vertices The vertices
0091   ConvexPolygonBounds(const vertex_array& vertices) noexcept(false);
0092 
0093   /// Constructor from a fixed size array of parameters
0094   /// This will throw if the vertices do not form a convex polygon.
0095   /// @param values The values to build up the vertices
0096   ConvexPolygonBounds(const value_array& values) noexcept(false);
0097 
0098   BoundsType type() const final { return SurfaceBounds::eConvexPolygon; }
0099 
0100   /// Return whether a local 2D point lies inside of the bounds defined by this
0101   /// object.
0102   /// @param lposition The local position to check
0103   /// @param boundaryTolerance The `BoundaryTolerance` object handling tolerances.
0104   /// @return Whether the points is inside
0105   bool inside(const Vector2& lposition,
0106               const BoundaryTolerance& boundaryTolerance) const final;
0107 
0108   /// Return the vertices
0109   ///
0110   /// @param ignoredSegments the number of segments used to approximate
0111   /// and eventually curved line
0112   ///
0113   /// @note the number of segments is ignored in this representation
0114   ///
0115   /// @return vector for vertices in 2D
0116   std::vector<Vector2> vertices(unsigned int ignoredSegments = 0u) const final;
0117 
0118   /// Return a rectangle bounds object that encloses this polygon.
0119   /// @return The rectangular bounds
0120   const RectangleBounds& boundingBox() const final;
0121 
0122  private:
0123   vertex_array m_vertices;
0124   RectangleBounds m_boundingBox;
0125 
0126   /// Return whether this bounds class is in fact convex
0127   /// throws a log error if not
0128   void checkConsistency() const noexcept(false);
0129 };
0130 
0131 /// Tag to trigger specialization of a dynamic polygon
0132 constexpr int PolygonDynamic = -1;
0133 
0134 /// This is the specialization handling a polygon with a dynamic number of
0135 /// points. It can accept any number of points.
0136 ///
0137 template <>
0138 class ConvexPolygonBounds<PolygonDynamic> : public ConvexPolygonBoundsBase {
0139  public:
0140   constexpr static int eSize = -1;
0141 
0142   /// Constructor from a vector of vertices, to facilitate construction.
0143   /// This will throw if the vertices do not form a convex polygon.
0144   /// @param vertices The list of vertices.
0145   ConvexPolygonBounds(const std::vector<Vector2>& vertices);
0146 
0147   /// Return the bounds type of this bounds object.
0148   /// @return The bounds type
0149   BoundsType type() const final { return SurfaceBounds::eConvexPolygon; }
0150 
0151   /// Return whether a local 2D point lies inside of the bounds defined by this
0152   /// object.
0153   /// @param lposition The local position to check
0154   /// @param boundaryTolerance The `BoundaryTolerance` object handling tolerances.
0155   /// @return Whether the points is inside
0156   bool inside(const Vector2& lposition,
0157               const BoundaryTolerance& boundaryTolerance) const final;
0158 
0159   /// Return the vertices
0160   ///
0161   /// @param lseg the number of segments used to approximate
0162   /// and eventually curved line
0163   ///
0164   /// @note the number of segments is ignored in this representation
0165   ///
0166   /// @return vector for vertices in 2D
0167   std::vector<Vector2> vertices(unsigned int lseg = 1) const final;
0168 
0169   ///
0170   /// Return a rectangle bounds object that encloses this polygon.
0171   /// @return The rectangular bounds
0172   ///
0173   const RectangleBounds& boundingBox() const final;
0174 
0175  private:
0176   boost::container::small_vector<Vector2, 10> m_vertices;
0177   RectangleBounds m_boundingBox;
0178 
0179   /// Return whether this bounds class is in fact convex
0180   /// thorws a logic error if not
0181   void checkConsistency() const noexcept(false);
0182 };
0183 
0184 }  // namespace Acts
0185 
0186 #include "Acts/Surfaces/ConvexPolygonBounds.ipp"