Refactoring#43
Conversation
|
Continuing the discussion from #42
I don't think we "break" the encapsulation. In fact, now a sphere or rectangle don't have to be aware of what is a Speaking strictly of design, I think there is a rational for a An alternative to a complete visitor class would be to have a set of overloaded intersect function, such as: bool intersect(scene::box const& b, task_context& ctx, const ray& r, real_t min, real_t max,
hit_record& rec, material_t& hit_material_type) {
hit_record temp_rec;
scene::material_t temp_material_type;
auto hit_anything = false;
auto closest_so_far = max;
// Checking if the ray hits any of the sides
for (const auto& side : b.sides) {
if (dev_visit(_hitable_hit(ctx, r, min, closest_so_far, temp_rec,
temp_material_type),
side)) {
hit_anything = true;
closest_so_far = temp_rec.t;
rec = temp_rec;
hit_material_type = temp_material_type;
}
}
return hit_anything;
}And creating implicit visitor by using dev_visit([&ctx, &r, =min, =max, &rec, &material](auto&& obj){
return intersect(obj, ctx, r, min, max, rec, material);
}, variant);But having the complete visitor class allow to DRY.
It is always read-only access on object properties, if these property become private there is no problem to get an accessor on it.
Not sure I understand you completely here |
|
I need to dive into the code again... |
|
I am unsure we want to close this. Perhaps keeping this as a Draft PR instead to keep track of this? |
Split refactoring commit from #42