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:
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/intern/math_geom.c20
-rw-r--r--source/blender/blenlib/intern/polyfill2d.c26
-rw-r--r--source/blender/blenlib/intern/string.c4
3 files changed, 23 insertions, 27 deletions
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 11875722d27..1d03bf42f83 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -721,24 +721,16 @@ bool isect_point_poly_v2(const float pt[2], const float verts[][2], const unsign
/* first vector */
fp1[0] = (float)(p1[0] - pt[0]);
fp1[1] = (float)(p1[1] - pt[1]);
- normalize_v2(fp1);
for (i = 0; i < nr; i++) {
- float dot, ang, cross;
p2 = verts[i];
/* second vector */
fp2[0] = (float)(p2[0] - pt[0]);
fp2[1] = (float)(p2[1] - pt[1]);
- normalize_v2(fp2);
/* dot and angle and cross */
- dot = dot_v2v2(fp1, fp2);
- ang = fabsf(saacos(dot));
- cross = (float)((p1[1] - p2[1]) * (p1[0] - pt[0]) + (p2[0] - p1[0]) * (p1[1] - pt[1]));
-
- if (cross < 0.0f) angletot -= ang;
- else angletot += ang;
+ angletot += angle_signed_v2v2(fp1, fp2);
/* circulate */
copy_v2_v2(fp1, fp2);
@@ -769,24 +761,16 @@ bool isect_point_poly_v2_int(const int pt[2], const int verts[][2], const unsign
/* first vector */
fp1[0] = (float)(p1[0] - pt[0]);
fp1[1] = (float)(p1[1] - pt[1]);
- normalize_v2(fp1);
for (i = 0; i < nr; i++) {
- float dot, ang, cross;
p2 = verts[i];
/* second vector */
fp2[0] = (float)(p2[0] - pt[0]);
fp2[1] = (float)(p2[1] - pt[1]);
- normalize_v2(fp2);
/* dot and angle and cross */
- dot = dot_v2v2(fp1, fp2);
- ang = fabsf(saacos(dot));
- cross = (float)((p1[1] - p2[1]) * (p1[0] - pt[0]) + (p2[0] - p1[0]) * (p1[1] - pt[1]));
-
- if (cross < 0.0f) angletot -= ang;
- else angletot += ang;
+ angletot += angle_signed_v2v2(fp1, fp2);
/* circulate */
copy_v2_v2(fp1, fp2);
diff --git a/source/blender/blenlib/intern/polyfill2d.c b/source/blender/blenlib/intern/polyfill2d.c
index 287a0909870..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)
@@ -316,9 +328,9 @@ static bool pf_ear_tip_check(PolyFill *pf, const unsigned int index_ear_tip)
/* Because the polygon has clockwise winding order,
* the area sign will be positive if the point is strictly inside.
* It will be 0 on the edge, which we want to include as well. */
- if ((span_tri_v2_sign(v1, v2, v) == CONVEX) &&
- (span_tri_v2_sign(v2, v3, v) == CONVEX) &&
- (span_tri_v2_sign(v3, v1, v) == CONVEX))
+ if ((span_tri_v2_sign(v1, v2, v) != CONCAVE) &&
+ (span_tri_v2_sign(v2, v3, v) != CONCAVE) &&
+ (span_tri_v2_sign(v3, v1, v) != CONCAVE))
{
return false;
}
diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c
index 572b142d044..0ce40f717d4 100644
--- a/source/blender/blenlib/intern/string.c
+++ b/source/blender/blenlib/intern/string.c
@@ -582,7 +582,7 @@ void BLI_ascii_strtolower(char *str, const size_t len)
{
size_t i;
- for (i = 0; i < len; i++)
+ for (i = 0; (i < len) && str[i]; i++)
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 'a' - 'A';
}
@@ -591,7 +591,7 @@ void BLI_ascii_strtoupper(char *str, const size_t len)
{
size_t i;
- for (i = 0; i < len; i++)
+ for (i = 0; (i < len) && str[i]; i++)
if (str[i] >= 'a' && str[i] <= 'z')
str[i] -= 'a' - 'A';
}