mirror of
https://github.com/thorvg/thorvg.git
synced 2025-07-27 08:36:59 +00:00
common scene: support bounds() method
this method returns boundary of a scene. Change-Id: I1a32c8e034f53822008048f1d8ae7062fb72cca3
This commit is contained in:
parent
0716d3e774
commit
17af011eae
4 changed files with 41 additions and 2 deletions
|
@ -78,6 +78,16 @@ int Scene::rotate(float degree) noexcept
|
||||||
|
|
||||||
int Scene::bounds(float& x, float& y, float& w, float& h) const 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,6 +71,29 @@ struct Scene::Impl
|
||||||
}
|
}
|
||||||
return true;
|
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_
|
#endif //_TVG_SCENE_IMPL_H_
|
|
@ -273,9 +273,9 @@ int Shape::rotate(float degree) noexcept
|
||||||
int Shape::bounds(float& x, float& y, float& w, float& h) const noexcept
|
int Shape::bounds(float& x, float& y, float& w, float& h) const noexcept
|
||||||
{
|
{
|
||||||
auto impl = pImpl.get();
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,6 +72,12 @@ struct Shape::Impl
|
||||||
if (edata) return true;
|
if (edata) return true;
|
||||||
return false;
|
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_
|
#endif //_TVG_SHAPE_IMPL_H_
|
Loading…
Add table
Reference in a new issue