From f14e50305a3cb07746a1e5094cb9d2490c69678f Mon Sep 17 00:00:00 2001 From: "sub.mohanty@samsung.com" Date: Sat, 8 Sep 2018 17:12:20 +0900 Subject: [PATCH] lottie/vector: refactor rect class. Change-Id: I553160f74ad06b002cf2d17d1bf55615e71f9853 --- src/lottie/lottieitem.cpp | 2 +- src/vector/vpath.cpp | 8 +- src/vector/vrect.h | 200 ++++++++++---------------------------- src/vector/vregion.cpp | 6 +- src/vector/vrle.cpp | 2 +- 5 files changed, 58 insertions(+), 160 deletions(-) diff --git a/src/lottie/lottieitem.cpp b/src/lottie/lottieitem.cpp index d63a176..f03ecce 100644 --- a/src/lottie/lottieitem.cpp +++ b/src/lottie/lottieitem.cpp @@ -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; diff --git a/src/vector/vpath.cpp b/src/vector/vpath.cpp index ad30a2a..57d4b4b 100644 --- a/src/vector/vpath.cpp +++ b/src/vector/vpath.cpp @@ -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 {}; } diff --git a/src/vector/vrect.h b/src/vector/vrect.h index b6c4d96..10e4929 100644 --- a/src/vector/vrect.h +++ b/src/vector/vrect.h @@ -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 diff --git a/src/vector/vregion.cpp b/src/vector/vregion.cpp index 71aa1ea..b5eab50 100644 --- a/src/vector/vregion.cpp +++ b/src/vector/vregion.cpp @@ -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(&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; diff --git a/src/vector/vrle.cpp b/src/vector/vrle.cpp index 1ab7393..3d4393d 100644 --- a/src/vector/vrle.cpp +++ b/src/vector/vrle.cpp @@ -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); -- 2.34.1