Fix divide by zero in Bevel.

The [Fix #125024: Bevel offset - eliminate divide by 0] (#126309)
in response to [Bevel Modifier creates unwanted geometries] (#125024)
created "divide by 0" situations when checking for clamp overlap geometry
in the bevel modifier. This PR eliminates this undefined behavior.

Original PR by Rob Blair. Modified by make format and added
a needed include.
This commit is contained in:
Rob Blair
2025-06-13 10:47:56 -04:00
committed by Howard Trickey
parent 6899c2dbfd
commit fc0b659066

View File

@@ -18,6 +18,7 @@
#include "BLI_alloca.h"
#include "BLI_math_base.h"
#include "BLI_math_base_safe.h"
#include "BLI_math_geom.h"
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
@@ -7551,7 +7552,8 @@ static float geometry_collide_offset(BevelParams *bp, EdgeHalf *eb)
* The intersection of these two corner vectors is the collapse point.
* The length of edge B divided by the projection of these vectors onto edge B
* is the number of 'offsets' that can be accommodated. */
float offsets_projected_on_B = (ka + cos1 * kb) / sin1 + (kc + cos2 * kb) / sin2;
float offsets_projected_on_B = safe_divide(ka + cos1 * kb, sin1) +
safe_divide(kc + cos2 * kb, sin2);
if (offsets_projected_on_B > BEVEL_EPSILON) {
offsets_projected_on_B = bp->offset * (len_v3v3(vb->co, vc->co) / offsets_projected_on_B);
if (offsets_projected_on_B > BEVEL_EPSILON) {