Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:28:06

0001 // This file is part of the actsvg packge.
0002 //
0003 // Copyright (C) 2022 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "defs.hpp"
0012 
0013 #include <vector>
0014 #include <array>
0015 #include <cmath>
0016 
0017 namespace actsvg
0018 {
0019 
0020     namespace generators
0021     {
0022 
0023         /** Generate phi values, respecting phi boundaries
0024          *
0025          * @param start_phi is the start for the arc generation
0026          * @param end_phi is the end of the arc generation
0027          * @param lseg is the number of segments used to gnerate the arc
0028          *
0029          * @return a vector of phi values for the arc
0030          */
0031         inline std::vector<scalar> phi_values(scalar start_phi, scalar end_phi,
0032                                        unsigned int lseg)
0033         {
0034             std::vector<scalar> values;
0035             values.reserve(lseg + 1);
0036             scalar step_phi = (end_phi - start_phi) / lseg;
0037             for (unsigned int istep = 0; istep <= lseg; ++istep)
0038             {
0039                 values.push_back(start_phi + istep * step_phi);
0040             }
0041             return values;
0042         }
0043 
0044         /** Generate a contour for a sector
0045          *
0046          * @param inner_r is the inner radius
0047          * @param outer_r is the outer radius
0048          * @param start_phi is the start for the arc generation
0049          * @param end_phi is the end of the arc generation
0050          * @param lseg is the number of segments to approximate the arc
0051          * 
0052          * @note this contour generation DOES NOT perform the y flip
0053          * @note start/end are respected in terms of orientation
0054          *
0055          **/
0056         inline std::vector<point2> sector_contour(scalar inner_r, scalar outer_r,
0057                                                   scalar start_phi, scalar end_phi,
0058                                                   unsigned int lseg=16)
0059         {
0060 
0061             // Re-bound phi
0062             if (start_phi > 0. and end_phi < 0.)
0063             {
0064                 end_phi += 2 * M_PI;
0065             }
0066 
0067             auto inner_phi = phi_values(end_phi, start_phi, lseg);
0068             auto outer_phi = phi_values(start_phi, end_phi, lseg);
0069 
0070             std::vector<point2> sector_vertices;
0071             sector_vertices.reserve(inner_phi.size() + outer_phi.size());
0072             for (auto iphi : inner_phi)
0073             {
0074                 sector_vertices.push_back({inner_r * std::cos(iphi),
0075                                            inner_r * std::sin(iphi)});
0076             }
0077             for (auto ophi : outer_phi)
0078             {
0079                 sector_vertices.push_back({outer_r * std::cos(ophi),
0080                                            outer_r * std::sin(ophi)});
0081             }
0082             return sector_vertices;
0083         }
0084 
0085     } // generators
0086 
0087 } // namespace actsvg