Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 08:01:52

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/Surfaces/ConvexPolygonBounds.hpp"
0012 
0013 #include "Acts/Surfaces/detail/VerticesHelper.hpp"
0014 #include "Acts/Utilities/ThrowAssert.hpp"
0015 
0016 namespace Acts {
0017 
0018 template <int N>
0019   requires isValidConvexPolygonSize<N>
0020 ConvexPolygonBounds<N>::ConvexPolygonBounds(
0021     std::span<const Vector2> vertices) noexcept(false) {
0022   throw_assert(vertices.size() == N,
0023                "Size and number of given vertices do not match.");
0024 
0025   std::ranges::copy(vertices, m_vertices.begin());
0026 
0027   checkConsistency(m_vertices);
0028   makeBoundingBox(m_vertices);
0029   calculateCenter(m_vertices);
0030 }
0031 
0032 template <int N>
0033   requires isValidConvexPolygonSize<N>
0034 ConvexPolygonBounds<N>::ConvexPolygonBounds(
0035     std::span<const double> values) noexcept(false) {
0036   throw_assert(values.size() == 2 * N,
0037                "Size and number of given values do not match.");
0038   for (std::size_t i = 0; i < N; i++) {
0039     m_vertices[i] = Vector2(values[2 * i], values[2 * i + 1]);
0040   }
0041   checkConsistency(m_vertices);
0042   makeBoundingBox(m_vertices);
0043   calculateCenter(m_vertices);
0044 }
0045 
0046 template <int N>
0047   requires isValidConvexPolygonSize<N>
0048 bool ConvexPolygonBounds<N>::inside(const Vector2& lposition) const {
0049   return detail::VerticesHelper::isInsidePolygon(lposition, m_vertices);
0050 }
0051 
0052 template <int N>
0053   requires isValidConvexPolygonSize<N>
0054 Vector2 ConvexPolygonBounds<N>::closestPoint(
0055     const Vector2& lposition, const SquareMatrix2& metric) const {
0056   return detail::VerticesHelper::computeClosestPointOnPolygon(
0057       lposition, m_vertices, metric);
0058 }
0059 
0060 template <int N>
0061   requires isValidConvexPolygonSize<N>
0062 std::vector<Vector2> ConvexPolygonBounds<N>::vertices(
0063     unsigned int /*ignoredSegments*/) const {
0064   return {m_vertices.begin(), m_vertices.end()};
0065 }
0066 
0067 }  // namespace Acts