mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-14 12:04:29 +00:00
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:
parent
389b028be4
commit
380450c95b
2 changed files with 6 additions and 4 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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_
|
||||
|
|
Loading…
Add table
Reference in a new issue