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)

state.wkt (10.5 KB ) - added by rundel 7 years ago.
Example multipolygon that produces the nan behavior on 32 bit systems (tested on both Windows 10 and Ubuntu 16.04)

Download all attachments as: .zip

Change History (5)

by rundel, 7 years ago

Attachment: state.wkt added

Example multipolygon that produces the nan behavior on 32 bit systems (tested on both Windows 10 and Ubuntu 16.04)

comment:1 by pramsey, 7 years ago

Milestone: PostGIS 2.4.2PostGIS 2.4.3

comment:2 by pramsey, 7 years ago

In 16164:

Test case on minimum bounding circle (references #3930)

comment:3 by pramsey, 7 years ago

In 16165:

Apply the epsilon fix to bounding circle (references #3930)

comment:4 by pramsey, 7 years ago

Resolution: fixed
Status: newclosed

In 16166:

Bring epsilon fix to minimum bounding circle back to 2.4 (closes #3930)

Note: See TracTickets for help on using tickets.