Skip to content

Commit

Permalink
Stop computing Bézier curve length when float overflow occurs after s…
Browse files Browse the repository at this point in the history
…plitting
  • Loading branch information
mymedia2 committed Feb 26, 2022
1 parent 19fc8e9 commit f7b72f1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/vector/vbezier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ float VBezier::length() const
if ((len - chord) > 0.01) {
VBezier left, right;
split(&left, &right);
return left.length() + right.length();

float sum = 0;
if (*this != left)
sum += left.length();
if (*this != right)
sum += right.length();
return sum;
}

return len;
Expand Down
13 changes: 13 additions & 0 deletions src/vector/vbezier.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
#ifndef VBEZIER_H
#define VBEZIER_H

#include <tuple>
#include <vpoint.h>

V_BEGIN_NAMESPACE

class VBezier {
friend bool operator == (const VBezier &l, const VBezier &r);

public:
VBezier() = default;
VPointF pointAt(float t) const;
Expand Down Expand Up @@ -134,6 +137,16 @@ inline void VBezier::split(VBezier *firstHalf, VBezier *secondHalf) const
firstHalf->y4 = secondHalf->y1 = (firstHalf->y3 + secondHalf->y2) * 0.5f;
}

inline bool operator == (const VBezier &l, const VBezier &r)
{
return std::tie(l.x1, l.y1, l.x2, l.y2, l.x3, l.y3, l.x4, l.y4)
== std::tie(r.x1, r.y1, r.x2, r.y2, r.x3, r.y3, r.x4, r.y4);
}
inline bool operator != (const VBezier &l, const VBezier &r)
{
return !(l == r);
}

V_END_NAMESPACE

#endif // VBEZIER_H

0 comments on commit f7b72f1

Please sign in to comment.