From: Jaeun Choi Date: Fri, 27 Jul 2018 08:04:49 +0000 (+0900) Subject: vector: add length() function in vpath X-Git-Tag: submit/tizen/20180917.042405~179 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86d179f9b14a30e755d5234a7cf13c4115da6ba7;p=platform%2Fcore%2Fuifw%2Flottie-player.git vector: add length() function in vpath Change-Id: I94e2a3d7a1441f250ca722f53de018efce191c74 --- diff --git a/src/vector/vpath.cpp b/src/vector/vpath.cpp index cfe64ee..1724f8f 100644 --- a/src/vector/vpath.cpp +++ b/src/vector/vpath.cpp @@ -26,6 +26,41 @@ void VPath::VPathData::transform(const VMatrix &m) } } +float VPath::VPathData::length() const +{ + float len = 0.0; + int i = 0; + for (auto e : m_elements) { + switch (e) { + case VPath::Element::MoveTo: + i++; + break; + case VPath::Element::LineTo: + { + VPointF p0 = m_points[i - 1]; + VPointF p = m_points[i++]; + VBezier b = VBezier::fromPoints(p0, p0, p, p); + len += b.length(); + break; + } + case VPath::Element::CubicTo: + { + VPointF p0 = m_points[i - 1]; + VPointF p = m_points[i++]; + VPointF p1 = m_points[i++]; + VPointF p2 = m_points[i++]; + VBezier b = VBezier::fromPoints(p0, p, p1, p2); + len += b.length(); + break; + } + case VPath::Element::Close: + break; + } + } + + return len; +} + void VPath::VPathData::checkNewSegment() { if (mNewSegment) { diff --git a/src/vector/vpath.h b/src/vector/vpath.h index 14a29bd..2782861 100644 --- a/src/vector/vpath.h +++ b/src/vector/vpath.h @@ -45,6 +45,7 @@ public: void addPolygon(float points, float radius, float roundness, float startAngle, float cx, float cy, VPath::Direction dir = Direction::CW); void transform(const VMatrix &m); + float length() const; const std::vector &elements() const; const std::vector &points() const; private: @@ -61,6 +62,7 @@ private: void checkNewSegment(); int segments() const; void transform(const VMatrix &m); + float length() const; void addRoundRect(const VRectF &, float, float, VPath::Direction); void addRect(const VRectF &, VPath::Direction); void arcTo(const VRectF&, float, float, bool); @@ -118,6 +120,12 @@ inline int VPath::segments() const return d->segments(); } +inline float VPath::length() const +{ + //TODO re-calculate when there is a change + return d->length(); +} + inline void VPath::cubicTo(const VPointF &c1, const VPointF &c2, const VPointF &e) { d.write().cubicTo(c1, c2, e);