diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-09-26 07:52:21 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-09-26 07:52:21 +0300 |
commit | 24b083c8f3c004619d5e350132768cc9f865d909 (patch) | |
tree | d4b6bd946385a81f9692c737d298dfc3ef5a98b4 /source/blender/blenlib | |
parent | 3ae0be45f1b14a32ae85acdec92744af4d05a4a0 (diff) | |
parent | aba2f8ea67d8c886bbe29f47e44d9e6838e32f25 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/polyfill2d_beautify.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/source/blender/blenlib/intern/polyfill2d_beautify.c b/source/blender/blenlib/intern/polyfill2d_beautify.c index c727a2a9c45..5f6fb8e6cd4 100644 --- a/source/blender/blenlib/intern/polyfill2d_beautify.c +++ b/source/blender/blenlib/intern/polyfill2d_beautify.c @@ -133,39 +133,40 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex( { /* not a loop (only to be able to break out) */ do { - bool is_zero_a, is_zero_b; + /* Allow very small faces to be considered non-zero. */ + const float eps_zero_area = 1e-12f; + const float area_2x_234 = cross_tri_v2(v2, v3, v4); + const float area_2x_241 = cross_tri_v2(v2, v4, v1); const float area_2x_123 = cross_tri_v2(v1, v2, v3); const float area_2x_134 = cross_tri_v2(v1, v3, v4); - is_zero_a = (fabsf(area_2x_123) <= FLT_EPSILON); - is_zero_b = (fabsf(area_2x_134) <= FLT_EPSILON); - - if (lock_degenerate && is_zero_a && is_zero_b) { - break; - } - - const float area_2x_234 = cross_tri_v2(v2, v3, v4); - const float area_2x_241 = cross_tri_v2(v2, v4, v1); - BLI_assert((ELEM(v1, v2, v3, v4) == false) && (ELEM(v2, v1, v3, v4) == false) && (ELEM(v3, v1, v2, v4) == false) && (ELEM(v4, v1, v2, v3) == false)); - /* * Test for unusable (1-3) state. * - Area sign flipping to check faces aren't going to point in opposite directions. * - Area epsilon check that the one of the faces won't be zero area. */ - if (is_zero_a || is_zero_b || ((area_2x_123 >= 0.0f) != (area_2x_134 >= 0.0f))) { + if ((area_2x_123 >= 0.0f) != (area_2x_134 >= 0.0f)) { + break; + } + else if ((fabsf(area_2x_123) <= eps_zero_area) || (fabsf(area_2x_134) <= eps_zero_area)) { break; } /* Test for unusable (2-4) state (same as above). */ - if (((area_2x_234 >= 0.0f) != (area_2x_241 >= 0.0f)) || - ((fabsf(area_2x_234) <= FLT_EPSILON) || (fabsf(area_2x_241) <= FLT_EPSILON))) - { + if ((area_2x_234 >= 0.0f) != (area_2x_241 >= 0.0f)) { + if (lock_degenerate) { + break; + } + else { + return -FLT_MAX; /* always rotate */ + } + } + else if ((fabsf(area_2x_234) <= eps_zero_area) || (fabsf(area_2x_241) <= eps_zero_area)) { return -FLT_MAX; /* always rotate */ } |