Fix T101645: division by zero in fillet node

This commit is contained in:
Jacques Lucke 2022-10-20 16:15:02 +02:00
parent f017fdecef
commit 9d710374bd
Notes: blender-bot 2023-02-14 00:44:02 +01:00
Referenced by issue #101645, Geometry Nodes: ASAN + divide by zero
1 changed files with 4 additions and 2 deletions

View File

@ -148,12 +148,14 @@ static float limit_radius(const float3 &position_prev,
const float displacement_prev = radius_prev * std::tan(angle_prev / 2.0f);
const float segment_length_prev = math::distance(position, position_prev);
const float total_displacement_prev = displacement_prev + displacement;
const float factor_prev = std::clamp(segment_length_prev / total_displacement_prev, 0.0f, 1.0f);
const float factor_prev = std::clamp(
safe_divide(segment_length_prev, total_displacement_prev), 0.0f, 1.0f);
const float displacement_next = radius_next * std::tan(angle_next / 2.0f);
const float segment_length_next = math::distance(position, position_next);
const float total_displacement_next = displacement_next + displacement;
const float factor_next = std::clamp(segment_length_next / total_displacement_next, 0.0f, 1.0f);
const float factor_next = std::clamp(
safe_divide(segment_length_next, total_displacement_next), 0.0f, 1.0f);
return radius * std::min(factor_prev, factor_next);
}