From d0a08aadc86861f230342e8b4a3763c6adb89caa Mon Sep 17 00:00:00 2001 From: Youngbok Shin Date: Tue, 24 Jul 2018 18:00:25 +0900 Subject: [PATCH] lottie/vector: change addPolystar* method to addPolystar/addPolygon It also move its implemented code to VPath::VPathData from VPath. Change-Id: Idc6f04e04930f1863bb78fd1a05ba86c573e328b --- example/pathtest.cpp | 6 ++---- src/lottie/lottieitem.cpp | 12 +++++------- src/vector/vpath.cpp | 24 ++++++++++-------------- src/vector/vpath.h | 33 ++++++++++++++++++++++++++------- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/example/pathtest.cpp b/example/pathtest.cpp index 011d38f..8fa1e0a 100644 --- a/example/pathtest.cpp +++ b/example/pathtest.cpp @@ -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); diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index e037b6c..53cd79a 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -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); diff --git a/src/vector/vpath.cpp b/src/vector/vpath.cpp index d8e2e13..639f2d0 100644 --- a/src/vector/vpath.cpp +++ b/src/vector/vpath.cpp @@ -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; diff --git a/src/vector/vpath.h b/src/vector/vpath.h index 68acc52..5b15a94 100644 --- a/src/vector/vpath.h +++ b/src/vector/vpath.h @@ -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 &elements() const; const std::vector &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 &elements() const { return m_elements;} const std::vector &points() const {return m_points;} std::vector 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::elements() const { return d->elements(); -- 2.7.4