24 LayerFillLimits::LayerFillLimits(std::vector<double> layers_bottomz)
25 : m_layers_bottomz(std::move(layers_bottomz)), m_layer_fill_limits(m_layers_bottomz.size() + 1)
32 if (m_layers_bottomz.empty())
34 double top = particle_limits.m_top + offset;
35 double bottom = particle_limits.m_bottom + offset;
37 throw std::runtime_error(
"LayerFillLimits::update: lower_limit > upper_limit.");
40 size_t top_index = layerIndexTop(top);
41 size_t bottom_index = layerIndexBottom(bottom);
42 for (
size_t i_layer = top_index; i_layer < bottom_index + 1; ++i_layer) {
44 updateLayerLimits(i_layer, limits);
50 return m_layer_fill_limits;
53 size_t LayerFillLimits::layerIndexTop(
double top_z)
const
55 if (m_layers_bottomz.empty())
57 if (top_z <= m_layers_bottomz.back())
58 return m_layers_bottomz.size();
59 auto index_above = std::lower_bound(m_layers_bottomz.rbegin(), m_layers_bottomz.rend(), top_z);
60 return static_cast<size_t>(m_layers_bottomz.rend() - index_above);
63 size_t LayerFillLimits::layerIndexBottom(
double bottom_z)
const
65 if (m_layers_bottomz.empty())
67 if (bottom_z < m_layers_bottomz.back())
68 return m_layers_bottomz.size();
70 std::upper_bound(m_layers_bottomz.rbegin(), m_layers_bottomz.rend(), bottom_z);
71 return static_cast<size_t>(m_layers_bottomz.rend() - index_below);
74 void LayerFillLimits::updateLayerLimits(
size_t i_layer,
ZLimits limits)
76 if (!limits.isFinite())
77 throw std::runtime_error(
"LayerFillLimits::updateLayerLimits: given limits are not "
79 auto old_limits = m_layer_fill_limits[i_layer];
80 double layer_ref = i_layer ? m_layers_bottomz[i_layer - 1] : m_layers_bottomz[i_layer];
82 i_layer ? std::min(limits.upperLimit().m_value, layer_ref) : limits.upperLimit().m_value;
83 double lower = (i_layer == m_layer_fill_limits.size() - 1)
84 ? limits.lowerLimit().m_value
85 : std::max(limits.lowerLimit().m_value, m_layers_bottomz[i_layer]);
86 ZLimits bounded_limits(lower - layer_ref, upper - layer_ref);
87 m_layer_fill_limits[i_layer] = CalculateNewLayerLimits(old_limits, bounded_limits);
94 if (!old_limits.isFinite())
95 return bounded_limits;
97 return ConvexHull(old_limits, bounded_limits);
Defines class LayerFillLimits.
std::vector< ZLimits > layerZLimits() const
Returns the filled region limits for each layer (in local layer coordinates)
void update(ParticleLimits particle_limits, double offset=0.0)
Particle limits are given in global coordinates.
Class that contains upper and lower limits of the z-coordinate for the slicing of form factors.
Vertical extension of a particle, specified by bottom and top z coordinate.