From 3cf0c93be1ac52e94e772458c6d357882dc7a779 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 14 Feb 2013 09:17:50 +0000 Subject: modify own changes to is_quad_convex_v3() to allow quads with a co-linear side to be considered convex (as it did in last release). this is needed so zero area faces be dealt with by beauty fill. --- source/blender/blenlib/intern/math_geom.c | 49 +++++++++++++++++++------------ 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'source/blender/blenlib/intern/math_geom.c') diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 618c237c8ba..1e1d97a35a4 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -3578,29 +3578,42 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl /* evaluate if entire quad is a proper convex quad */ int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]) { - float nor[3], nor1[3], nor2[3], vec[4][2]; + float nor[3], nor_a[3], nor_b[3], vec[4][2]; float mat[3][3]; + const bool is_ok_a = (normal_tri_v3(nor_a, v1, v2, v3) > FLT_EPSILON); + const bool is_ok_b = (normal_tri_v3(nor_b, v1, v3, v4) > FLT_EPSILON); /* define projection, do both trias apart, quad is undefined! */ /* check normal length incase one size is zero area */ - if (UNLIKELY((normal_tri_v3(nor1, v1, v2, v3) <= FLT_EPSILON) || - (normal_tri_v3(nor2, v1, v3, v4) <= FLT_EPSILON))) - { - return false; - } + if (is_ok_a) { + if (is_ok_b) { + /* use both, most common outcome */ + + /* when the face is folded over as 2 tris we probably don't want to create + * a quad from it, but go ahead with the intersection test since this + * isn't a function for degenerate faces */ + if (UNLIKELY(dot_v3v3(nor_a, nor_b) < 0.0f)) { + /* flip so adding normals in the opposite direction + * doesn't give a zero length vector */ + negate_v3(nor_b); + } - /* when the face is folded over as 2 tris we probably don't want to create - * a quad from it, but go ahead with the intersection test since this - * isn't a function for degenerate faces */ - if (UNLIKELY(dot_v3v3(nor1, nor2) < 0.0f)) { - /* flip so adding normals in the opposite direction - * doesnt give a zero length vector */ - negate_v3(nor2); + add_v3_v3v3(nor, nor_a, nor_b); + normalize_v3(nor); + } + else { + copy_v3_v3(nor, nor_a); /* only 'a' */ + } + } + else { + if (is_ok_b) { + copy_v3_v3(nor, nor_b); /* only 'b' */ + } + else { + return false; /* both zero, we can't do anything useful here */ + } } - - add_v3_v3v3(nor, nor1, nor2); - normalize_v3(nor); axis_dominant_v3_to_m3(mat, nor); @@ -3610,12 +3623,12 @@ int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], c mul_v2_m3v3(vec[3], mat, v4); /* linetests, the 2 diagonals have to instersect to be convex */ - return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) == ISECT_LINE_LINE_CROSS); + return (isect_line_line_v2(vec[0], vec[2], vec[1], vec[3]) > 0); } int is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], const float v4[2]) { /* linetests, the 2 diagonals have to instersect to be convex */ - return (isect_line_line_v2(v1, v3, v2, v4) == ISECT_LINE_LINE_CROSS); + return (isect_line_line_v2(v1, v3, v2, v4) > 0); } -- cgit v1.2.3