lottie/vector: added intersected() and size() api to vrect class. 66/196766/2
authorsubhransu mohanty <sub.mohanty@samsung.com>
Fri, 4 Jan 2019 06:21:30 +0000 (15:21 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 8 Jan 2019 05:56:50 +0000 (05:56 +0000)
Change-Id: Ibb4c764e8a12bc3b95cbd601b42c73b777793afd

src/vector/CMakeLists.txt
src/vector/meson.build
src/vector/vrect.cpp
src/vector/vrect.h

index 573a33b..96c55d6 100644 (file)
@@ -4,6 +4,7 @@ add_subdirectory(pixman)
 
 target_sources(lottie-player
     PRIVATE
+        "${CMAKE_CURRENT_LIST_DIR}/vrect.cpp"
         "${CMAKE_CURRENT_LIST_DIR}/vdasher.cpp"
         "${CMAKE_CURRENT_LIST_DIR}/vbrush.cpp"
         "${CMAKE_CURRENT_LIST_DIR}/vbitmap.cpp"
index 3246e43..338b87e 100644 (file)
@@ -14,7 +14,7 @@ source_file  += files('vdrawhelper.cpp')
 source_file  += files('vdrawhelper_sse2.cpp')
 source_file  += files('vdrawable.cpp')
 
-
+source_file  += files('vrect.cpp')
 source_file  += files('vrle.cpp')
 source_file  += files('vpath.cpp')
 source_file  += files('vpathmesure.cpp')
index c044a53..60d2116 100644 (file)
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#include "vrect.h"
+
+VRect VRect::operator&(const VRect &r) const
+{
+    if (empty())
+        return VRect();
+
+    int l1 = x1;
+    int r1 = x1;
+    if (x2 - x1 + 1 < 0)
+        l1 = x2;
+    else
+        r1 = x2;
+
+    int l2 = r.x1;
+    int r2 = r.x1;
+    if (r.x2 - r.x1 + 1 < 0)
+        l2 = r.x2;
+    else
+        r2 = r.x2;
+
+    if (l1 > r2 || l2 > r1)
+        return VRect();
+
+    int t1 = y1;
+    int b1 = y1;
+    if (y2 - y1 + 1 < 0)
+        t1 = y2;
+    else
+        b1 = y2;
+
+    int t2 = r.y1;
+    int b2 = r.y1;
+    if (r.y2 - r.y1 + 1 < 0)
+        t2 = r.y2;
+    else
+        b2 = r.y2;
+
+    if (t1 > b2 || t2 > b1)
+        return VRect();
+
+    VRect tmp;
+    tmp.x1 = std::max(l1, l2);
+    tmp.x2 = std::min(r1, r2);
+    tmp.y1 = std::max(t1, t2);
+    tmp.y2 = std::min(b1, b2);
+    return tmp;
+}
index b38746f..2fa937e 100644 (file)
@@ -38,6 +38,7 @@ public:
     V_CONSTEXPR int height() const {return y2-y1;}
     V_CONSTEXPR int x() const {return x1;}
     V_CONSTEXPR int y() const {return y1;}
+    VSize           size() const {return {width(), height()};}
     void            setLeft(int l) { x1 = l; }
     void            setTop(int t) { y1 = t; }
     void            setRight(int r) { x2 = r; }
@@ -54,6 +55,9 @@ public:
                                               const VRect &) noexcept;
     friend VDebug &                operator<<(VDebug &os, const VRect &o);
 
+    VRect intersected(const VRect &r) const;
+    VRect operator&(const VRect &r) const;
+
 private:
     int x1{0};
     int y1{0};
@@ -61,6 +65,11 @@ private:
     int y2{0};
 };
 
+inline VRect VRect::intersected(const VRect &r) const
+{
+    return *this & r;
+}
+
 inline bool VRect::intersects(const VRect &r)
 {
     return (right() > r.left() && left() < r.right() && bottom() > r.top() &&