From 43d77af0d175f0fff8854ce1fd0a608c3504c372 Mon Sep 17 00:00:00 2001 From: subhransu mohanty Date: Thu, 23 Aug 2018 13:10:06 +0900 Subject: [PATCH] lottie/vector : added addPath() api to vpath. Change-Id: I3fd7ee9ba8add8f7109c23c0b6e62388b3fda5bf --- src/vector/vpath.cpp | 17 +++++++++++++++++ src/vector/vpath.h | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/vector/vpath.cpp b/src/vector/vpath.cpp index 085094c..7089d2b 100644 --- a/src/vector/vpath.cpp +++ b/src/vector/vpath.cpp @@ -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 diff --git a/src/vector/vpath.h b/src/vector/vpath.h index ff5583a..8845b41 100644 --- a/src/vector/vpath.h +++ b/src/vector/vpath.h @@ -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 &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 &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::elements() const { return d->elements(); -- 2.7.4