lottie/vector: add angle api to VLine class 22/193122/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 15 Nov 2018 02:36:58 +0000 (11:36 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Thu, 15 Nov 2018 02:36:58 +0000 (11:36 +0900)
Change-Id: Iaa839e5a4e7a0517c7a9a01cb8e0de972dba95c6

src/vector/vline.h

index 5ac6eb3..bd959c3 100644 (file)
@@ -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