vector/matrix: added scale() api in vmatrix
authorsub.mohanty@samsung.com <smohantty@gmail.com>
Sun, 25 Aug 2019 02:50:28 +0000 (11:50 +0900)
committerHermet Park <hermetpark@gmail.com>
Wed, 4 Sep 2019 08:28:02 +0000 (17:28 +0900)
Change-Id: Ide0ea9f1ae039fd9fd9a2a95cca8e45619254990

src/vector/vmatrix.h

index fe2f0ed..4d15f48 100644 (file)
@@ -58,9 +58,9 @@ public:
     float        m_ty() const { return mty;}
     float        m_33() const { return m33;}
 
-    VMatrix &translate(VPointF pos) { return translate(pos.x(), pos.y()); };
+    VMatrix &translate(VPointF pos) { return translate(pos.x(), pos.y()); }
     VMatrix &translate(float dx, float dy);
-    VMatrix &scale(VPointF s) { return scale(s.x(), s.y()); };
+    VMatrix &scale(VPointF s) { return scale(s.x(), s.y()); }
     VMatrix &scale(float sx, float sy);
     VMatrix &shear(float sh, float sv);
     VMatrix &rotate(float a, Axis axis = VMatrix::Axis::Z);
@@ -81,6 +81,7 @@ public:
     bool                 operator==(const VMatrix &) const;
     bool                 operator!=(const VMatrix &) const;
     bool                 fuzzyCompare(const VMatrix &) const;
+    float                scale() const;
 private:
     friend struct VSpanData;
     float              m11{1}, m12{0}, m13{0};
@@ -90,6 +91,18 @@ private:
     mutable MatrixType dirty{MatrixType::None};
 };
 
+inline float VMatrix::scale() const
+{
+    constexpr float SQRT_2 = 1.41421f;
+    VPointF         p1(0, 0);
+    VPointF         p2(SQRT_2, SQRT_2);
+    p1 = map(p1);
+    p2 = map(p2);
+    VPointF final = p2 - p1;
+
+    return std::sqrt(final.x() * final.x() + final.y() * final.y()) / 2.0f;
+}
+
 inline VPointF VMatrix::map(float x, float y) const
 {
     return map(VPointF(x, y));