Bor,
when I was dealing with this problem I did the same at certain point (see my post of 5th August): however, in my opinion this solution could just hide the real problem which is (in my opinion) the one described above. Moreover, this solution can create issues here:
if (p.collision_distance() > p.boundary().distance) {
p.event_cross_surface();
} else {
p.event_collide();
}
p.collision_distance() can be INFINITY (see here) and if both are INFINITY the “if” statement would fail. Indeed, in my opinion, this is the reason why we have two “infinity” values in the code.
The following for loop in Region::distance fails in finding i_surf so it remains at the initializated value (std::numeric_limits<int32_t>::max()): it fails because it’s considering the wrong cell (from here).
for (int32_t token : expression_) {
// Ignore this token if it corresponds to an operator rather than a region.
if (token >= OP_UNION)
continue;// Calculate the distance to this surface. // Note the off-by-one indexing bool coincident {std::abs(token) == std::abs(on_surface)}; double d {model::surfaces[abs(token) - 1]->distance(r, u, coincident)}; // Check if this distance is the new minimum. if (d < min_dist) { if (min_dist - d >= FP_PRECISION * min_dist) { min_dist = d; i_surf = -token; } }
Best,
Giovanni