Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2013-12-26 05:21:40 +0400
committerCampbell Barton <ideasman42@gmail.com>2013-12-26 05:21:40 +0400
commitdb8293d4561791b4ddb349fa3ce37803afe509ee (patch)
tree8e478ce7ace82eb7862bf6a5bb178884d15d6c38
parentaf32c1c77bbba31172354ed8c3d425bb81b31893 (diff)
Polyfill: minor changes to which fix rare errors with float precision
-rw-r--r--source/blender/blenlib/intern/polyfill2d.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/polyfill2d.c b/source/blender/blenlib/intern/polyfill2d.c
index 56cd385e76b..f5a226cebb6 100644
--- a/source/blender/blenlib/intern/polyfill2d.c
+++ b/source/blender/blenlib/intern/polyfill2d.c
@@ -50,8 +50,6 @@
#include "BLI_strict_flags.h"
-#define SIGN_EPS 0.000001f
-
/* avoid fan-fill topology */
#define USE_CLIP_EVEN
#define USE_CONVEX_SKIP
@@ -97,7 +95,7 @@ static void pf_ear_tip_cut(PolyFill *pf, unsigned int index_ear_tip);
BLI_INLINE eSign signum_i(float a)
{
- if (UNLIKELY(fabsf(a) < SIGN_EPS))
+ if (UNLIKELY(a == 0.0f))
return 0;
else if (a > 0.0f)
return 1;
@@ -105,9 +103,23 @@ BLI_INLINE eSign signum_i(float a)
return -1;
}
+/**
+ * alternative version of #area_tri_signed_v2
+ * needed because of float precision issues
+ *
+ * \note removes / 2 since its not needed since we only need ths sign.
+ */
+BLI_INLINE float area_tri_signed_v2_alt_2x(const float v1[2], const float v2[2], const float v3[2])
+{
+ return ((v1[0] * (v2[1] - v3[1])) +
+ (v2[0] * (v3[1] - v1[1])) +
+ (v3[0] * (v1[1] - v2[1])));
+}
+
+
static eSign span_tri_v2_sign(const float v1[2], const float v2[2], const float v3[2])
{
- return signum_i(area_tri_signed_v2(v3, v2, v1));
+ return signum_i(area_tri_signed_v2_alt_2x(v3, v2, v1));
}
static unsigned int *pf_tri_add(PolyFill *pf)