diff options
Diffstat (limited to 'thirdparty/thorvg/src/common')
-rw-r--r-- | thirdparty/thorvg/src/common/tvgArray.h | 1 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgCompressor.cpp | 4 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgLines.cpp (renamed from thirdparty/thorvg/src/common/tvgBezier.cpp) | 25 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgLines.h (renamed from thirdparty/thorvg/src/common/tvgBezier.h) | 16 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgMath.h | 12 | ||||
-rw-r--r-- | thirdparty/thorvg/src/common/tvgStr.cpp | 3 |
6 files changed, 53 insertions, 8 deletions
diff --git a/thirdparty/thorvg/src/common/tvgArray.h b/thirdparty/thorvg/src/common/tvgArray.h index d95df40460..8178bd0e42 100644 --- a/thirdparty/thorvg/src/common/tvgArray.h +++ b/thirdparty/thorvg/src/common/tvgArray.h @@ -61,6 +61,7 @@ struct Array void push(Array<T>& rhs) { + if (rhs.count == 0) return; grow(rhs.count); memcpy(data + count, rhs.data, rhs.count * sizeof(T)); count += rhs.count; diff --git a/thirdparty/thorvg/src/common/tvgCompressor.cpp b/thirdparty/thorvg/src/common/tvgCompressor.cpp index 778fc4d0a2..9a1dc54632 100644 --- a/thirdparty/thorvg/src/common/tvgCompressor.cpp +++ b/thirdparty/thorvg/src/common/tvgCompressor.cpp @@ -458,11 +458,11 @@ size_t b64Decode(const char* encoded, const size_t len, char** decoded) auto value2 = B64_INDEX[(size_t)encoded[1]]; output[idx++] = (value1 << 2) + ((value2 & 0x30) >> 4); - if (!encoded[2] || encoded[2] == '=' || encoded[2] == '.') break; + if (!encoded[2] || encoded[3] < 0 || encoded[2] == '=' || encoded[2] == '.') break; auto value3 = B64_INDEX[(size_t)encoded[2]]; output[idx++] = ((value2 & 0x0f) << 4) + ((value3 & 0x3c) >> 2); - if (!encoded[3] || encoded[3] == '=' || encoded[3] == '.') break; + if (!encoded[3] || encoded[3] < 0 || encoded[3] == '=' || encoded[3] == '.') break; auto value4 = B64_INDEX[(size_t)encoded[3]]; output[idx++] = ((value3 & 0x03) << 6) + value4; encoded += 4; diff --git a/thirdparty/thorvg/src/common/tvgBezier.cpp b/thirdparty/thorvg/src/common/tvgLines.cpp index 8c19afa32a..da48f9eae2 100644 --- a/thirdparty/thorvg/src/common/tvgBezier.cpp +++ b/thirdparty/thorvg/src/common/tvgLines.cpp @@ -21,9 +21,9 @@ */ #include "tvgMath.h" -#include "tvgBezier.h" +#include "tvgLines.h" -#define BEZIER_EPSILON 1e-4f +#define BEZIER_EPSILON 1e-2f /************************************************************************/ /* Internal Class Implementation */ @@ -101,6 +101,25 @@ float _bezAt(const Bezier& bz, float at, float length, LengthFunc lineLengthFunc namespace tvg { +float lineLength(const Point& pt1, const Point& pt2) +{ + return _lineLength(pt1, pt2); +} + + +void lineSplitAt(const Line& cur, float at, Line& left, Line& right) +{ + auto len = lineLength(cur.pt1, cur.pt2); + auto dx = ((cur.pt2.x - cur.pt1.x) / len) * at; + auto dy = ((cur.pt2.y - cur.pt1.y) / len) * at; + left.pt1 = cur.pt1; + left.pt2.x = left.pt1.x + dx; + left.pt2.y = left.pt1.y + dy; + right.pt1 = left.pt2; + right.pt2 = cur.pt2; +} + + void bezSplit(const Bezier& cur, Bezier& left, Bezier& right) { auto c = (cur.ctrl1.x + cur.ctrl2.x) * 0.5f; @@ -219,7 +238,7 @@ float bezAngleAt(const Bezier& bz, float t) pt.x *= 3; pt.y *= 3; - return atan2(pt.x, pt.y) * 180.0f / 3.141592f; + return mathRad2Deg(atan2(pt.x, pt.y)); } diff --git a/thirdparty/thorvg/src/common/tvgBezier.h b/thirdparty/thorvg/src/common/tvgLines.h index 80a199258a..d900782b56 100644 --- a/thirdparty/thorvg/src/common/tvgBezier.h +++ b/thirdparty/thorvg/src/common/tvgLines.h @@ -20,14 +20,24 @@ * SOFTWARE. */ -#ifndef _TVG_BEZIER_H_ -#define _TVG_BEZIER_H_ +#ifndef _TVG_LINES_H_ +#define _TVG_LINES_H_ #include "tvgCommon.h" namespace tvg { +struct Line +{ + Point pt1; + Point pt2; +}; + +float lineLength(const Point& pt1, const Point& pt2); +void lineSplitAt(const Line& cur, float at, Line& left, Line& right); + + struct Bezier { Point start; @@ -48,4 +58,4 @@ float bezLengthApprox(const Bezier& cur); float bezAtApprox(const Bezier& bz, float at, float length); } -#endif //_TVG_BEZIER_H_ +#endif //_TVG_LINES_H_ diff --git a/thirdparty/thorvg/src/common/tvgMath.h b/thirdparty/thorvg/src/common/tvgMath.h index 32f4e6b7d1..60ea1d21b0 100644 --- a/thirdparty/thorvg/src/common/tvgMath.h +++ b/thirdparty/thorvg/src/common/tvgMath.h @@ -44,6 +44,18 @@ bool mathIdentity(const Matrix* m); void mathMultiply(Point* pt, const Matrix* transform); +static inline float mathDeg2Rad(float degree) +{ + return degree * (MATH_PI / 180.0f); +} + + +static inline float mathRad2Deg(float radian) +{ + return radian * (180.0f / MATH_PI); +} + + static inline bool mathZero(float a) { return (fabsf(a) < FLT_EPSILON) ? true : false; diff --git a/thirdparty/thorvg/src/common/tvgStr.cpp b/thirdparty/thorvg/src/common/tvgStr.cpp index 311b986511..1336f2447c 100644 --- a/thirdparty/thorvg/src/common/tvgStr.cpp +++ b/thirdparty/thorvg/src/common/tvgStr.cpp @@ -21,6 +21,7 @@ */ #include "config.h" +#include <cmath> #include <cstring> #include <memory.h> #include "tvgMath.h" @@ -197,6 +198,8 @@ float strToFloat(const char *nPtr, char **endPtr) success: if (endPtr) *endPtr = (char *)(a); + if (!std::isfinite(val)) return 0.0f; + return minus * val; error: |