rlottie: Fix clang-tidy warning
authorsubhransu mohanty <sub.mohanty@samsung.com>
Mon, 24 Jun 2019 05:44:02 +0000 (14:44 +0900)
committerHermet Park <hermetpark@gmail.com>
Tue, 25 Jun 2019 11:59:00 +0000 (20:59 +0900)
14 files changed:
inc/rlottie.h
src/lottie/lottieitem.cpp
src/lottie/lottieitem.h
src/vector/vdasher.cpp
src/vector/vdasher.h
src/vector/vdrawhelper.cpp
src/vector/vdrawhelper.h
src/vector/vmatrix.h
src/vector/vpath.cpp
src/vector/vpath.h
src/vector/vraster.cpp
src/vector/vrect.h
src/vector/vrle.cpp
src/vector/vrle.h

index 765698eb5685ae425232e304d4673a9113158877..74def69ebc3c984f1410c370e5cc1066a8bbbc55 100644 (file)
@@ -84,7 +84,7 @@ private:
 };
 
 struct FrameInfo {
-    FrameInfo(uint32_t frame): _frameNo(frame){}
+    explicit FrameInfo(uint32_t frame): _frameNo(frame){}
     uint32_t curFrame() const {return _frameNo;}
 private:
     uint32_t _frameNo;
index 10a337ce9a4ba8a610683bcbc3bdf4e36eea30cd..a687d76c64cb255f88cd6eeef3390365c3603d1a 100644 (file)
@@ -1525,14 +1525,14 @@ void LOTTrimItem::addPathItems(std::vector<LOTPathDataItem *> &list, int startOf
 }
 
 
-LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mData(data)
+LOTRepeaterItem::LOTRepeaterItem(LOTRepeaterData *data) : mRepeaterData(data)
 {
-    assert(mData->content());
+    assert(mRepeaterData->content());
 
-    mCopies = mData->maxCopies();
+    mCopies = mRepeaterData->maxCopies();
 
     for (int i= 0; i < mCopies; i++) {
-        auto content = std::make_unique<LOTContentGroupItem>(mData->content());
+        auto content = std::make_unique<LOTContentGroupItem>(mRepeaterData->content());
         content->setParent(this);
         mContents.push_back(std::move(content));
     }
@@ -1543,7 +1543,7 @@ void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix, float par
 
     DirtyFlag newFlag = flag;
 
-    float copies = mData->copies(frameNo);
+    float copies = mRepeaterData->copies(frameNo);
     int visibleCopies = int(copies);
 
     if (visibleCopies == 0) {
@@ -1553,11 +1553,11 @@ void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix, float par
         mHidden = false;
     }
 
-    if (!mData->isStatic()) newFlag |= DirtyFlagBit::Matrix;
+    if (!mRepeaterData->isStatic()) newFlag |= DirtyFlagBit::Matrix;
 
-    float offset = mData->offset(frameNo);
-    float startOpacity = mData->mTransform.startOpacity(frameNo);
-    float endOpacity = mData->mTransform.endOpacity(frameNo);
+    float offset = mRepeaterData->offset(frameNo);
+    float startOpacity = mRepeaterData->mTransform.startOpacity(frameNo);
+    float endOpacity = mRepeaterData->mTransform.endOpacity(frameNo);
 
     newFlag |= DirtyFlagBit::Alpha;
 
@@ -1567,7 +1567,7 @@ void LOTRepeaterItem::update(int frameNo, const VMatrix &parentMatrix, float par
         // hide rest of the copies , @TODO find a better solution.
         if ( i >= visibleCopies) newAlpha = 0;
 
-        VMatrix result = mData->mTransform.matrix(frameNo, i + offset) * parentMatrix;
+        VMatrix result = mRepeaterData->mTransform.matrix(frameNo, i + offset) * parentMatrix;
         mContents[i]->update(frameNo, result, newAlpha, newFlag);
     }
 }
@@ -1641,9 +1641,6 @@ void LOTDrawable::sync()
         case CapStyle::Round:
             mCNode->mStroke.cap = LOTCapStyle::CapRound;
             break;
-        default:
-            mCNode->mStroke.cap = LOTCapStyle::CapFlat;
-            break;
         }
 
         switch (mStroke.join) {
index 887f03c78b727cea47a0e06dcfc99ae4c18a16fb..407994dee93844c87431f2117eb741c5b48495c2 100644 (file)
@@ -63,7 +63,7 @@ public:
 class LOTCompItem
 {
 public:
-   LOTCompItem(LOTModel *model);
+   explicit LOTCompItem(LOTModel *model);
    static std::unique_ptr<LOTLayerItem> createLayerItem(LOTLayerData *layerData);
    bool update(int frameNo);
    void resize(const VSize &size);
@@ -88,7 +88,7 @@ class LOTLayerMaskItem;
 class LOTClipperItem
 {
 public:
-    LOTClipperItem(VSize size): mSize(size){}
+    explicit LOTClipperItem(VSize size): mSize(size){}
     void update(const VMatrix &matrix);
     VRle rle();
 public:
@@ -148,7 +148,7 @@ protected:
 class LOTCompLayerItem: public LOTLayerItem
 {
 public:
-   LOTCompLayerItem(LOTLayerData *layerData);
+   explicit LOTCompLayerItem(LOTLayerData *layerData);
    void renderList(std::vector<VDrawable *> &list)final;
    void render(VPainter *painter, const VRle &mask, const VRle &matteRle) final;
    void buildLayerNode() final;
@@ -168,7 +168,7 @@ private:
 class LOTSolidLayerItem: public LOTLayerItem
 {
 public:
-   LOTSolidLayerItem(LOTLayerData *layerData);
+   explicit LOTSolidLayerItem(LOTLayerData *layerData);
    void buildLayerNode() final;
 protected:
    void updateContent() final;
@@ -183,7 +183,7 @@ class LOTContentGroupItem;
 class LOTShapeLayerItem: public LOTLayerItem
 {
 public:
-   LOTShapeLayerItem(LOTLayerData *layerData);
+   explicit LOTShapeLayerItem(LOTLayerData *layerData);
    static std::unique_ptr<LOTContentItem> createContentItem(LOTData *contentData);
    void renderList(std::vector<VDrawable *> &list)final;
    void buildLayerNode() final;
@@ -197,7 +197,7 @@ protected:
 class LOTNullLayerItem: public LOTLayerItem
 {
 public:
-   LOTNullLayerItem(LOTLayerData *layerData);
+   explicit LOTNullLayerItem(LOTLayerData *layerData);
 protected:
    void updateContent() final;
 };
@@ -205,7 +205,7 @@ protected:
 class LOTImageLayerItem: public LOTLayerItem
 {
 public:
-   LOTImageLayerItem(LOTLayerData *layerData);
+   explicit LOTImageLayerItem(LOTLayerData *layerData);
    void buildLayerNode() final;
 protected:
    void updateContent() final;
@@ -218,13 +218,13 @@ private:
 class LOTMaskItem
 {
 public:
-    LOTMaskItem(LOTMaskData *data): mData(data), mCombinedAlpha(0){}
+    explicit LOTMaskItem(LOTMaskData *data): mData(data){}
     void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
     LOTMaskData::Mode maskMode() const { return mData->mMode;}
     VRle rle();
 public:
     LOTMaskData             *mData;
-    float                    mCombinedAlpha;
+    float                    mCombinedAlpha{0};
     VMatrix                  mCombinedMatrix;
     VPath                    mLocalPath;
     VPath                    mFinalPath;
@@ -238,7 +238,7 @@ public:
 class LOTLayerMaskItem
 {
 public:
-    LOTLayerMaskItem(LOTLayerData *layerData);
+    explicit LOTLayerMaskItem(LOTLayerData *layerData);
     void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag);
     bool isStatic() const {return mStatic;}
     VRle maskRle(const VRect &clipRect);
@@ -282,7 +282,7 @@ private:
 class LOTContentGroupItem: public LOTContentItem
 {
 public:
-   LOTContentGroupItem(LOTGroupData *data=nullptr);
+   explicit LOTContentGroupItem(LOTGroupData *data=nullptr);
    void addChildren(LOTGroupData *data);
    void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) override;
    void applyTrim();
@@ -336,7 +336,7 @@ private:
 class LOTRectItem: public LOTPathDataItem
 {
 public:
-   LOTRectItem(LOTRectData *data);
+   explicit LOTRectItem(LOTRectData *data);
 protected:
    void updatePath(VPath& path, int frameNo) final;
    LOTRectData           *mData;
@@ -351,7 +351,7 @@ protected:
 class LOTEllipseItem: public LOTPathDataItem
 {
 public:
-   LOTEllipseItem(LOTEllipseData *data);
+   explicit LOTEllipseItem(LOTEllipseData *data);
 private:
    void updatePath(VPath& path, int frameNo) final;
    LOTEllipseData           *mData;
@@ -364,7 +364,7 @@ private:
 class LOTShapeItem: public LOTPathDataItem
 {
 public:
-   LOTShapeItem(LOTShapeData *data);
+   explicit LOTShapeItem(LOTShapeData *data);
 private:
    void updatePath(VPath& path, int frameNo) final;
    LOTShapeData             *mData;
@@ -376,7 +376,7 @@ private:
 class LOTPolystarItem: public LOTPathDataItem
 {
 public:
-   LOTPolystarItem(LOTPolystarData *data);
+   explicit LOTPolystarItem(LOTPolystarData *data);
 private:
    void updatePath(VPath& path, int frameNo) final;
    LOTPolystarData             *mData;
@@ -419,7 +419,7 @@ protected:
 class LOTFillItem : public LOTPaintDataItem
 {
 public:
-   LOTFillItem(LOTFillData *data);
+   explicit LOTFillItem(LOTFillData *data);
 protected:
    void updateContent(int frameNo) final;
    void updateRenderNode() final;
@@ -432,7 +432,7 @@ private:
 class LOTGFillItem : public LOTPaintDataItem
 {
 public:
-   LOTGFillItem(LOTGFillData *data);
+   explicit LOTGFillItem(LOTGFillData *data);
 protected:
    void updateContent(int frameNo) final;
    void updateRenderNode() final;
@@ -446,7 +446,7 @@ private:
 class LOTStrokeItem : public LOTPaintDataItem
 {
 public:
-   LOTStrokeItem(LOTStrokeData *data);
+   explicit LOTStrokeItem(LOTStrokeData *data);
 protected:
    void updateContent(int frameNo) final;
    void updateRenderNode() final;
@@ -462,7 +462,7 @@ private:
 class LOTGStrokeItem : public LOTPaintDataItem
 {
 public:
-   LOTGStrokeItem(LOTGStrokeData *data);
+   explicit LOTGStrokeItem(LOTGStrokeData *data);
 protected:
    void updateContent(int frameNo) final;
    void updateRenderNode() final;
@@ -510,11 +510,11 @@ private:
 class LOTRepeaterItem : public LOTContentGroupItem
 {
 public:
-   LOTRepeaterItem(LOTRepeaterData *data);
+   explicit LOTRepeaterItem(LOTRepeaterData *data);
    void update(int frameNo, const VMatrix &parentMatrix, float parentAlpha, const DirtyFlag &flag) final;
    void renderList(std::vector<VDrawable *> &list) final;
 private:
-   LOTRepeaterData             *mData;
+   LOTRepeaterData             *mRepeaterData;
    bool                         mHidden{false};
    int                          mCopies{0};
 };
index cc7ea5bbb54fb8a7d96585fb8f3fe4eae0f83b59..760fdc58367b6e4a6286ef43979bdbc1520e0315 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include "vdasher.h"
 #include "vbezier.h"
+
+#include <cmath>
+
+#include "vdasher.h"
 #include "vline.h"
 
 V_BEGIN_NAMESPACE
 
-VDasher::VDasher(const float *dashArray, int size)
+VDasher::VDasher(const float *dashArray, size_t size)
 {
     mDashArray = reinterpret_cast<const VDasher::Dash *>(dashArray);
     mArraySize = size / 2;
@@ -42,16 +45,16 @@ void VDasher::moveTo(const VPointF &p)
 
     if (!vCompare(mDashOffset, 0.0f)) {
         float totalLength = 0.0;
-        for (int i = 0; i < mArraySize; i++) {
+        for (size_t i = 0; i < mArraySize; i++) {
             totalLength = mDashArray[i].length + mDashArray[i].gap;
         }
-        float normalizeLen = fmod(mDashOffset, totalLength);
-        if (normalizeLen < 0.0) {
+        float normalizeLen = std::fmod(mDashOffset, totalLength);
+        if (normalizeLen < 0.0f) {
             normalizeLen = totalLength + normalizeLen;
         }
         // now the length is less than total length and +ve
         // findout the current dash index , dashlength and gap.
-        for (int i = 0; i < mArraySize; i++) {
+        for (size_t i = 0; i < mArraySize; i++) {
             if (normalizeLen < mDashArray[i].length) {
                 mIndex = i;
                 mCurrentLength = mDashArray[i].length - normalizeLen;
@@ -120,13 +123,13 @@ void VDasher::lineTo(const VPointF &p)
             mCurPt = line.p1();
         }
         // handle remainder
-        if (length > 1.0) {
+        if (length > 1.0f) {
             mCurrentLength -= length;
             addLine(line.p2());
         }
     }
 
-    if (mCurrentLength < 1.0) updateActiveSegment();
+    if (mCurrentLength < 1.0f) updateActiveSegment();
 
     mCurPt = p;
 }
@@ -145,9 +148,8 @@ void VDasher::addCubic(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
 void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
 {
     VBezier left, right;
-    float   bezLen = 0.0;
     VBezier b = VBezier::fromPoints(mCurPt, cp1, cp2, e);
-    bezLen = b.length();
+    float bezLen = b.length();
 
     if (bezLen <= mCurrentLength) {
         mCurrentLength -= bezLen;
@@ -164,13 +166,13 @@ void VDasher::cubicTo(const VPointF &cp1, const VPointF &cp2, const VPointF &e)
             mCurPt = b.pt1();
         }
         // handle remainder
-        if (bezLen > 1.0) {
+        if (bezLen > 1.0f) {
             mCurrentLength -= bezLen;
             addCubic(b.pt2(), b.pt3(), b.pt4());
         }
     }
 
-    if (mCurrentLength < 1.0) updateActiveSegment();
+    if (mCurrentLength < 1.0f) updateActiveSegment();
 
     mCurPt = e;
 }
@@ -206,8 +208,6 @@ VPath VDasher::dashed(const VPath &path)
             // no need to do anything here.
             break;
         }
-        default:
-            break;
         }
     }
     return std::move(mResult);
index 41769f407b1c045be0ef085b88ab5bfe0010128c..224a2a8f28148c37bc9e23b3282084af585ff62f 100644 (file)
@@ -24,7 +24,7 @@ V_BEGIN_NAMESPACE
 
 class VDasher {
 public:
-    VDasher(const float *dashArray, int size);
+    VDasher(const float *dashArray, size_t size);
     VPath dashed(const VPath &path);
 
 private:
@@ -42,9 +42,9 @@ private:
         float gap;
     };
     const VDasher::Dash *mDashArray;
-    int                  mArraySize{0};
+    size_t               mArraySize{0};
     VPointF              mCurPt;
-    int                  mIndex{0}; /* index to the dash Array */
+    size_t               mIndex{0}; /* index to the dash Array */
     float                mCurrentLength;
     bool                 mDiscard;
     float                mDashOffset{0};
index 455d771d31bdf5b350ed599eb366a7c241178e4c..27ee26634bb62166414726f647bf8e0637af21bb 100644 (file)
@@ -497,7 +497,7 @@ void fetch_radial_gradient(uint32_t *buffer, const Operator *op,
 }
 
 static inline Operator getOperator(const VSpanData * data,
-                                   const VRle::Span *, int)
+                                   const VRle::Span *, size_t)
 {
     Operator op;
     bool     solidSource = false;
@@ -532,7 +532,7 @@ static inline Operator getOperator(const VSpanData * data,
     return op;
 }
 
-static void blendColorARGB(int count, const VRle::Span *spans, void *userData)
+static void blendColorARGB(size_t count, const VRle::Span *spans, void *userData)
 {
     VSpanData *data = (VSpanData *)(userData);
     Operator   op = getOperator(data, spans, count);
@@ -563,7 +563,7 @@ static void blendColorARGB(int count, const VRle::Span *spans, void *userData)
 }
 
 #define BLEND_GRADIENT_BUFFER_SIZE 2048
-static void blendGradientARGB(int count, const VRle::Span *spans,
+static void blendGradientARGB(size_t count, const VRle::Span *spans,
                               void *userData)
 {
     VSpanData *data = (VSpanData *)(userData);
@@ -595,7 +595,7 @@ constexpr const T& clamp( const T& v, const T& lo, const T& hi)
 
 static const int buffer_size = 1024;
 static const int fixed_scale = 1 << 16;
-static void blend_transformed_argb(int count, const VRle::Span *spans, void *userData)
+static void blend_transformed_argb(size_t count, const VRle::Span *spans, void *userData)
 {
     VSpanData *data = reinterpret_cast<VSpanData *>(userData);
     if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied
@@ -692,7 +692,7 @@ static void blend_transformed_argb(int count, const VRle::Span *spans, void *use
     }
 }
 
-static void blend_untransformed_argb(int count, const VRle::Span *spans, void *userData)
+static void blend_untransformed_argb(size_t count, const VRle::Span *spans, void *userData)
 {
     VSpanData *data = reinterpret_cast<VSpanData *>(userData);
     if (data->mBitmap.format != VBitmap::Format::ARGB32_Premultiplied
index 93710bbaff89cae3a263aa1be1d9c6b5c809b2c0..a0245d77844b93d74b49f371c48fe5db38aef6bd 100644 (file)
@@ -40,7 +40,7 @@ typedef void (*CompositionFunction)(uint32_t *dest, const uint32_t *src,
 typedef void (*SourceFetchProc)(uint32_t *buffer, const Operator *o,
                                 const VSpanData *data, int y, int x,
                                 int length);
-typedef void (*ProcessRleSpan)(int count, const VRle::Span *spans,
+typedef void (*ProcessRleSpan)(size_t count, const VRle::Span *spans,
                                void *userData);
 
 extern void memfill32(uint32_t *dest, uint32_t value, int count);
index 8128a1c5d78778fdf1560e54bc54fc2907d29af6..f762343300ae082c3d5f0657d332a43a611fd5d1 100644 (file)
@@ -36,7 +36,7 @@ public:
         Shear = 0x08,
         Project = 0x10
     };
-
+    VMatrix() = default;
     bool         isAffine() const;
     bool         isIdentity() const;
     bool         isInvertible() const;
index 3d6dfd035a258e05092d86423ea299364c368d3e..1eb8aa6f1ce5ba9b7300e33d1e07cf7457fda048 100644 (file)
@@ -42,7 +42,7 @@ float VPath::VPathData::length() const
     mLengthDirty = false;
     mLength = 0.0;
 
-    int   i = 0;
+    size_t i = 0;
     for (auto e : m_elements) {
         switch (e) {
         case VPath::Element::MoveTo:
@@ -128,12 +128,12 @@ void VPath::VPathData::reset()
     mLengthDirty = false;
 }
 
-int VPath::VPathData::segments() const
+size_t VPath::VPathData::segments() const
 {
     return m_segments;
 }
 
-void VPath::VPathData::reserve(int pts, int elms)
+void VPath::VPathData::reserve(size_t pts, size_t elms)
 {
     if (m_points.capacity() < m_points.size() + pts)
         m_points.reserve(m_points.size() + pts);
@@ -141,13 +141,14 @@ void VPath::VPathData::reserve(int pts, int elms)
         m_elements.reserve(m_elements.size() + elms);
 }
 
-static VPointF curvesForArc(const VRectF &, float, float, VPointF *, int *);
-static constexpr float PATH_KAPPA = 0.5522847498;
+static VPointF curvesForArc(const VRectF &, float, float, VPointF *, size_t *);
+static constexpr float PATH_KAPPA = 0.5522847498f;
+static constexpr float K_PI = M_PIf32;
 
 void VPath::VPathData::arcTo(const VRectF &rect, float startAngle,
                              float sweepLength, bool forceMoveTo)
 {
-    int     point_count = 0;
+    size_t     point_count = 0;
     VPointF pts[15];
     VPointF curve_start =
         curvesForArc(rect, startAngle, sweepLength, pts, &point_count);
@@ -158,7 +159,7 @@ void VPath::VPathData::arcTo(const VRectF &rect, float startAngle,
     } else {
         lineTo(curve_start.x(), curve_start.y());
     }
-    for (int i = 0; i < point_count; i += 3) {
+    for (size_t i = 0; i < point_count; i += 3) {
         cubicTo(pts[i].x(), pts[i].y(), pts[i + 1].x(), pts[i + 1].y(),
                 pts[i + 2].x(), pts[i + 2].y());
     }
@@ -248,8 +249,8 @@ void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir)
 void VPath::VPathData::addRoundRect(const VRectF &rect, float roundness,
                                     VPath::Direction dir)
 {
-    if (2 * roundness > rect.width()) roundness = rect.width()/2.0;
-    if (2 * roundness > rect.height()) roundness = rect.height()/2.0;
+    if (2 * roundness > rect.width()) roundness = rect.width()/2.0f;
+    if (2 * roundness > rect.height()) roundness = rect.height()/2.0f;
     addRoundRect(rect, roundness, roundness, dir);
 }
 
@@ -308,7 +309,7 @@ void         findEllipseCoords(const VRectF &r, float angle, float length,
     for (int i = 0; i < 2; ++i) {
         if (!points[i]) continue;
 
-        float theta = angles[i] - 360 * floor(angles[i] / 360);
+        float theta = angles[i] - 360 * floorf(angles[i] / 360);
         float t = theta / 90;
         // truncate
         int quadrant = int(t);
@@ -340,10 +341,10 @@ static float tForArcAngle(float angle)
     if (vCompare(angle, 0.f)) return 0;
     if (vCompare(angle, 90.0f)) return 1;
 
-    radians = (angle / 180) * M_PI;
+    radians = (angle / 180) * K_PI;
 
-    cos_angle = cos(radians);
-    sin_angle = sin(radians);
+    cos_angle = cosf(radians);
+    sin_angle = sinf(radians);
 
     // initial guess
     tc = angle / 90;
@@ -378,14 +379,14 @@ static float tForArcAngle(float angle)
 
     // use the average of the t that best approximates cos_angle
     // and the t that best approximates sin_angle
-    t = 0.5 * (tc + ts);
+    t = 0.5f * (tc + ts);
     return t;
 }
 
 // The return value is the starting point of the arc
 static VPointF curvesForArc(const VRectF &rect, float startAngle,
                             float sweepLength, VPointF *curves,
-                            int *point_count)
+                            size_t *point_count)
 {
     if (rect.empty()) {
         return {};
@@ -427,18 +428,18 @@ static VPointF curvesForArc(const VRectF &rect, float startAngle,
         sweepLength = -360;
 
     // Special case fast paths
-    if (startAngle == 0.0) {
-        if (sweepLength == 360.0) {
+    if (startAngle == 0.0f) {
+        if (vCompare(sweepLength, 360)) {
             for (int i = 11; i >= 0; --i) curves[(*point_count)++] = points[i];
             return points[12];
-        } else if (sweepLength == -360.0) {
+        } else if (vCompare(sweepLength, -360)) {
             for (int i = 1; i <= 12; ++i) curves[(*point_count)++] = points[i];
             return points[0];
         }
     }
 
-    int startSegment = int(floor(startAngle / 90));
-    int endSegment = int(floor((startAngle + sweepLength) / 90));
+    int startSegment = int(floorf(startAngle / 90.0f));
+    int endSegment = int(floorf((startAngle + sweepLength) / 90.0f));
 
     float startT = (startAngle - startSegment * 90) / 90;
     float endT = (startAngle + sweepLength - endSegment * 90) / 90;
@@ -520,36 +521,36 @@ void VPath::VPathData::addPolystar(float points, float innerRadius,
                                    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;
+    const static float POLYSTAR_MAGIC_NUMBER = 0.47829f / 0.28f;
+    float              currentAngle = (startAngle - 90.0f) * K_PI / 180.0f;
     float              x;
     float              y;
     float              partialPointRadius = 0;
-    float              anglePerPoint = (float)(2.0 * M_PI / points);
-    float              halfAnglePerPoint = anglePerPoint / 2.0;
-    float              partialPointAmount = points - (int)points;
+    float              anglePerPoint = (2.0f * K_PI / points);
+    float              halfAnglePerPoint = anglePerPoint / 2.0f;
+    float              partialPointAmount = points - floorf(points);
     bool               longSegment = false;
-    int                numPoints = (int)ceil(points) * 2.0;
+    size_t             numPoints = size_t(ceilf(points) * 2);
     float              angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
     bool               hasRoundness = false;
 
-    innerRoundness /= 100.0;
-    outerRoundness /= 100.0;
+    innerRoundness /= 100.0f;
+    outerRoundness /= 100.0f;
 
-    if (partialPointAmount != 0) {
+    if (!vCompare(partialPointAmount, 0)) {
         currentAngle +=
-            halfAnglePerPoint * (1.0 - partialPointAmount) * angleDir;
+            halfAnglePerPoint * (1.0f - partialPointAmount) * angleDir;
     }
 
-    if (partialPointAmount != 0) {
+    if (!vCompare(partialPointAmount, 0)) {
         partialPointRadius =
             innerRadius + partialPointAmount * (outerRadius - innerRadius);
-        x = (float)(partialPointRadius * cos(currentAngle));
-        y = (float)(partialPointRadius * sin(currentAngle));
-        currentAngle += anglePerPoint * partialPointAmount / 2.0 * angleDir;
+        x = partialPointRadius * cosf(currentAngle);
+        y = partialPointRadius * sinf(currentAngle);
+        currentAngle += anglePerPoint * partialPointAmount / 2.0f * angleDir;
     } else {
-        x = (float)(outerRadius * cos(currentAngle));
-        y = (float)(outerRadius * sin(currentAngle));
+        x = outerRadius * cosf(currentAngle);
+        y = outerRadius * sinf(currentAngle);
         currentAngle += halfAnglePerPoint * angleDir;
     }
 
@@ -562,28 +563,28 @@ void VPath::VPathData::addPolystar(float points, float innerRadius,
 
     moveTo(x + cx, y + cy);
 
-    for (int i = 0; i < numPoints; i++) {
+    for (size_t i = 0; i < numPoints; i++) {
         float radius = longSegment ? outerRadius : innerRadius;
         float dTheta = halfAnglePerPoint;
-        if (partialPointRadius != 0 && i == numPoints - 2) {
-            dTheta = anglePerPoint * partialPointAmount / 2.0;
+        if (!vIsZero(partialPointRadius) && i == numPoints - 2) {
+            dTheta = anglePerPoint * partialPointAmount / 2.0f;
         }
-        if (partialPointRadius != 0 && i == numPoints - 1) {
+        if (!vIsZero(partialPointRadius) && i == numPoints - 1) {
             radius = partialPointRadius;
         }
         float previousX = x;
         float previousY = y;
-        x = (float)(radius * cos(currentAngle));
-        y = (float)(radius * sin(currentAngle));
+        x = radius * cosf(currentAngle);
+        y = radius * sinf(currentAngle);
 
         if (hasRoundness) {
             float cp1Theta =
-                (float)(atan2(previousY, previousX) - M_PI / 2.0 * angleDir);
-            float cp1Dx = (float)cos(cp1Theta);
-            float cp1Dy = (float)sin(cp1Theta);
-            float cp2Theta = (float)(atan2(y, x) - M_PI / 2.0 * angleDir);
-            float cp2Dx = (float)cos(cp2Theta);
-            float cp2Dy = (float)sin(cp2Theta);
+                (atan2f(previousY, previousX) - K_PI / 2.0f * angleDir);
+            float cp1Dx = cosf(cp1Theta);
+            float cp1Dy = sinf(cp1Theta);
+            float cp2Theta = (atan2f(y, x) - K_PI / 2.0f * angleDir);
+            float cp2Dx = cosf(cp2Theta);
+            float cp2Dy = sinf(cp2Theta);
 
             float cp1Roundness = longSegment ? innerRoundness : outerRoundness;
             float cp2Roundness = longSegment ? outerRoundness : innerRoundness;
@@ -599,7 +600,7 @@ void VPath::VPathData::addPolystar(float points, float innerRadius,
             float cp2y = cp2Radius * cp2Roundness * POLYSTAR_MAGIC_NUMBER *
                          cp2Dy / points;
 
-            if ((partialPointAmount != 0) &&
+            if (!vIsZero(partialPointAmount) &&
                 ((i == 0) || (i == numPoints - 1))) {
                 cp1x *= partialPointAmount;
                 cp1y *= partialPointAmount;
@@ -627,19 +628,19 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
 {
     // TODO: Need to support floating point number for number of points
     const static float POLYGON_MAGIC_NUMBER = 0.25;
-    float              currentAngle = (startAngle - 90.0) * M_PI / 180.0;
+    float              currentAngle = (startAngle - 90.0f) * K_PI / 180.0f;
     float              x;
     float              y;
-    float              anglePerPoint = (float)(2.0 * M_PI / floor(points));
-    int                numPoints = (int)floor(points);
+    float              anglePerPoint = 2.0f * K_PI / floorf(points);
+    size_t             numPoints = size_t(floorf(points));
     float              angleDir = ((dir == VPath::Direction::CW) ? 1.0 : -1.0);
     bool               hasRoundness = false;
 
-    roundness /= 100.0;
+    roundness /= 100.0f;
 
-    currentAngle = (currentAngle - 90.0) * M_PI / 180.0;
-    x = (float)(radius * cos(currentAngle));
-    y = (float)(radius * sin(currentAngle));
+    currentAngle = (currentAngle - 90.0f) * K_PI / 180.0f;
+    x = radius * cosf(currentAngle);
+    y = radius * sinf(currentAngle);
     currentAngle += anglePerPoint * angleDir;
 
     if (vIsZero(roundness)) {
@@ -651,20 +652,20 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
 
     moveTo(x + cx, y + cy);
 
-    for (int i = 0; i < numPoints; i++) {
+    for (size_t i = 0; i < numPoints; i++) {
         float previousX = x;
         float previousY = y;
-        x = (float)(radius * cos(currentAngle));
-        y = (float)(radius * sin(currentAngle));
+        x = (radius * cosf(currentAngle));
+        y = (radius * sinf(currentAngle));
 
         if (hasRoundness) {
             float cp1Theta =
-                (float)(atan2(previousY, previousX) - M_PI / 2.0 * angleDir);
-            float cp1Dx = (float)cos(cp1Theta);
-            float cp1Dy = (float)sin(cp1Theta);
-            float cp2Theta = (float)(atan2(y, x) - M_PI / 2.0 * angleDir);
-            float cp2Dx = (float)cos(cp2Theta);
-            float cp2Dy = (float)sin(cp2Theta);
+                (atan2f(previousY, previousX) - K_PI / 2.0f * angleDir);
+            float cp1Dx = cosf(cp1Theta);
+            float cp1Dy = sinf(cp1Theta);
+            float cp2Theta = atan2f(y, x) - K_PI / 2.0f * angleDir;
+            float cp2Dx = cosf(cp2Theta);
+            float cp2Dy = sinf(cp2Theta);
 
             float cp1x = radius * roundness * POLYGON_MAGIC_NUMBER * cp1Dx;
             float cp1y = radius * roundness * POLYGON_MAGIC_NUMBER * cp1Dy;
@@ -685,7 +686,7 @@ void VPath::VPathData::addPolygon(float points, float radius, float roundness,
 
 void VPath::VPathData::addPath(const VPathData &path)
 {
-    int segment = path.segments();
+    size_t segment = path.segments();
 
     // make sure enough memory available
     if (m_points.capacity() < m_points.size() + path.m_points.size())
index 2c044e822d22fabc12bbf9940661dd5c49a3a4f1..1c4bf0b781145659d996530d8dd1c7320cbe2b66 100644 (file)
@@ -45,8 +45,8 @@ public:
                 bool forceMoveTo);
     void  close();
     void  reset();
-    void  reserve(int pts, int elms);
-    int   segments() const;
+    void  reserve(size_t pts, size_t elms);
+    size_t segments() const;
     void  addCircle(float cx, float cy, float radius,
                     VPath::Direction dir = Direction::CW);
     void  addOval(const VRectF &rect, VPath::Direction dir = Direction::CW);
@@ -80,9 +80,9 @@ private:
         void  cubicTo(float cx1, float cy1, float cx2, float cy2, float ex, float ey);
         void  close();
         void  reset();
-        void  reserve(int, int);
+        void  reserve(size_t, size_t);
         void  checkNewSegment();
-        int   segments() const;
+        size_t segments() const;
         void  transform(const VMatrix &m);
         float length() const;
         void  addRoundRect(const VRectF &, float, float, VPath::Direction);
@@ -107,7 +107,7 @@ private:
         const std::vector<VPointF> &points() const { return m_points; }
         std::vector<VPointF>        m_points;
         std::vector<VPath::Element> m_elements;
-        int                         m_segments;
+        unsigned int                m_segments;
         VPointF                     mStartPoint;
         mutable float               mLength{0};
         mutable bool                mLengthDirty{true};
@@ -150,12 +150,12 @@ inline void VPath::reset()
     d.write().reset();
 }
 
-inline void VPath::reserve(int pts, int elms)
+inline void VPath::reserve(size_t pts, size_t elms)
 {
     d.write().reserve(pts, elms);
 }
 
-inline int VPath::segments() const
+inline size_t VPath::segments() const
 {
     return d->segments();
 }
index 75b1193aa8431dff191957bedf32ff64eb0cfcaf..3a47b2cafb941fc31083958f1e48c25e37a4dc27 100644 (file)
@@ -59,6 +59,7 @@ public:
     void close();
     void end();
     void transform(const VMatrix &m);
+    SW_FT_Pos TO_FT_COORD(float x) { return SW_FT_Pos(x*64);}  // to freetype 26.6 coordinate.
     SW_FT_Outline          ft;
     bool                   closed{false};
     SW_FT_Stroker_LineCap  ftCap;
@@ -116,8 +117,6 @@ void FTOutline::convert(const VPath &path)
         case VPath::Element::Close:
             close();
             break;
-        default:
-            break;
         }
     }
     end();
@@ -128,7 +127,7 @@ void FTOutline::convert(CapStyle cap, JoinStyle join, float width,
 {
     // map strokeWidth to freetype. It uses as the radius of the pen not the
     // diameter
-    width = width / 2.0;
+    width = width / 2.0f;
     // convert to freetype co-ordinate
     // IMP: stroker takes radius in 26.6 co-ordinate
     ftWidth = SW_FT_Fixed(width * (1 << 6));
@@ -160,8 +159,6 @@ void FTOutline::convert(CapStyle cap, JoinStyle join, float width,
     }
 }
 
-#define TO_FT_COORD(x) ((x)*64)  // to freetype 26.6 coordinate.
-
 void FTOutline::moveTo(const VPointF &pt)
 {
     ft.points[ft.n_points].x = TO_FT_COORD(pt.x());
@@ -238,20 +235,21 @@ void FTOutline::end()
 
 static void rleGenerationCb(int count, const SW_FT_Span *spans, void *user)
 {
-    VRle *      rle = (VRle *)user;
-    VRle::Span *rleSpan = (VRle::Span *)spans;
+    VRle *      rle = static_cast<VRle *>(user);
+    auto *rleSpan = reinterpret_cast<const VRle::Span *>(spans);
     rle->addSpan(rleSpan, count);
 }
 
 static void bboxCb(int x, int y, int w, int h, void *user)
 {
-    VRle *      rle = (VRle *)user;
+    VRle *      rle = static_cast<VRle *>(user);
     rle->setBoundingRect({x, y, w, h});
 }
 
 
 class SharedRle {
 public:
+    SharedRle() = default;
     VRle& unsafe(){ return _rle;}
     void notify() {
         {
index 2fa937e3605bbb10828a7044c452459f73c46876..494579bceaa18970b3d1aaf5821d8f58a8e7d194 100644 (file)
@@ -28,7 +28,7 @@ class VRect {
 public:
     VRect() = default;
     VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
-    VRect(const VRectF &r);
+    explicit VRect(const VRectF &r);
     V_CONSTEXPR bool empty() const {return x1 >= x2 || y1 >= y2;}
     V_CONSTEXPR int left() const {return x1;}
     V_CONSTEXPR int top() const {return y1;}
@@ -122,8 +122,8 @@ class VRectF {
 public:
     VRectF() = default;
     VRectF(float x, float y, float w, float h):x1(x),y1(y),x2(x+w),y2(y+h){}
-    VRectF(const VRect &r):x1(r.left()),y1(r.top()),
-                           x2(r.right()),y2(r.bottom()){}
+    explicit VRectF(const VRect &r):x1(r.left()),y1(r.top()),
+                                    x2(r.right()),y2(r.bottom()){}
 
     V_CONSTEXPR bool  empty() const {return x1 >= x2 || y1 >= y2;}
     V_CONSTEXPR float left() const {return x1;}
index c1dc9ba416c47a6509400aabe0188ce01c2d12c5..e3373464e2032c9211b80b3ac795d1733927c70b 100644 (file)
@@ -34,8 +34,8 @@ enum class Operation {
 };
 
 struct VRleHelper {
-    ushort      alloc;
-    ushort      size;
+    size_t      alloc;
+    size_t      size;
     VRle::Span *spans;
 };
 static void rleIntersectWithRle(VRleHelper *, int, int, VRleHelper *,
@@ -49,7 +49,7 @@ static inline uchar divBy255(int x)
     return (x + (x >> 8) + 0x80) >> 8;
 }
 
-inline static void copyArrayToVector(const VRle::Span *span, int count,
+inline static void copyArrayToVector(const VRle::Span *span, size_t count,
                                      std::vector<VRle::Span> &v)
 {
     // make sure enough memory available
@@ -57,7 +57,7 @@ inline static void copyArrayToVector(const VRle::Span *span, int count,
     std::copy(span, span + count, back_inserter(v));
 }
 
-void VRle::VRleData::addSpan(const VRle::Span *span, int count)
+void VRle::VRleData::addSpan(const VRle::Span *span, size_t count)
 {
     copyArrayToVector(span, count, mSpans);
     mBboxDirty = true;
@@ -109,7 +109,7 @@ void VRle::VRleData::addRect(const VRect &rect)
     int width = rect.width();
     int height = rect.height();
 
-    mSpans.reserve(height);
+    mSpans.reserve(size_t(height));
 
     VRle::Span span;
     for (int i = 0; i < height; i++) {
@@ -208,12 +208,12 @@ void VRle::VRleData::opSubstract(const VRle::VRleData &a,
 
         // 1. forward till both y intersect
         while ((aPtr != aEnd) && (aPtr->y < bPtr->y)) aPtr++;
-        int sizeA = aPtr - a.mSpans.data();
+        size_t sizeA = size_t(aPtr - a.mSpans.data());
         if (sizeA) copyArrayToVector(a.mSpans.data(), sizeA, mSpans);
 
         // 2. forward b till it intersect with a.
         while ((bPtr != bEnd) && (bPtr->y < aPtr->y)) bPtr++;
-        int sizeB = bPtr - b.mSpans.data();
+        size_t sizeB = size_t(bPtr - b.mSpans.data());
 
         // 2. calculate the intersect region
         VRleHelper                  tresult, aObj, bObj;
@@ -271,12 +271,12 @@ void VRle::VRleData::opGeneric(const VRle::VRleData &a, const VRle::VRleData &b,
 
         // 1. forward a till it intersects with b
         while ((aPtr != aEnd) && (aPtr->y < bPtr->y)) aPtr++;
-        int sizeA = aPtr - a.mSpans.data();
+        size_t sizeA = size_t(aPtr - a.mSpans.data());
         if (sizeA) copyArrayToVector(a.mSpans.data(), sizeA, mSpans);
 
         // 2. forward b till it intersects with a
         while ((bPtr != bEnd) && (bPtr->y < aPtr->y)) bPtr++;
-        int sizeB = bPtr - b.mSpans.data();
+        size_t sizeB = size_t(bPtr - b.mSpans.data());
         if (sizeB) copyArrayToVector(b.mSpans.data(), sizeB, mSpans);
 
         // 3. calculate the intersect region
@@ -304,8 +304,6 @@ void VRle::VRleData::opGeneric(const VRle::VRleData &a, const VRle::VRleData &b,
         case OpCode::Xor:
             op = Operation::Xor;
             break;
-        default:
-            break;
         }
         // run till all the spans are processed
         while (aObj.size && bObj.size) {
@@ -327,7 +325,7 @@ void VRle::VRleData::opGeneric(const VRle::VRleData &a, const VRle::VRleData &b,
     mBboxDirty = false;
 }
 
-static void  rle_cb(int count, const VRle::Span *spans, void *userData)
+static void  rle_cb(size_t count, const VRle::Span *spans, void *userData)
 {
     auto vector = static_cast<std::vector<VRle::Span> *>(userData);
     copyArrayToVector(spans, count, *vector);
@@ -422,11 +420,11 @@ static void rleIntersectWithRle(VRleHelper *tmp_clip, int clip_offset_x,
             ++spans;
             continue;
         }
-        x = VMAX(sx1, cx1);
-        len = VMIN(sx2, cx2) - x;
+        x = std::max(sx1, cx1);
+        len = std::min(sx2, cx2) - x;
         if (len) {
-            out->x = VMAX(sx1, cx1);
-            out->len = (VMIN(sx2, cx2) - out->x);
+            out->x = std::max(sx1, cx1);
+            out->len = (std::min(sx2, cx2) - out->x);
             out->y = spans->y;
             out->coverage = divBy255(spans->coverage * clipSpans->coverage);
             ++out;
@@ -567,9 +565,9 @@ void blit(VRle::Span *spans, int count, uchar *buffer, int offsetX)
     }
 }
 
-int bufferToRle(uchar *buffer, int size, int offsetX, int y, VRle::Span *out)
+size_t bufferToRle(uchar *buffer, int size, int offsetX, int y, VRle::Span *out)
 {
-    int   count = 0;
+    size_t   count = 0;
     uchar value = buffer[0];
     int   curIndex = 0;
 
@@ -604,7 +602,7 @@ static void rleOpGeneric(VRleHelper *a, VRleHelper *b, VRleHelper *result, Opera
 {
     std::array<VRle::Span, 256> temp;
     VRle::Span *                out = result->spans;
-    int                         available = result->alloc;
+    size_t                      available = result->alloc;
     VRle::Span *                aPtr = a->spans;
     VRle::Span *                aEnd = a->spans + a->size;
     VRle::Span *                bPtr = b->spans;
@@ -637,7 +635,7 @@ static void rleOpGeneric(VRleHelper *a, VRleHelper *b, VRleHelper *result, Opera
             else if (op == Operation::Xor)
                 blitXor(bStart, (bPtr - bStart), array.data(), -offset);
             VRle::Span *tResult = temp.data();
-            int size = bufferToRle(array.data(), std::max(aLength, bLength),
+            size_t size = bufferToRle(array.data(), std::max(aLength, bLength),
                                    offset, y, tResult);
             if (available >= size) {
                 while (size--) {
@@ -668,7 +666,7 @@ static void rleSubstractWithRle(VRleHelper *a, VRleHelper *b,
 {
     std::array<VRle::Span, 256> temp;
     VRle::Span *                out = result->spans;
-    int                         available = result->alloc;
+    size_t                      available = result->alloc;
     VRle::Span *                aPtr = a->spans;
     VRle::Span *                aEnd = a->spans + a->size;
     VRle::Span *                bPtr = b->spans;
@@ -697,7 +695,7 @@ static void rleSubstractWithRle(VRleHelper *a, VRleHelper *b,
             blit(aStart, (aPtr - aStart), array.data(), -offset);
             blitDestinationOut(bStart, (bPtr - bStart), array.data(), -offset);
             VRle::Span *tResult = temp.data();
-            int size = bufferToRle(array.data(), std::max(aLength, bLength),
+            size_t size = bufferToRle(array.data(), std::max(aLength, bLength),
                                    offset, y, tResult);
             if (available >= size) {
                 while (size--) {
@@ -713,11 +711,11 @@ static void rleSubstractWithRle(VRleHelper *a, VRleHelper *b,
     }
     // update the span list that yet to be processed
     a->spans = aPtr;
-    a->size = aEnd - aPtr;
+    a->size = size_t(aEnd - aPtr);
 
     // update the clip list that yet to be processed
     b->spans = bPtr;
-    b->size = bEnd - bPtr;
+    b->size = size_t(bEnd - bPtr);
 
     // update the result
     result->size = result->alloc - available;
index 4de7f144fc56d25ee27a2ce9cd5999d438da3e26..b8d97db3c74eaa5a2a72937c8aa9850466dc5bda 100644 (file)
@@ -35,12 +35,12 @@ public:
         ushort len;
         uchar  coverage;
     };
-    typedef void (*VRleSpanCb)(int count, const VRle::Span *spans,
+    typedef void (*VRleSpanCb)(size_t count, const VRle::Span *spans,
                                void *userData);
     bool  empty() const;
     VRect boundingRect() const;
     void setBoundingRect(const VRect &bbox);
-    void  addSpan(const VRle::Span *span, int count);
+    void  addSpan(const VRle::Span *span, size_t count);
 
     void reset();
     void translate(const VPoint &p);
@@ -69,7 +69,7 @@ private:
             Xor
         };
         bool  empty() const { return mSpans.empty(); }
-        void  addSpan(const VRle::Span *span, int count);
+        void  addSpan(const VRle::Span *span, size_t count);
         void  updateBbox() const;
         VRect bbox() const;
         void setBbox(const VRect &bbox) const;
@@ -99,7 +99,7 @@ inline bool VRle::empty() const
     return d->empty();
 }
 
-inline void VRle::addSpan(const VRle::Span *span, int count)
+inline void VRle::addSpan(const VRle::Span *span, size_t count)
 {
     d.write().addSpan(span, count);
 }