geometry icon indicating copy to clipboard operation
geometry copied to clipboard

centroid not working without main geometry header

Open MelisWillem opened this issue 4 years ago • 2 comments

When I try to use the centroid or return_centroid function, by including the bare minimum (#include <boost/geometry/algorithms/centroid.hpp>) it doesn't seem to compile.("error: no type named 'state_type'")

If I add the "#include<boost/geometry.hpp>" header things work just fine. Is this by design? or a bug?

example code:

// #include<boost/geometry.hpp> // uncomment me to get stuff compiling.
#include <boost/geometry/algorithms/centroid.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/linestring.hpp>

namespace bg = boost::geometry;

using point = bg::model::point<int, 2, bg::cs::cartesian>;
using linestring = bg::model::linestring<point>;

int main(){
    auto l = linestring{{0,0},{1,1}};
    auto p = bg::return_centroid<point>(l);
}

Or on compiler explorer: https://godbolt.org/z/Wdcb6f

MelisWillem avatar Jan 05 '21 08:01 MelisWillem

You need to include the stategies for centroid. Including the following should work #include <boost/geometry/strategies/strategies.hpp> However, AFAIU, this should not be needed to use the centroid algorithm.

vissarion avatar Jan 11 '21 10:01 vissarion

@vissarion thanks !. With the "strategies" include it works, but the doc's don't say anything about it. I'l go trough the code and figure out why exactly the strategies header is required here.

MelisWillem avatar Jan 11 '21 11:01 MelisWillem

This is fixed in boost 1.77.0.

vissarion avatar Oct 19 '22 13:10 vissarion