File indexing completed on 2025-01-18 09:28:06
0001
0002
0003
0004
0005
0006
0007
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
0024
0025
0026
0027
0028
0029
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
0045
0046
0047
0048
0049
0050
0051
0052
0053
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
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 }
0086
0087 }