boost::polygon::area returns 0

124 views Asked by At

I am seeing strange result from boost::polygon::area. I posted this issue on the Boost GitHub page, but looking for suggestions form the wider SO community.

The code below report 0 area for the given polygon. Any suggestions how to work around this?

#include <boost/polygon/polygon.hpp>
#include <boost/polygon/rectangle_data.hpp>
#include <boost/polygon/polygon_set_data.hpp>
#include <boost/polygon/polygon_data.hpp>
#include <boost/version.hpp>
#include <boost/format.hpp>

template<typename T>
auto make_rect(T x1, T y1, T x2, T y2) {
    auto r = boost::polygon::rectangle_data(x1, y1, x2, y2);
    boost::polygon::polygon_data<T> p;
    boost::polygon::assign(p, r);
    return p;
}

int main(int argc, char **argv) {
    std::cout << BOOST_LIB_VERSION << std::endl;
    boost::polygon::polygon_set_data<double> poly, poly1;
    poly.insert(make_rect(0.003065, 0.0007, 0.0034, 0.0009525));
    std::cout << boost::format("%e") % boost::polygon::area(poly) << std::endl;
}

output is:

1_78
0.000000e+00
1

There are 1 answers

0
David R. On

After re-reading the Boost Polygon documentation, this explains it:

The coordinate data type is a template parameter of all data types and algorithms provided by the library, and is expected to be integral. Floating point coordinate data types are not supported by the algorithms implemented in the library due to the fact that the achieving floating point robustness implies a different set of algorithms and generally platform specific assumptions about floating point representations.