0

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
David R.
  • 855
  • 8
  • 17
  • The first thing I would do, myself, is use my debugger to run this code one line at a time, and inspect what all the variables are; see what `p` turns out to be, for example. Do you know how to use a debugger? – Sam Varshavchik Jun 26 '22 at 19:29
  • Isn't `boost::polygon::polygon_data p;` defined as local variable? – RC0993 Jun 26 '22 at 20:13
  • Yes, @RC0993 it is a local variable, and your point is...? – Sam Varshavchik Jun 26 '22 at 20:17
  • @SamVarshavchik Did you really spend time and effort posting comment like this? Could've used it to click on the link and find out more... – David R. Jun 26 '22 at 21:17
  • All questions here should have all relevant information ***in the question itself as plain text***. Random links can be posted on appropriate social media sites (Facebook, Reddit, etc...), Stackoverflow is for ***specific*** questions. Links can stop working at any time making questions meaningless. Can you [edit] this question, removing and replacing all links with all relevant information as plain text? – Sam Varshavchik Jun 26 '22 at 21:18
  • This questions does include all relevant information - it describes the issue, has the code, and asks if anyone has workarounds. It is fine if you don't know the answer to the question/problem and can't help. I will only edit to fix the typos. – David R. Jun 26 '22 at 21:29
  • So, just to make sure I understand, you're yet to use your "debugger to run this code one line at a time, and inspect what all the variables are; see what `p` turns out to be", you're waiting for someone else to do this instead, for you, you don't want to do it yourself? You see, C++ is just too complicated, only the simplest issues are apparent on first glance and nearly every time it is necessary to do what's generally described as "debugging" to identify the root cause of the issue at hand. And, if one can't, one improves one's chances of getting help by showing some of one's own efforts. – Sam Varshavchik Jun 26 '22 at 21:33
  • @SamVarshavchik Yes, debugged it, found the root cause, went back to documentation, found the explanation case closed. I am sorry that C++ is too complicated for you, keep at it, you will get better. – David R. Jun 26 '22 at 21:38

1 Answers1

0

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.

David R.
  • 855
  • 8
  • 17