summaryrefslogtreecommitdiffstats
path: root/thirdparty/thorvg/src/common
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-03-09 23:58:59 +0100
committerRémi Verschelde <rverschelde@gmail.com>2024-03-09 23:58:59 +0100
commit6fa77e0f1442328a969c9ad0651047fae34f72a3 (patch)
treeadbcdca713d10d162423970a36a3ea6e57298789 /thirdparty/thorvg/src/common
parent0ace0a129284ffc6646b199699c1607a316fcec0 (diff)
downloadredot-engine-6fa77e0f1442328a969c9ad0651047fae34f72a3.tar.gz
thorvg: Update to 0.12.7
Diffstat (limited to 'thirdparty/thorvg/src/common')
-rw-r--r--thirdparty/thorvg/src/common/tvgArray.h10
-rw-r--r--thirdparty/thorvg/src/common/tvgBezier.cpp99
-rw-r--r--thirdparty/thorvg/src/common/tvgBezier.h2
-rw-r--r--thirdparty/thorvg/src/common/tvgLock.h1
-rw-r--r--thirdparty/thorvg/src/common/tvgMath.h1
5 files changed, 80 insertions, 33 deletions
diff --git a/thirdparty/thorvg/src/common/tvgArray.h b/thirdparty/thorvg/src/common/tvgArray.h
index acb3a41b97..d95df40460 100644
--- a/thirdparty/thorvg/src/common/tvgArray.h
+++ b/thirdparty/thorvg/src/common/tvgArray.h
@@ -90,6 +90,16 @@ struct Array
return data[idx];
}
+ const T* begin() const
+ {
+ return data;
+ }
+
+ T* begin()
+ {
+ return data;
+ }
+
T* end()
{
return data + count;
diff --git a/thirdparty/thorvg/src/common/tvgBezier.cpp b/thirdparty/thorvg/src/common/tvgBezier.cpp
index 5fb501721e..8c19afa32a 100644
--- a/thirdparty/thorvg/src/common/tvgBezier.cpp
+++ b/thirdparty/thorvg/src/common/tvgBezier.cpp
@@ -29,7 +29,7 @@
/* Internal Class Implementation */
/************************************************************************/
-static float _lineLength(const Point& pt1, const Point& pt2)
+static float _lineLengthApprox(const Point& pt1, const Point& pt2)
{
/* approximate sqrt(x*x + y*y) using alpha max plus beta min algorithm.
With alpha = 1, beta = 3/8, giving results with the largest error less
@@ -41,6 +41,59 @@ static float _lineLength(const Point& pt1, const Point& pt2)
}
+static float _lineLength(const Point& pt1, const Point& pt2)
+{
+ Point diff = {pt2.x - pt1.x, pt2.y - pt1.y};
+ return sqrtf(diff.x * diff.x + diff.y * diff.y);
+}
+
+
+template<typename LengthFunc>
+float _bezLength(const Bezier& cur, LengthFunc lineLengthFunc)
+{
+ Bezier left, right;
+ auto len = lineLengthFunc(cur.start, cur.ctrl1) + lineLengthFunc(cur.ctrl1, cur.ctrl2) + lineLengthFunc(cur.ctrl2, cur.end);
+ auto chord = lineLengthFunc(cur.start, cur.end);
+
+ if (fabsf(len - chord) > BEZIER_EPSILON) {
+ tvg::bezSplit(cur, left, right);
+ return _bezLength(left, lineLengthFunc) + _bezLength(right, lineLengthFunc);
+ }
+ return len;
+}
+
+
+template<typename LengthFunc>
+float _bezAt(const Bezier& bz, float at, float length, LengthFunc lineLengthFunc)
+{
+ auto biggest = 1.0f;
+ auto smallest = 0.0f;
+ auto t = 0.5f;
+
+ //just in case to prevent an infinite loop
+ if (at <= 0) return 0.0f;
+ if (at >= length) return 1.0f;
+
+ while (true) {
+ auto right = bz;
+ Bezier left;
+ bezSplitLeft(right, t, left);
+ length = _bezLength(left, lineLengthFunc);
+ if (fabsf(length - at) < BEZIER_EPSILON || fabsf(smallest - biggest) < BEZIER_EPSILON) {
+ break;
+ }
+ if (length < at) {
+ smallest = t;
+ t = (t + biggest) * 0.5f;
+ } else {
+ biggest = t;
+ t = (smallest + t) * 0.5f;
+ }
+ }
+ return t;
+}
+
+
/************************************************************************/
/* External Class Implementation */
/************************************************************************/
@@ -48,7 +101,7 @@ static float _lineLength(const Point& pt1, const Point& pt2)
namespace tvg
{
-void bezSplit(const Bezier&cur, Bezier& left, Bezier& right)
+void bezSplit(const Bezier& cur, Bezier& left, Bezier& right)
{
auto c = (cur.ctrl1.x + cur.ctrl2.x) * 0.5f;
left.ctrl1.x = (cur.start.x + cur.ctrl1.x) * 0.5f;
@@ -72,15 +125,13 @@ void bezSplit(const Bezier&cur, Bezier& left, Bezier& right)
float bezLength(const Bezier& cur)
{
- Bezier left, right;
- auto len = _lineLength(cur.start, cur.ctrl1) + _lineLength(cur.ctrl1, cur.ctrl2) + _lineLength(cur.ctrl2, cur.end);
- auto chord = _lineLength(cur.start, cur.end);
+ return _bezLength(cur, _lineLength);
+}
- if (fabsf(len - chord) > BEZIER_EPSILON) {
- bezSplit(cur, left, right);
- return bezLength(left) + bezLength(right);
- }
- return len;
+
+float bezLengthApprox(const Bezier& cur)
+{
+ return _bezLength(cur, _lineLengthApprox);
}
@@ -110,31 +161,13 @@ void bezSplitLeft(Bezier& cur, float at, Bezier& left)
float bezAt(const Bezier& bz, float at, float length)
{
- auto biggest = 1.0f;
- auto smallest = 0.0f;
- auto t = 0.5f;
+ return _bezAt(bz, at, length, _lineLength);
+}
- //just in case to prevent an infinite loop
- if (at <= 0) return 0.0f;
- if (at >= length) return 1.0f;
- while (true) {
- auto right = bz;
- Bezier left;
- bezSplitLeft(right, t, left);
- length = bezLength(left);
- if (fabsf(length - at) < BEZIER_EPSILON || fabsf(smallest - biggest) < BEZIER_EPSILON) {
- break;
- }
- if (length < at) {
- smallest = t;
- t = (t + biggest) * 0.5f;
- } else {
- biggest = t;
- t = (smallest + t) * 0.5f;
- }
- }
- return t;
+float bezAtApprox(const Bezier& bz, float at, float length)
+{
+ return _bezAt(bz, at, length, _lineLengthApprox);
}
diff --git a/thirdparty/thorvg/src/common/tvgBezier.h b/thirdparty/thorvg/src/common/tvgBezier.h
index cb2766c505..80a199258a 100644
--- a/thirdparty/thorvg/src/common/tvgBezier.h
+++ b/thirdparty/thorvg/src/common/tvgBezier.h
@@ -44,6 +44,8 @@ void bezSplitAt(const Bezier& cur, float at, Bezier& left, Bezier& right);
Point bezPointAt(const Bezier& bz, float t);
float bezAngleAt(const Bezier& bz, float t);
+float bezLengthApprox(const Bezier& cur);
+float bezAtApprox(const Bezier& bz, float at, float length);
}
#endif //_TVG_BEZIER_H_
diff --git a/thirdparty/thorvg/src/common/tvgLock.h b/thirdparty/thorvg/src/common/tvgLock.h
index 8bf1534605..5dd3d5a624 100644
--- a/thirdparty/thorvg/src/common/tvgLock.h
+++ b/thirdparty/thorvg/src/common/tvgLock.h
@@ -68,3 +68,4 @@ namespace tvg {
#endif //THORVG_THREAD_SUPPORT
#endif //_TVG_LOCK_H_
+
diff --git a/thirdparty/thorvg/src/common/tvgMath.h b/thirdparty/thorvg/src/common/tvgMath.h
index 50c3458efc..7f6708262b 100644
--- a/thirdparty/thorvg/src/common/tvgMath.h
+++ b/thirdparty/thorvg/src/common/tvgMath.h
@@ -31,6 +31,7 @@
#define MATH_PI 3.14159265358979323846f
#define MATH_PI2 1.57079632679489661923f
+#define PATH_KAPPA 0.552284f
#define mathMin(x, y) (((x) < (y)) ? (x) : (y))
#define mathMax(x, y) (((x) > (y)) ? (x) : (y))