Josh Pieper wrote:
Hello,
We have been using the 1.44.0 release of polygon for some internal projects and have come across a number of oddities. The first one I've got is a valgrind error when normalizing polygons with numerically large coordinate values. Using the gmp_override.hpp header does resolve these problems, but my understanding is that it is the intent for the library to merely be numerically imprecise, rather than crash, for coordinates which are too large.
No, I fully expect the library may crash or exhibit other undefined behaviors if coordinates are too large and gmp is not used. If the coordinates are small enough that the numerator and denominator of the line intersection equation fit in the floating point representation without roundoff then the library may work correctly without the need for gmp, but in general I don't advise using the library without gmp. You will quickly find that in order to avoid rounding error issues you want to scale your data up, which won't work if you are trying to keep things within a ~16 bit range.
Our simplified test case is below, and was compiled on an AMD64 Ubuntu 10.4 system. The first call to Normalize has no problems, but the second call causes valgrind to report both uninitialized memory usage and invalid reads. (I can produce the valgrind log on demand, but it is somewhat large for inclusion in an email). While we have deployed 1.44.0 internally, I tested against the most recent svn version and the problem still exists.
I just checked into the trunk today a couple changes that should make the library more reliable without the use of gmp. My version number for the checkin is 66403. The sandbox version is older than the 1.44 release. I stopped syncing the sandbox once I merged to the release branch and now do all development on the trunk. Included in this checkin were several fixes for resizing that didn't make it in time for the 1.45 release. If you plan to use resizing you should update.
Is this merely a mis-use of the API?
I would say yes, but only because you expected the library to be reliable without using gmp. Right now I can't provide that and make no promises about reliability if gmp is not used. You mentioned a number of oddities but describe only one. What else have you run into? Thanks, Luke