lottie/vector : added addPath() api to vpath. 11/187411/1
authorsubhransu mohanty <sub.mohanty@samsung.com>
Thu, 23 Aug 2018 04:10:06 +0000 (13:10 +0900)
committersubhransu mohanty <sub.mohanty@samsung.com>
Thu, 23 Aug 2018 04:15:49 +0000 (13:15 +0900)
Change-Id: I3fd7ee9ba8add8f7109c23c0b6e62388b3fda5bf

src/vector/vpath.cpp
src/vector/vpath.h

index 085094c..7089d2b 100644 (file)
@@ -667,4 +667,21 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
     close();
 }
 
+void VPath::VPathData::addPath(const VPathData &path)
+{
+    int segment = path.segments();
+
+    // make sure enough memory available
+    if (m_points.capacity() < m_points.size() + path.m_points.size())
+        m_points.reserve(m_points.size() + path.m_points.size());
+
+    if (m_elements.capacity() < m_elements.size() + path.m_elements.size())
+        m_elements.reserve(m_elements.size() + path.m_elements.size());
+
+    std::copy(path.m_points.begin(), path.m_points.end(), back_inserter(m_points));
+    std::copy(path.m_elements.begin(), path.m_elements.end(), back_inserter(m_elements));
+
+    m_segments += segment;
+}
+
 V_END_NAMESPACE
index ff5583a..8845b41 100644 (file)
@@ -41,6 +41,7 @@ public:
     void  addPolygon(float points, float radius, float roundness,
                      float startAngle, float cx, float cy,
                      VPath::Direction dir = Direction::CW);
+    void addPath(const VPath &path);
     void  transform(const VMatrix &m);
     float length() const;
     const std::vector<VPath::Element> &elements() const;
@@ -74,6 +75,7 @@ private:
         void  addPolygon(float points, float radius, float roundness,
                          float startAngle, float cx, float cy,
                          VPath::Direction dir = Direction::CW);
+        void  addPath(const VPathData &path);
         const std::vector<VPath::Element> &elements() const
         {
             return m_elements;
@@ -201,6 +203,17 @@ inline void VPath::addPolygon(float points, float radius, float roundness,
     d.write().addPolygon(points, radius, roundness, startAngle, cx, cy, dir);
 }
 
+inline void VPath::addPath(const VPath &path)
+{
+    if (path.isEmpty()) return;
+
+    if (isEmpty()) {
+        *this = path;
+    } else {
+        d.write().addPath(path.d.read());
+    }
+}
+
 inline const std::vector<VPath::Element> &VPath::elements() const
 {
     return d->elements();