c++ - How can I find a box that encompasses all given boxes? -


i have sequence of boost geometry box types , wish find dimensions of box encompasses of objects.

i've noticed boost geometry provides encompass function, seems i'm asking general geometry concepts, don't know how sequence of boxes.

basically i've had roll own, wondering if possible turn sequence of boxes "geometry" can apply envelope function. here's i've written:

// elsewhere in code: using location = boost::geometry::model::d2::point_xy<double>; using box = boost::geometry::model::box<location>;  // calculate smallest box encompasses provided boxes             template <template <typename...> class iterablecontainer>                           box envelope(const iterablecontainer<box>& sequence)                                {                                                                                       location mincorner(                                                                     std::numeric_limits<double>::max(),                                                 std::numeric_limits<double>::max());                                             location maxcorner(                                                                     std::numeric_limits<double>::lowest(),                                                 std::numeric_limits<double>::lowest());                                             (auto& box : sequence)                                                          {                                                                                       if (box.min_corner().x() < mincorner.x())                                               mincorner.x() == box.min_corner().x();                                           if (box.min_corner().y() < mincorner.y())                                               mincorner.y() == box.min_corner().y();                                           if (box.max_corner().x() > maxcorner.x())                                               maxcorner.x() == box.max_corner().x();                                           if (box.max_corner().y() > maxcorner.y())                                               maxcorner.y() == box.max_corner().y();                                      }                                                                                    return box(mincorner, maxcorner);                                               }                                                                                   

the function looking called std::accumulate. need feed box-union function.

using location = boost::geometry::model::d2::point_xy<double>; using box = boost::geometry::model::box<location>; double pinfi = std::numeric_limits<double>::max(); double ninfi = std::numeric_limits<double>::lowest();  box u = std::accumulate(container.begin(), container.end(),                          box(location(pinfi,pinfi), location(ninfi,ninfi)),                         [](const box& a, const box& b) {                              return box(                                     location(                                      std::min(a.min_corner().x(),b.min_corner().x()),                                      std::min(a.min_corner().y(),b.min_corner().y())),                                     location(                                      std::max(a.max_corner().x(),b.max_corner().x()),                                      std::min(a.max_corner().y(),b.max_corner().y())));                          }); 

update: building blocks of function exist in boost::geometry. here's complete tested code:

template <typename t> box box_encompass (t beg, t end) {     return std::accumulate(beg, end, boost::geometry::make_inverse<box>(),                 [](box a, const box& b) -> box {                     boost::geometry::expand(a,b);                     return a;                 }); } 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -