lottie/vector: change addPolystar* method to addPolystar/addPolygon 21/184921/1
authorYoungbok Shin <youngb.shin@samsung.com>
Tue, 24 Jul 2018 09:00:25 +0000 (18:00 +0900)
committerYoungbok Shin <youngb.shin@samsung.com>
Tue, 24 Jul 2018 09:00:25 +0000 (18:00 +0900)
It also move its implemented code to VPath::VPathData from VPath.

Change-Id: Idc6f04e04930f1863bb78fd1a05ba86c573e328b

example/pathtest.cpp
src/lottie/lottieitem.cpp
src/vector/vpath.cpp
src/vector/vpath.h

index 011d38f..8fa1e0a 100644 (file)
@@ -87,10 +87,8 @@ main(void)
 
    path.addOval(VRectF(300, 100, 100, 50), VPath::Direction::CCW);
 
-   path.addPolystarStar(0.0, 150, 150, 15.0,
-                        106.0, 34.0,
-                        231.0, 88.0, VPath::Direction::CW);
-
+   path.addPolystar(15.0, 106.0, 34.0, 0.0, 150,
+                    150, 231.0, 88.0, VPath::Direction::CW);
 
    PathTest test(APP);
    test.setPath(path);
index e037b6c..53cd79a 100644 (file)
@@ -946,14 +946,12 @@ VPath LOTPolystarItem::getPath(int frameNo)
    VMatrix m;
 
    if (mData->mType == LOTPolystarData::PolyType::Star) {
-        path.addPolystarStar(0.0, 0.0, 0.0, points,
-                             innerRadius, outerRadius,
-                             innerRoundness, outerRoundness,
-                             mData->direction());
+        path.addPolystar(points, innerRadius, outerRadius,
+                         innerRoundness, outerRoundness,
+                         0.0, 0.0, 0.0, mData->direction());
    } else {
-        path.addPolystarPolygon(0.0, 0.0, 0.0, points,
-                                outerRadius, outerRoundness,
-                                mData->direction());
+        path.addPolygon(points, outerRadius, outerRoundness,
+                        0.0, 0.0, 0.0, mData->direction());
    }
 
    m.translate(pos.x(), pos.y()).rotate(rotation);
index d8e2e13..639f2d0 100644 (file)
@@ -439,10 +439,9 @@ curvesForArc(const VRectF &rect, float startAngle, float sweepLength,
     return startPoint;
 }
 
-void VPath::addPolystarStar(float startAngle, float cx, float cy, float points,
-                             float innerRadius, float outerRadius,
-                             float innerRoundness, float outerRoundness,
-                             VPath::Direction dir)
+void VPath::VPathData::addPolystar(float points, float innerRadius, float outerRadius,
+                                   float innerRoundness, float outerRoundness,
+                                   float startAngle, float cx, float cy, VPath::Direction dir)
 {
    const static float POLYSTAR_MAGIC_NUMBER = 0.47829 / 0.28;
    float currentAngle = (startAngle - 90.0) * M_PI / 180.0;
@@ -476,9 +475,7 @@ void VPath::addPolystarStar(float startAngle, float cx, float cy, float points,
         currentAngle += halfAnglePerPoint * angleDir;
    }
 
-   VPathData &ref = d.write();
-
-   ref.moveTo(VPointF(x + cx, y + cy));
+   moveTo(VPointF(x + cx, y + cy));
 
    for (int i = 0; i < numPoints; i++) {
         float radius = longSegment ? outerRadius : innerRadius;
@@ -495,7 +492,7 @@ void VPath::addPolystarStar(float startAngle, float cx, float cy, float points,
         y = (float) (radius * sin(currentAngle));
 
         if (innerRoundness == 0 && outerRoundness == 0) {
-             ref.lineTo(VPointF(x + cx, y + cy));
+             lineTo(VPointF(x + cx, y + cy));
         } else {
              float cp1Theta = (float) (atan2(previousY, previousX) - M_PI / 2.0 * angleDir);
              float cp1Dx = (float) cos(cp1Theta);
@@ -522,9 +519,9 @@ void VPath::addPolystarStar(float startAngle, float cx, float cy, float points,
                   cp2y *= partialPointAmount;
              }
 
-             ref.cubicTo(VPointF(previousX - cp1x + cx, previousY - cp1y + cy),
-                         VPointF(x + cp2x + cx, y + cp2y + cy),
-                         VPointF(x + cx, y + cy));
+             cubicTo(VPointF(previousX - cp1x + cx, previousY - cp1y + cy),
+                     VPointF(x + cp2x + cx, y + cp2y + cy),
+                     VPointF(x + cx, y + cy));
         }
 
         currentAngle += dTheta * angleDir;
@@ -534,9 +531,8 @@ void VPath::addPolystarStar(float startAngle, float cx, float cy, float points,
    close();
 }
 
-void VPath::addPolystarPolygon(float startAngle, float cx, float cy, float points,
-                                float radius, float roundness,
-                                VPath::Direction dir)
+void VPath::VPathData::addPolygon(float points, float radius, float roundness,
+                                  float startAngle, float cx, float cy, VPath::Direction dir)
 {
    // TODO: Need to support floating point number for number of points
    const static float POLYGON_MAGIC_NUMBER = 0.25;
index 68acc52..5b15a94 100644 (file)
@@ -39,13 +39,11 @@ public:
     void addOval(const VRectF &rect, VPath::Direction dir = Direction::CW);
     void addRoundRect(const VRectF &rect, float rx, float ry, VPath::Direction dir = Direction::CW);
     void addRect(const VRectF &rect, VPath::Direction dir = Direction::CW);
-    void addPolystarStar(float startAngle, float cx, float cy, float points,
-                         float innerRadius, float outerRadius,
-                         float innerRoundness, float outerRoundness,
-                         VPath::Direction dir = Direction::CW);
-    void addPolystarPolygon(float startAngle, float cx, float cy, float points,
-                            float radius, float roundness,
-                            VPath::Direction dir = Direction::CW);
+    void addPolystar(float points, float innerRadius, float outerRadius,
+                     float innerRoundness, float outerRoundness,
+                     float startAngle, float cx, float cy, VPath::Direction dir = Direction::CW);
+    void addPolygon(float points, float radius, float roundness,
+                    float startAngle, float cx, float cy, VPath::Direction dir = Direction::CW);
     void transform(const VMatrix &m);
     const std::vector<VPath::Element> &elements() const;
     const std::vector<VPointF> &points() const;
@@ -68,6 +66,11 @@ private:
         void arcTo(const VRectF&, float, float, bool);
         void addCircle(float, float, float, VPath::Direction);
         void addOval(const VRectF &, VPath::Direction);
+        void addPolystar(float points, float innerRadius, float outerRadius,
+                         float innerRoundness, float outerRoundness,
+                         float startAngle, float cx, float cy, VPath::Direction dir = Direction::CW);
+        void addPolygon(float points, float radius, float roundness,
+                        float startAngle, float cx, float cy, VPath::Direction dir = Direction::CW);
         const std::vector<VPath::Element> &elements() const { return m_elements;}
         const std::vector<VPointF> &points() const {return m_points;}
         std::vector<VPointF>         m_points;
@@ -165,6 +168,22 @@ inline void VPath::addOval(const VRectF &rect, VPath::Direction dir)
     d.write().addOval(rect, dir);
 }
 
+inline void VPath::addPolystar(float points, float innerRadius, float outerRadius,
+                               float innerRoundness, float outerRoundness,
+                               float startAngle, float cx, float cy, VPath::Direction dir)
+{
+    d.write().addPolystar(points, innerRadius, outerRadius,
+                          innerRoundness, outerRoundness,
+                          startAngle, cx, cy, dir);
+}
+
+inline void VPath::addPolygon(float points, float radius, float roundness,
+                              float startAngle, float cx, float cy, VPath::Direction dir)
+{
+    d.write().addPolygon(points, radius, roundness,
+                         startAngle, cx, cy, dir);
+}
+
 inline const std::vector<VPath::Element> &VPath::elements() const
 {
     return d->elements();