lottie/vector: refactor rect class. 19/188719/2
authorsub.mohanty@samsung.com <smohantty@gmail.com>
Sat, 8 Sep 2018 08:12:20 +0000 (17:12 +0900)
committersub.mohanty@samsung.com <smohantty@gmail.com>
Sun, 9 Sep 2018 02:52:21 +0000 (11:52 +0900)
Change-Id: I553160f74ad06b002cf2d17d1bf55615e71f9853

src/lottie/lottieitem.cpp
src/vector/vpath.cpp
src/vector/vrect.h
src/vector/vregion.cpp
src/vector/vrle.cpp

index d63a176c8a2b6e9f2c795d1e028971569021ee82..f03eccefe0901b40bffd69b104aae563cc376dc5 100644 (file)
@@ -215,7 +215,7 @@ VRle LOTLayerItem::maskRle(const VRect &clipRect)
             break;
         }
         case LOTMaskData::Mode::Substarct: {
-            if (rle.isEmpty() && !clipRect.isEmpty())
+            if (rle.isEmpty() && !clipRect.empty())
                 rle = VRle::toRle(clipRect);
             rle = rle - i->rle();
             break;
index ad30a2ad67968c1623d9fe30c0a7c9cc383cd9db..57d4b4b31dcbc6a8c4c6e53003c16a596b234702 100644 (file)
@@ -142,7 +142,7 @@ void VPath::VPathData::addCircle(float cx, float cy, float radius,
 
 void VPath::VPathData::addOval(const VRectF &rect, VPath::Direction dir)
 {
-    if (rect.isNull()) return;
+    if (rect.empty()) return;
 
     float x = rect.x();
     float y = rect.y();
@@ -192,7 +192,7 @@ void VPath::VPathData::addOval(const VRectF &rect, VPath::Direction dir)
 
 void VPath::VPathData::addRect(const VRectF &rect, VPath::Direction dir)
 {
-    if (rect.isNull()) return;
+    if (rect.empty()) return;
 
     float x = rect.x();
     float y = rect.y();
@@ -255,7 +255,7 @@ static float tForArcAngle(float angle);
 void         findEllipseCoords(const VRectF &r, float angle, float length,
                                VPointF *startPoint, VPointF *endPoint)
 {
-    if (r.isNull()) {
+    if (r.empty()) {
         if (startPoint) *startPoint = VPointF();
         if (endPoint) *endPoint = VPointF();
         return;
@@ -349,7 +349,7 @@ static VPointF curvesForArc(const VRectF &rect, float startAngle,
                             float sweepLength, VPointF *curves,
                             int *point_count)
 {
-    if (rect.isNull()) {
+    if (rect.empty()) {
         return {};
     }
 
index b6c4d96907577d25e2d482126c7c9540dad6f3f4..10e492996218893bff7e5221321b9967dd1a9b6d 100644 (file)
@@ -4,32 +4,32 @@
 #include "vpoint.h"
 
 V_BEGIN_NAMESPACE
+class VRectF;
 
 class VRect {
 public:
     VRect() = default;
-    V_CONSTEXPR             VRect(int left, int top, int width, int height);
-    V_CONSTEXPR inline bool isEmpty() const;
-    V_CONSTEXPR inline bool isNull() const;
-
-    V_CONSTEXPR inline int left() const;
-    V_CONSTEXPR inline int top() const;
-    V_CONSTEXPR inline int right() const;
-    V_CONSTEXPR inline int bottom() const;
-    V_CONSTEXPR inline int width() const;
-    V_CONSTEXPR inline int height() const;
-    V_CONSTEXPR inline int x() const;
-    V_CONSTEXPR inline int y() const;
-    inline void            setLeft(int l) { x1 = l; }
-    inline void            setTop(int t) { y1 = t; }
-    inline void            setRight(int r) { x2 = r; }
-    inline void            setBottom(int b) { y2 = b; }
-    inline void            setWidth(int w) { x2 = x1 + w; }
-    inline void            setHeight(int h) { y2 = y1 + h; }
-    inline VRect           translated(int dx, int dy) const;
-    inline void            translate(int dx, int dy);
-    inline bool            contains(const VRect &r, bool proper = false) const;
-    inline bool            intersects(const VRect &r);
+    VRect(int x, int y, int w, int h):x1(x),y1(y),x2(x+w),y2(y+h){}
+    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;}
+    V_CONSTEXPR int right() const {return x2;}
+    V_CONSTEXPR int bottom() const {return y2;}
+    V_CONSTEXPR int width() const {return x2-x1;}
+    V_CONSTEXPR int height() const {return y2-y1;}
+    V_CONSTEXPR int x() const {return x1;}
+    V_CONSTEXPR int y() const {return y1;}
+    void            setLeft(int l) { x1 = l; }
+    void            setTop(int t) { y1 = t; }
+    void            setRight(int r) { x2 = r; }
+    void            setBottom(int b) { y2 = b; }
+    void            setWidth(int w) { x2 = x1 + w; }
+    void            setHeight(int h) { y2 = y1 + h; }
+    VRect    translated(int dx, int dy) const;
+    void     translate(int dx, int dy);
+    bool     contains(const VRect &r, bool proper = false) const;
+    bool     intersects(const VRect &r);
     friend V_CONSTEXPR inline bool operator==(const VRect &,
                                               const VRect &) noexcept;
     friend V_CONSTEXPR inline bool operator!=(const VRect &,
@@ -39,8 +39,8 @@ public:
 private:
     int x1{0};
     int y1{0};
-    int x2{-1};
-    int y2{-1};
+    int x2{0};
+    int y2{0};
 };
 
 inline bool VRect::intersects(const VRect &r)
@@ -65,54 +65,6 @@ V_CONSTEXPR inline bool operator!=(const VRect &r1, const VRect &r2) noexcept
     return r1.x1 != r2.x1 || r1.x2 != r2.x2 || r1.y1 != r2.y1 || r1.y2 != r2.y2;
 }
 
-V_CONSTEXPR inline bool VRect::isEmpty() const
-{
-    return x1 > x2 || y1 > y2;
-}
-
-V_CONSTEXPR inline bool VRect::isNull() const
-{
-    return (((x2 - x1) == 0) || ((y2 - y1) == 0));
-}
-
-V_CONSTEXPR inline int VRect::x() const
-{
-    return x1;
-}
-
-V_CONSTEXPR inline int VRect::y() const
-{
-    return y1;
-}
-
-V_CONSTEXPR inline int VRect::left() const
-{
-    return x1;
-}
-
-V_CONSTEXPR inline int VRect::top() const
-{
-    return y1;
-}
-
-V_CONSTEXPR inline int VRect::right() const
-{
-    return x2;
-}
-
-V_CONSTEXPR inline int VRect::bottom() const
-{
-    return y2;
-}
-V_CONSTEXPR inline int VRect::width() const
-{
-    return x2 - x1;
-}
-V_CONSTEXPR inline int VRect::height() const
-{
-    return y2 - y1;
-}
-
 inline VRect VRect::translated(int dx, int dy) const
 {
     return {x1 + dx, y1 + dy, x2 - x1, y2 - y1};
@@ -125,6 +77,7 @@ inline void VRect::translate(int dx, int dy)
     x2 += dx;
     y2 += dy;
 }
+
 inline bool VRect::contains(const VRect &r, bool proper) const
 {
     if (!proper) {
@@ -137,43 +90,34 @@ inline bool VRect::contains(const VRect &r, bool proper) const
         return false;
     }
 }
-V_CONSTEXPR inline VRect::VRect(int left, int top, int width, int height)
-    : x1(left), y1(top), x2(width + left), y2(height + top)
-{
-}
 
 class VRectF {
 public:
     VRectF() = default;
-    VRectF(float left, float top, float width, float height)
-    {
-        x1 = left;
-        y1 = top;
-        x2 = x1 + width;
-        y2 = y1 + height;
-    }
-
-    V_CONSTEXPR inline bool    isEmpty() const;
-    V_CONSTEXPR inline bool    isNull() const;
-    V_CONSTEXPR inline float   left() const;
-    V_CONSTEXPR inline float   top() const;
-    V_CONSTEXPR inline float   right() const;
-    V_CONSTEXPR inline float   bottom() const;
-    V_CONSTEXPR inline float   width() const;
-    V_CONSTEXPR inline float   height() const;
-    V_CONSTEXPR inline float   x() const;
-    V_CONSTEXPR inline float   y() const;
+    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()){}
+
+    V_CONSTEXPR bool  empty() const {return x1 >= x2 || y1 >= y2;}
+    V_CONSTEXPR float left() const {return x1;}
+    V_CONSTEXPR float top() const {return y1;}
+    V_CONSTEXPR float right() const {return x2;}
+    V_CONSTEXPR float bottom() const {return y2;}
+    V_CONSTEXPR float width() const {return x2-x1;}
+    V_CONSTEXPR float height() const {return y2-y1;}
+    V_CONSTEXPR float x() const {return x1;}
+    V_CONSTEXPR float y() const {return y1;}
     V_CONSTEXPR inline VPointF center() const
     {
         return {x1 + (x2 - x1) / 2.f, y1 + (y2 - y1) / 2.f};
     }
-    inline void setLeft(float l) { x1 = l; }
-    inline void setTop(float t) { y1 = t; }
-    inline void setRight(float r) { x2 = r; }
-    inline void setBottom(float b) { y2 = b; }
-    inline void setWidth(float w) { x2 = x1 + w; }
-    inline void setHeight(float h) { y2 = y1 + h; }
-    inline void translate(float dx, float dy)
+    void setLeft(float l) { x1 = l; }
+    void setTop(float t) { y1 = t; }
+    void setRight(float r) { x2 = r; }
+    void setBottom(float b) { y2 = b; }
+    void setWidth(float w) { x2 = x1 + w; }
+    void setHeight(float h) { y2 = y1 + h; }
+    void translate(float dx, float dy)
     {
         x1 += dx;
         y1 += dy;
@@ -184,58 +128,12 @@ public:
 private:
     float x1{0};
     float y1{0};
-    float x2{-1};
-    float y2{-1};
+    float x2{0};
+    float y2{0};
 };
 
-V_CONSTEXPR inline bool VRectF::isEmpty() const
-{
-    return x1 > x2 || y1 > y2;
-}
-
-V_CONSTEXPR inline bool VRectF::isNull() const
-{
-    return (((x2 - x1) == 0) || ((y2 - y1) == 0));
-}
-
-V_CONSTEXPR inline float VRectF::x() const
-{
-    return x1;
-}
-
-V_CONSTEXPR inline float VRectF::y() const
-{
-    return y1;
-}
-
-V_CONSTEXPR inline float VRectF::left() const
-{
-    return x1;
-}
-
-V_CONSTEXPR inline float VRectF::top() const
-{
-    return y1;
-}
-
-V_CONSTEXPR inline float VRectF::right() const
-{
-    return x2;
-}
-
-V_CONSTEXPR inline float VRectF::bottom() const
-{
-    return y2;
-}
-V_CONSTEXPR inline float VRectF::width() const
-{
-    return x2 - x1;
-}
-V_CONSTEXPR inline float VRectF::height() const
-{
-    return y2 - y1;
-}
-
+inline VRect::VRect(const VRectF &r):x1(r.left()),y1(r.top()),
+                                     x2(r.right()),y2(r.bottom()){}
 V_END_NAMESPACE
 
 #endif  // VRECT_H
index 71aa1ea4680a1b069254da33177fec8d76280a64..b5eab50895691e266b241f923435a76977a452b0 100644 (file)
@@ -1825,7 +1825,7 @@ VRegion::VRegion(int x, int y, int w, int h)
 
 VRegion::VRegion(const VRect &r)
 {
-    if (r.isEmpty()) {
+    if (r.empty()) {
         d = const_cast<VRegionData *>(&shared_empty);
     } else {
         d = new VRegionData;
@@ -1938,7 +1938,7 @@ VRegion VRegion::united(const VRegion &r) const
 
 VRegion VRegion::intersected(const VRect &r) const
 {
-    if (isEmpty() || r.isEmpty()) return VRegion();
+    if (isEmpty() || r.empty()) return VRegion();
 
     /* this is fully contained in r */
     if (within(r)) return *this;
@@ -2009,7 +2009,7 @@ VRegion VRegion::operator-(const VRegion &r) const
 VRegion &VRegion::operator+=(const VRect &r)
 {
     if (isEmpty()) return *this = r;
-    if (r.isEmpty()) return *this;
+    if (r.empty()) return *this;
 
     if (contains(r)) {
         return *this;
index 1ab7393eb1378cf20e4e2a29f8cafbe45072e949..3d4393d344bfe08e7a00a92db31d79cf110e2438 100644 (file)
@@ -680,7 +680,7 @@ static void rleSubstractWithRle(VRleHelper *a, VRleHelper *b,
 
 VRle VRle::toRle(const VRect &rect)
 {
-    if (rect.isEmpty()) return VRle();
+    if (rect.empty()) return VRle();
 
     VRle result;
     result.d.write().addRect(rect);