From fe211418e622b3bf81fcd60d7cdfd4c0abd1ae85 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Thu, 15 Nov 2018 11:36:58 +0900 Subject: [PATCH] lottie/vector: add angle api to VLine class Change-Id: Iaa839e5a4e7a0517c7a9a01cb8e0de972dba95c6 --- src/vector/vline.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/vector/vline.h b/src/vector/vline.h index 5ac6eb3..bd959c3 100644 --- a/src/vector/vline.h +++ b/src/vector/vline.h @@ -21,7 +21,7 @@ public: void splitAtLength(float length, VLine &left, VLine &right) const; VPointF p1() const { return {mX1, mY1}; } VPointF p2() const { return {mX2, mY2}; } - + float angle() const; static float length(float x1, float y1, float x2, float y2); private: @@ -31,6 +31,15 @@ private: float mY2{0}; }; +inline float VLine::angle() const +{ + const float dx = mX2 - mX1; + const float dy = mY2 - mY1; + + const float theta = std::atan2(dy, dx) * 180.0 / M_PI; + return theta; +} + // 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 // than 7% compared to the exact value. @@ -62,4 +71,4 @@ inline void VLine::splitAtLength(float lengthAt, VLine &left, VLine &right) cons right.mY2 = mY2; } -#endif //VLINE_H \ No newline at end of file +#endif //VLINE_H -- 2.34.1