Opened 7 years ago
Closed 7 years ago
#3930 closed defect (fixed)
Precision error in lwgeom_calculate_mbc / point_inside_circle
Reported by: | rundel | Owned by: | strk |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.4.3 |
Component: | liblwgeom | Version: | 2.4.x |
Keywords: | Cc: |
Description
Working on an R wrapper for lwgeom we recent came across a bug with lwgeom_calculate_mbc where certain geometries on 32 bit systems returned nan values for center and radius of the mbc. After some debugging the issue is caused by bad floating point comparison in the point_inside_circle function. Specifically, distance2d_pt_pt(p, c→center) > c→radius will erroneously return true when the point p is identical to one of the support points on 32 bit but not 64 bit systems.
Replacing this test with distance2d_pt_pt(p, c→center) - c→radius > DBL_EPSILON along with including float.h was able to resolve this issue for our test case.
Our discussion about the bug and the related pull request for the R package can be found here: https://github.com/r-spatial/lwgeom/issues/7. An example of the specific geometry that was producing the error is attached as WKT.
I am happy to provide a pull request to the github repo if that would be helpful.
Attachments (1)
Change History (5)
by , 7 years ago
comment:1 by , 7 years ago
Milestone: | PostGIS 2.4.2 → PostGIS 2.4.3 |
---|
Example multipolygon that produces the nan behavior on 32 bit systems (tested on both Windows 10 and Ubuntu 16.04)