surface intersection specialization #27
Unanswered
asalzburger
asked this question in
Q&A
Replies: 2 comments 1 reply
-
You mean that the |
Beta Was this translation helpful? Give feedback.
0 replies
-
This is the kind of thing you'd want to solve with a macro system, but I'm guessing we don't really want to be using C++'s non-syntactic macro system here. The cleanest thing I can think of right now (and that's not really saying much in this case) is to abstract the logic inside the if-else conditions into some templated function, roughly like this: template <typename surface_type, typename links_type, typename mask_type_map, typename mask_container>
bool update_intersection(
surface_intersection &sfi,
links_type &links,
track<transform_type> &track,
const transform_type &trf,
const surface_type &surface,
const mask_type_map &mask_types,
const mask_container &masks,
bool trust = false
) {
auto h = [&]<int N>(auto tmr) -> std::optional<bool> {
if (std::get<0>(tmr) != N) {
return {};
}
const auto &mask_group = std::get<N>(masks);
if constexpr (N == 2) {
return update_intersection_by_mask(sfi, links, track, trf, cyl2, mask_group, std::get<1>(tmr));
} else {
return update_intersection_by_mask(sfi, links, track, trf, cart2, mask_group, std::get<1>(tmr));
}
}
const auto &tmr = surface.mask();
return h<0>(tmr).value_or(h<1>(tmr).value_or(h<2>(tmr).value_or(h<3>(tmr).value_or(false))));
} Edit: Rather, because C++ doesn't do lazy evaluation: if (auto v = h<0>(tmr), v) {
return *v;
} else if (auto v = h<1>(tmr), v) {
return *v;
} else if (auto v = h<2>(tmr), v) {
return *v;
} else if (auto v = h<3>(tmr), v) {
return *v;
} else {
return false;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As there are no polymorphic types in the detector, different surface masks are accessed by their tuple index, i.e. in the
navigator
this looks like this.The code looks a bit clumsy, can this be unrolled at compile time?
@paulgessinger @krasznaa @stephenswat - any ides?
Beta Was this translation helpful? Give feedback.
All reactions