mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-15 12:34:30 +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 len = _lineLength(cur.start, cur.ctrl1) + _lineLength(cur.ctrl1, cur.ctrl2) + _lineLength(cur.ctrl2, cur.end);
|
||||||
auto chord = _lineLength(cur.start, 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);
|
bezSplit(cur, left, right);
|
||||||
return bezLength(left) + bezLength(right);
|
return bezLength(left) + bezLength(right);
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ float bezAt(const Bezier& bz, float at)
|
||||||
bezSplitLeft(right, t, left);
|
bezSplitLeft(right, t, left);
|
||||||
len = bezLength(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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@
|
||||||
namespace tvg
|
namespace tvg
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#define BEZIER_EPSILON 1e-4f
|
||||||
|
|
||||||
struct Bezier
|
struct Bezier
|
||||||
{
|
{
|
||||||
Point start;
|
Point start;
|
||||||
|
|
Loading…
Add table
Reference in a new issue