common scene: support bounds() method 59/232459/1
authorHermet Park <chuneon.park@samsung.com>
Tue, 5 May 2020 11:38:26 +0000 (20:38 +0900)
committerHermet Park <chuneon.park@samsung.com>
Tue, 5 May 2020 11:38:26 +0000 (20:38 +0900)
this method returns boundary of a scene.

Change-Id: I1a32c8e034f53822008048f1d8ae7062fb72cca3

src/lib/tvgScene.cpp
src/lib/tvgSceneImpl.h
src/lib/tvgShape.cpp
src/lib/tvgShapeImpl.h

index 9b9844b..471d2ab 100644 (file)
@@ -78,6 +78,16 @@ int Scene::rotate(float degree) noexcept
 
 int Scene::bounds(float& x, float& y, float& w, float& h) const noexcept
 {
+    auto impl = pImpl.get();
+    assert(impl);
+
+    x = FLT_MAX;
+    y = FLT_MAX;
+    w = 0;
+    h = 0;
+
+    if (!impl->bounds(x, y, w, h)) return -1;
+
     return 0;
 }
 
index 31a3614..a2ce90d 100644 (file)
@@ -71,6 +71,29 @@ struct Scene::Impl
         }
         return true;
     }
+
+    bool bounds(float& x, float& y, float& w, float& h)
+    {
+        for(auto paint: paints) {
+            auto x2 = FLT_MAX;
+            auto y2 = FLT_MAX;
+            auto w2 = 0.0f;
+            auto h2 = 0.0f;
+
+            if (auto scene = dynamic_cast<Scene*>(paint)) {
+                if (!SCENE_IMPL->bounds(x2, y2, w2, h2)) return false;
+            } else if (auto shape = dynamic_cast<Shape*>(paint)) {
+                if (!SHAPE_IMPL->bounds(x2, y2, w2, h2)) return false;
+            }
+
+            //Merge regions
+            if (x2 < x) x = x2;
+            if (x + w < x2 + w2) w = (x2 + w2) - x;
+            if (y2 < y) y = x2;
+            if (y + h < y2 + h2) h = (y2 + h2) - y;
+        }
+        return true;
+    }
 };
 
 #endif //_TVG_SCENE_IMPL_H_
\ No newline at end of file
index 1e5545d..272b194 100644 (file)
@@ -273,9 +273,9 @@ int Shape::rotate(float degree) noexcept
 int Shape::bounds(float& x, float& y, float& w, float& h) const noexcept
 {
     auto impl = pImpl.get();
-    assert(impl && impl->path);
+    assert(impl);
 
-    if (!impl->path->bounds(x, y, w, h)) return -1;
+    if (!impl->bounds(x, y, w, h)) return -1;
 
     return 0;
 }
index 63b7477..5894b1e 100644 (file)
@@ -72,6 +72,12 @@ struct Shape::Impl
         if (edata) return true;
         return false;
     }
+
+    bool bounds(float& x, float& y, float& w, float& h)
+    {
+        assert(path);
+        return path->bounds(x, y, w, h);
+    }
 };
 
 #endif //_TVG_SHAPE_IMPL_H_
\ No newline at end of file