Bezier curve: introducing BEZIER_EPSILON

BEZIER_EPSILON is used instead of EPSILON_FLT, because its
value was to small causing in some cases an infinite loop.
This commit is contained in:
Mira Grudzinska 2020-10-15 22:10:56 +02:00 committed by Hermet Park
parent 389b028be4
commit 380450c95b
2 changed files with 6 additions and 4 deletions

View file

@ -74,7 +74,7 @@ float bezLength(const Bezier& cur)
auto len = _lineLength(cur.start, cur.ctrl1) + _lineLength(cur.ctrl1, cur.ctrl2) + _lineLength(cur.ctrl2, cur.end);
auto chord = _lineLength(cur.start, cur.end);
if (fabs(len - chord) > FLT_EPSILON) {
if (fabs(len - chord) > BEZIER_EPSILON) {
bezSplit(cur, left, right);
return bezLength(left) + bezLength(right);
}
@ -124,7 +124,7 @@ float bezAt(const Bezier& bz, float at)
bezSplitLeft(right, t, left);
len = bezLength(left);
if (fabs(len - at) < FLT_EPSILON || fabs(smallest - biggest) < FLT_EPSILON) {
if (fabs(len - at) < BEZIER_EPSILON || fabs(smallest - biggest) < BEZIER_EPSILON) {
break;
}
@ -147,4 +147,4 @@ void bezSplitAt(const Bezier& cur, float at, Bezier& left, Bezier& right)
bezSplitLeft(right, t, left);
}
}
}

View file

@ -27,6 +27,8 @@
namespace tvg
{
#define BEZIER_EPSILON 1e-4f
struct Bezier
{
Point start;
@ -43,4 +45,4 @@ void bezSplitAt(const Bezier& cur, float at, Bezier& left, Bezier& right);
}
#endif //_TVG_BEZIER_H_
#endif //_TVG_BEZIER_H_